Introduction
Automation Platform
Botmain DAO
Building Trading Strategies
API References Dev Live Stream
@botmain/common / Class

OrderProcessor

An instance of this class serves as an intermediary between a trading strategy and the target order execution system. Botmain supports two types of order executions: Backtesting and Real-Time Trading.

The Backtesting order execution system is realized as the internal Botmain software component named OrderSimulator.

In Real-Time Trading mode, the order execution system is a part of a certain external trading platform provided by an exchange. Botmain in this case only controls the connection to this platform.

Properties

NameTypeDescription
isSimulation
boolean

Identifies the current working mode of OrderProcessor - Backtesting (Simulation) or Real-Time trading.

Methods

cancelOrder()

Sends a request to cancel the order with the given ID.

Presentation
cancelOrder(orderId: string, reason?: string): void;
Parameters
NameTypeDescription
orderId
string

the ID of the order to cancel

reason
string

optional reason for cancelation

Returns

void

cancelPendingOrder()

Cancels all pending orders that were sent through given OrderProcessor.

Pending orders are the one having statuses PendingSubmit, PreSubmit, Submitted or PartiallyFilled. See OrderStatus description for details.

Presentation
cancelPendingOrder(instrumentOrPortfolio?: string): void;
Parameters
NameTypeDescription
instrumentOrPortfolio
string

the instrument or portfolio name to cancel orders for

Returns

void

cancelReplaceOrder()

Sends a request to replace the original order with a new one. The original order is canceled, and new one (specified by replacementOrder) comes into effect. This conforms to the following rules:

  • If the replacement is successful, the original order receives a status of Canceled and new one becomes Submitted.
  • If the replacement fails, the original order remains in its current state, and the new one is rejected.
Presentation
cancelReplaceOrder(originalOrder: Order, replacementOrder: Order): void;
Parameters
NameTypeDescription
originalOrder
Order

the original order to be replaced

replacementOrder
Order

the replacement order to be sent

Returns

void

getLongPositionSymbols()

Get list of instruments for which a long position exists

Presentation
getLongPositionSymbols(portfolio?: string): string[];
Parameters
NameTypeDescription
portfolio
string

optional portfolio name

Returns

string[]

getNextValidOrderId()

Generates the next valid order identifier. Commonly used when creating orders.

Presentation
getNextValidOrderId(): string;
Returns

string

getOrder()

Gets an order by its identifier. A particular strategy can only get orders that it sent.

Presentation
getOrder(order: Order): void;
Parameters
NameTypeDescription
order
Order
Returns

void

getOrders()

Get a list of all orders for an instrument in a particular portfolio

Presentation
getOrders(instrumentOrPortfolio?: string, portfolio?: string): Order[];
Parameters
NameTypeDescription
instrumentOrPortfolio
string

instrument or portfolio name

portfolio
string

portfolio name

Returns

Order[]

getPendingOrders()

Get a list of all pending orders for an instrument in a particular portfolio

Presentation
getPendingOrders(instrumentOrPortfolio?: string, portfolio?: string): Order[];
Parameters
NameTypeDescription
instrumentOrPortfolio
string

instrument or portfolio name

portfolio
string

portfolio name

Returns

Order[]

getPosition()

Get the aggregate position for an instrument, portfolio, or an instrument in a portfolio

Presentation
getPosition(instrumentOrPortfolio: string, portfolio?: string): Position;
Parameters
NameTypeDescription
instrumentOrPortfolio
string

instrument or portfolio name

portfolio
string

portfolio name

Returns

Position

getPositionSymbols()

Get list of instruments for which a position exists

Presentation
getPositionSymbols(portfolio?: string): string[];
Parameters
NameTypeDescription
portfolio
string

optional portfolio name

Returns

string[]

getShortPositionSymbols()

Get list of instruments for which a short position exists

Presentation
getShortPositionSymbols(portfolio?: string): string[];
Parameters
NameTypeDescription
portfolio
string

optional portfolio name

Returns

string[]

modifyOrder()

Sends a request to modify an order to the target executor.

Presentation
modifyOrder(order: Order): void;
Parameters
NameTypeDescription
order
Order

The prepared update order object

Returns

void

sendOrder()

Sends an order to the target execution system.

Presentation
sendOrder(order: Order): void;
Parameters
NameTypeDescription
order
Order

The prepared order object to send

Returns

void