Create, list, modify, cancel orders. Supports market, limit, stop, take profit, stop loss, trailing stop loss.
Create a new order.
create(
accountID: string,
bodyParams: { order: OrderRequest },
responseHandler: (response: Response) => void
): void;Response: { orderCreateTransaction: Transaction, orderFillTransaction?: Transaction, lastTransactionID: string }
Example:
ctx.order.create(accountID, {
order: {
type: 'MARKET',
instrument: 'EUR_USD',
units: '1000',
timeInForce: 'FOK',
positionFill: 'DEFAULT',
takeProfitOnFill: { price: '1.1050' },
stopLossOnFill: { price: '1.0950' }
}
}, (response) => {
if (response.isSuccess()) {
console.log(response.body.orderCreateTransaction.id);
}
});market(accountID: string, orderSpec: object, responseHandler: (response: Response) => void): void;
limit(accountID: string, orderSpec: object, responseHandler: (response: Response) => void): void;
stop(accountID: string, orderSpec: object, responseHandler: (response: Response) => void): void;
marketIfTouched(accountID: string, orderSpec: object, responseHandler: (response: Response) => void): void;
takeProfit(accountID: string, orderSpec: object, responseHandler: (response: Response) => void): void;
stopLoss(accountID: string, orderSpec: object, responseHandler: (response: Response) => void): void;
trailingStopLoss(accountID: string, orderSpec: object, responseHandler: (response: Response) => void): void;Example:
ctx.order.market(accountID, {
instrument: 'EUR_USD',
units: '1000',
takeProfitOnFill: { price: '1.1050' }
}, callback);List orders with optional filtering.
list(
accountID: string,
queryParams: {
ids?: string;
state?: string;
instrument?: string;
count?: number;
beforeID?: string;
},
responseHandler: (response: Response) => void
): void;Response: { orders: Order[], lastTransactionID: string }
List all pending orders.
listPending(accountID: string, responseHandler: (response: Response) => void): void;Response: { orders: Order[], lastTransactionID: string }
Get specific order details.
get(accountID: string, orderSpecifier: string, responseHandler: (response: Response) => void): void;Response: { order: Order, lastTransactionID: string }
Replace an existing order.
replace(
accountID: string,
orderSpecifier: string,
bodyParams: { order: OrderRequest },
responseHandler: (response: Response) => void
): void;Response: { orderCancelTransaction: Transaction, orderCreateTransaction: Transaction, lastTransactionID: string }
Cancel a pending order.
cancel(accountID: string, orderSpecifier: string, responseHandler: (response: Response) => void): void;Response: { orderCancelTransaction: Transaction, lastTransactionID: string }
Set or modify client extensions on an order.
setClientExtensions(
accountID: string,
orderSpecifier: string,
bodyParams: {
clientExtensions?: ClientExtensions;
tradeClientExtensions?: ClientExtensions;
},
responseHandler: (response: Response) => void
): void;interface MarketOrderRequest {
type: 'MARKET';
instrument: string;
units: string;
timeInForce?: 'FOK' | 'IOC';
priceBound?: string;
positionFill?: 'DEFAULT' | 'OPEN_ONLY' | 'REDUCE_FIRST' | 'REDUCE_ONLY';
clientExtensions?: ClientExtensions;
takeProfitOnFill?: TakeProfitDetails;
stopLossOnFill?: StopLossDetails;
trailingStopLossOnFill?: TrailingStopLossDetails;
tradeClientExtensions?: ClientExtensions;
}interface LimitOrderRequest {
type: 'LIMIT';
instrument: string;
units: string;
price: string;
timeInForce?: 'GTC' | 'GTD' | 'GFD' | 'FOK' | 'IOC';
gtdTime?: string;
positionFill?: string;
triggerCondition?: 'DEFAULT' | 'INVERSE' | 'BID' | 'ASK' | 'MID';
clientExtensions?: ClientExtensions;
takeProfitOnFill?: TakeProfitDetails;
stopLossOnFill?: StopLossDetails;
trailingStopLossOnFill?: TrailingStopLossDetails;
tradeClientExtensions?: ClientExtensions;
}interface StopOrderRequest {
type: 'STOP';
instrument: string;
units: string;
price: string;
priceBound?: string;
timeInForce?: string;
gtdTime?: string;
positionFill?: string;
triggerCondition?: string;
clientExtensions?: ClientExtensions;
takeProfitOnFill?: TakeProfitDetails;
stopLossOnFill?: StopLossDetails;
trailingStopLossOnFill?: TrailingStopLossDetails;
tradeClientExtensions?: ClientExtensions;
}interface MarketIfTouchedOrderRequest {
type: 'MARKET_IF_TOUCHED';
instrument: string;
units: string;
price: string;
priceBound?: string;
timeInForce?: 'GTC' | 'GFD' | 'GTD';
gtdTime?: string;
positionFill?: string;
triggerCondition?: string;
clientExtensions?: ClientExtensions;
takeProfitOnFill?: TakeProfitDetails;
stopLossOnFill?: StopLossDetails;
trailingStopLossOnFill?: TrailingStopLossDetails;
tradeClientExtensions?: ClientExtensions;
}interface TakeProfitOrderRequest {
type: 'TAKE_PROFIT';
tradeID: string;
clientTradeID?: string;
price: string;
timeInForce?: 'GTC' | 'GFD' | 'GTD';
gtdTime?: string;
triggerCondition?: string;
clientExtensions?: ClientExtensions;
}interface StopLossOrderRequest {
type: 'STOP_LOSS';
tradeID: string;
clientTradeID?: string;
price?: string;
distance?: string;
timeInForce?: 'GTC' | 'GFD' | 'GTD';
gtdTime?: string;
triggerCondition?: string;
guaranteed?: boolean;
clientExtensions?: ClientExtensions;
}interface TrailingStopLossOrderRequest {
type: 'TRAILING_STOP_LOSS';
tradeID: string;
clientTradeID?: string;
distance: string;
timeInForce?: 'GTC' | 'GFD' | 'GTD';
gtdTime?: string;
triggerCondition?: string;
clientExtensions?: ClientExtensions;
}interface ClientExtensions {
id?: string;
tag?: string;
comment?: string;
}interface TakeProfitDetails {
price: string;
timeInForce?: 'GTC' | 'GFD' | 'GTD';
gtdTime?: string;
clientExtensions?: ClientExtensions;
}interface StopLossDetails {
price?: string;
distance?: string;
timeInForce?: 'GTC' | 'GFD' | 'GTD';
gtdTime?: string;
guaranteed?: boolean;
clientExtensions?: ClientExtensions;
}interface TrailingStopLossDetails {
distance: string;
timeInForce?: 'GTC' | 'GFD' | 'GTD';
gtdTime?: string;
clientExtensions?: ClientExtensions;
}PENDING - Order is pending executionFILLED - Order has been filledTRIGGERED - Order has been triggeredCANCELLED - Order has been cancelledMARKET - Immediate executionLIMIT - Buy/sell at specified price or betterSTOP - Triggered when price reaches stop priceMARKET_IF_TOUCHED - Becomes market order when price touchedTAKE_PROFIT - Close trade at profit targetSTOP_LOSS - Close trade at loss limitTRAILING_STOP_LOSS - Close trade with trailing stopFIXED_PRICE - Execute at fixed priceGTC - Good Till CancelledGTD - Good Till DateGFD - Good For DayFOK - Fill Or KillIOC - Immediate Or CancelDEFAULT - Use account's default behaviorOPEN_ONLY - Only open new positionsREDUCE_FIRST - Reduce existing positions firstREDUCE_ONLY - Only reduce existing positionsDEFAULT - Ask for buy orders, bid for sell ordersINVERSE - Ask for sell orders, bid for buy ordersBID - Use bid priceASK - Use ask priceMID - Use mid pricectx.order.create(accountID, { order: orderSpec }, (response) => {
if (response.isSuccess()) {
console.log('Order created:', response.body.orderCreateTransaction);
} else if (response.isClientError()) {
console.error('Client error:', response.body.errorCode, response.body.errorMessage);
if (response.body.orderRejectTransaction) {
console.error('Rejection reason:', response.body.orderRejectTransaction.rejectReason);
}
}
});Common errors: