or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

account.mdcore.mdindex.mdorder.mdposition.mdpricing.mdtrade.mdtransaction.mduser.md
tile.json

order.mddocs/

Order Management

Complete order lifecycle management with support for multiple order types including market, limit, stop, market-if-touched, take-profit, stop-loss, and trailing-stop-loss orders. Operations include order creation, modification, cancellation, and client extension management.

All order operations are accessed via ctx.order where ctx is a Context instance.

Capabilities

Create Order

Create a new order for an Account.

/**
 * Create an Order
 * @param accountID - Account identifier
 * @param bodyParams - Body parameters object
 *   - order: OrderRequest (required - market, limit, stop, MIT, TP, SL, or TSL order request)
 * @param responseHandler - Callback receiving Response object
 * Response body varies by order type and result (filled, pending, rejected)
 */
create(accountID, bodyParams, responseHandler);

Usage Example:

// Create a market order
ctx.order.create('001-001-1234567-001', {
  order: {
    type: 'MARKET',
    instrument: 'EUR_USD',
    units: '100',
    timeInForce: 'FOK',
    positionFill: 'DEFAULT'
  }
}, response => {
  if (response.isSuccess()) {
    console.log('Order filled:', response.body.orderFillTransaction);
  }
});

// Create a limit order
ctx.order.create('001-001-1234567-001', {
  order: {
    type: 'LIMIT',
    instrument: 'EUR_USD',
    units: '100',
    price: '1.1000',
    timeInForce: 'GTC'
  }
}, response => {
  if (response.isSuccess()) {
    console.log('Limit order created:', response.body.orderCreateTransaction);
  }
});

List Orders

Get a list of Orders for an Account.

/**
 * Get list of Orders for Account
 * @param accountID - Account identifier
 * @param queryParams - Query parameters object
 *   - ids: string (comma-separated list of Order IDs, optional)
 *   - state: string (order state filter: PENDING, FILLED, TRIGGERED, CANCELLED, optional)
 *   - instrument: string (instrument filter, optional)
 *   - count: number (maximum orders to return, optional, default 50)
 *   - beforeID: string (orders before this ID, optional)
 * @param responseHandler - Callback receiving Response object
 * Response body contains: { orders: Order[], lastTransactionID: string }
 */
list(accountID, queryParams, responseHandler);

Usage Example:

// List all orders
ctx.order.list('001-001-1234567-001', {}, response => {
  if (response.isSuccess()) {
    response.body.orders.forEach(order => {
      console.log(`Order ${order.id}: ${order.type} ${order.instrument} ${order.units}`);
    });
  }
});

// List pending orders for specific instrument
ctx.order.list('001-001-1234567-001', {
  state: 'PENDING',
  instrument: 'EUR_USD'
}, response => {
  if (response.isSuccess()) {
    console.log('Pending EUR_USD orders:', response.body.orders);
  }
});

List Pending Orders

Get a list of all pending Orders for an Account.

/**
 * Get list of pending Orders
 * @param accountID - Account identifier
 * @param responseHandler - Callback receiving Response object
 * Response body contains: { orders: Order[], lastTransactionID: string }
 */
listPending(accountID, responseHandler);

Get Order Details

Get details of a specific Order.

/**
 * Get details of specific Order
 * @param accountID - Account identifier
 * @param orderSpecifier - Order ID or client Order ID
 * @param responseHandler - Callback receiving Response object
 * Response body contains: { order: Order, lastTransactionID: string }
 */
get(accountID, orderSpecifier, responseHandler);

Replace Order

Replace an Order by simultaneously cancelling it and creating a replacement Order.

/**
 * Replace an Order
 * @param accountID - Account identifier
 * @param orderSpecifier - Order ID or client Order ID
 * @param bodyParams - Body parameters object
 *   - order: OrderRequest (required - replacement order specification)
 * @param responseHandler - Callback receiving Response object
 * Response body contains cancellation and creation transaction details
 */
replace(accountID, orderSpecifier, bodyParams, responseHandler);

Usage Example:

// Replace a limit order with different price
ctx.order.replace('001-001-1234567-001', '1234', {
  order: {
    type: 'LIMIT',
    instrument: 'EUR_USD',
    units: '100',
    price: '1.1050',  // New price
    timeInForce: 'GTC'
  }
}, response => {
  if (response.isSuccess()) {
    console.log('Order replaced');
    console.log('Cancelled:', response.body.orderCancelTransaction);
    console.log('Created:', response.body.orderCreateTransaction);
  }
});

Cancel Order

Cancel a pending Order.

/**
 * Cancel an Order
 * @param accountID - Account identifier
 * @param orderSpecifier - Order ID or client Order ID
 * @param responseHandler - Callback receiving Response object
 * Response body contains: { orderCancelTransaction: OrderCancelTransaction, lastTransactionID: string }
 */
cancel(accountID, orderSpecifier, responseHandler);

Usage Example:

ctx.order.cancel('001-001-1234567-001', '1234', response => {
  if (response.isSuccess()) {
    console.log('Order cancelled:', response.body.orderCancelTransaction);
  }
});

Set Client Extensions

Update the client extensions for an Order.

/**
 * Update client extensions for Order
 * @param accountID - Account identifier
 * @param orderSpecifier - Order ID or client Order ID
 * @param bodyParams - Body parameters object
 *   - clientExtensions: ClientExtensions (optional)
 *   - tradeClientExtensions: ClientExtensions (optional - for orders that create trades)
 * @param responseHandler - Callback receiving Response object
 * Response body contains modification transaction details
 */
setClientExtensions(accountID, orderSpecifier, bodyParams, responseHandler);

Usage Example:

ctx.order.setClientExtensions('001-001-1234567-001', '1234', {
  clientExtensions: {
    id: 'my-order-123',
    tag: 'momentum-strategy',
    comment: 'Breakout entry'
  }
}, response => {
  if (response.isSuccess()) {
    console.log('Client extensions updated');
  }
});

Helper Methods

Convenience methods for creating and replacing specific order types:

/**
 * Create a Market Order
 * @param accountID - Account identifier
 * @param orderSpec - Market order specification object
 * @param responseCallback - Callback receiving Response object
 */
market(accountID, orderSpec, responseCallback);

/**
 * Create a Limit Order
 * @param accountID - Account identifier
 * @param orderSpec - Limit order specification object
 * @param responseCallback - Callback receiving Response object
 */
limit(accountID, orderSpec, responseCallback);

/**
 * Replace a Limit Order
 * @param accountID - Account identifier
 * @param orderID - Order ID to replace
 * @param orderSpec - New limit order specification object
 * @param responseCallback - Callback receiving Response object
 */
limitReplace(accountID, orderID, orderSpec, responseCallback);

/**
 * Create a Stop Order
 * @param accountID - Account identifier
 * @param orderSpec - Stop order specification object
 * @param responseCallback - Callback receiving Response object
 */
stop(accountID, orderSpec, responseCallback);

/**
 * Replace a Stop Order
 * @param accountID - Account identifier
 * @param orderID - Order ID to replace
 * @param orderSpec - New stop order specification object
 * @param responseCallback - Callback receiving Response object
 */
stopReplace(accountID, orderID, orderSpec, responseCallback);

/**
 * Create a Market-If-Touched Order
 * @param accountID - Account identifier
 * @param orderSpec - MIT order specification object
 * @param responseCallback - Callback receiving Response object
 */
marketIfTouched(accountID, orderSpec, responseCallback);

/**
 * Replace a Market-If-Touched Order
 * @param accountID - Account identifier
 * @param orderID - Order ID to replace
 * @param orderSpec - New MIT order specification object
 * @param responseCallback - Callback receiving Response object
 */
marketIfTouchedReplace(accountID, orderID, orderSpec, responseCallback);

/**
 * Create a Take Profit Order
 * @param accountID - Account identifier
 * @param orderSpec - Take profit order specification object
 * @param responseCallback - Callback receiving Response object
 */
takeProfit(accountID, orderSpec, responseCallback);

/**
 * Replace a Take Profit Order
 * @param accountID - Account identifier
 * @param orderID - Order ID to replace
 * @param orderSpec - New take profit order specification object
 * @param responseCallback - Callback receiving Response object
 */
takeProfitReplace(accountID, orderID, orderSpec, responseCallback);

/**
 * Create a Stop Loss Order
 * @param accountID - Account identifier
 * @param orderSpec - Stop loss order specification object
 * @param responseCallback - Callback receiving Response object
 */
stopLoss(accountID, orderSpec, responseCallback);

/**
 * Replace a Stop Loss Order
 * @param accountID - Account identifier
 * @param orderID - Order ID to replace
 * @param orderSpec - New stop loss order specification object
 * @param responseCallback - Callback receiving Response object
 */
stopLossReplace(accountID, orderID, orderSpec, responseCallback);

/**
 * Create a Trailing Stop Loss Order
 * @param accountID - Account identifier
 * @param orderSpec - Trailing stop loss order specification object
 * @param responseCallback - Callback receiving Response object
 */
trailingStopLoss(accountID, orderSpec, responseCallback);

/**
 * Replace a Trailing Stop Loss Order
 * @param accountID - Account identifier
 * @param orderID - Order ID to replace
 * @param orderSpec - New trailing stop loss order specification object
 * @param responseCallback - Callback receiving Response object
 */
trailingStopLossReplace(accountID, orderID, orderSpec, responseCallback);

Helper Method Usage Example:

// Using helper method instead of create()
ctx.order.market('001-001-1234567-001', {
  instrument: 'EUR_USD',
  units: '100',
  timeInForce: 'FOK'
}, response => {
  if (response.isSuccess()) {
    console.log('Market order executed');
  }
});

// Create stop loss order
ctx.order.stopLoss('001-001-1234567-001', {
  tradeID: '5678',
  price: '1.0950',
  timeInForce: 'GTC'
}, response => {
  if (response.isSuccess()) {
    console.log('Stop loss created');
  }
});

Types

Order Request Types

When creating orders using the create() method, you pass an OrderRequest object. Each order type has a corresponding request type:

/**
 * Base class for all order requests
 */
interface OrderRequest {
  type: string;  // Order type
}

/**
 * Request to create a Market Order
 */
interface MarketOrderRequest extends OrderRequest {
  type: 'MARKET';
  instrument: string;
  units: string;
  timeInForce: string;  // FOK, IOC
  priceBound?: string;
  positionFill?: string;  // DEFAULT, OPEN_ONLY, REDUCE_FIRST, REDUCE_ONLY
  tradeClose?: MarketOrderTradeClose;
  longPositionCloseout?: MarketOrderPositionCloseout;
  shortPositionCloseout?: MarketOrderPositionCloseout;
  marginCloseout?: MarketOrderMarginCloseout;
  delayedTradeClose?: MarketOrderDelayedTradeClose;
  takeProfitOnFill?: TakeProfitDetails;
  stopLossOnFill?: StopLossDetails;
  trailingStopLossOnFill?: TrailingStopLossDetails;
  tradeClientExtensions?: ClientExtensions;
  clientExtensions?: ClientExtensions;
}

/**
 * Request to create a Limit Order
 */
interface LimitOrderRequest extends OrderRequest {
  type: 'LIMIT';
  instrument: string;
  units: string;
  price: string;
  timeInForce: string;  // GTC, GTD, GFD, FOK, IOC
  gtdTime?: string;
  positionFill?: string;
  triggerCondition?: string;
  takeProfitOnFill?: TakeProfitDetails;
  stopLossOnFill?: StopLossDetails;
  trailingStopLossOnFill?: TrailingStopLossDetails;
  tradeClientExtensions?: ClientExtensions;
  clientExtensions?: ClientExtensions;
}

/**
 * Request to create a Stop Order
 */
interface StopOrderRequest extends OrderRequest {
  type: 'STOP';
  instrument: string;
  units: string;
  price: string;
  priceBound?: string;
  timeInForce: string;  // GTC, GTD, GFD, FOK, IOC
  gtdTime?: string;
  positionFill?: string;
  triggerCondition?: string;
  takeProfitOnFill?: TakeProfitDetails;
  stopLossOnFill?: StopLossDetails;
  trailingStopLossOnFill?: TrailingStopLossDetails;
  tradeClientExtensions?: ClientExtensions;
  clientExtensions?: ClientExtensions;
}

/**
 * Request to create a Market-If-Touched Order
 */
interface MarketIfTouchedOrderRequest extends OrderRequest {
  type: 'MARKET_IF_TOUCHED';
  instrument: string;
  units: string;
  price: string;
  priceBound?: string;
  timeInForce: string;  // GTC, GTD, GFD
  gtdTime?: string;
  positionFill?: string;
  triggerCondition?: string;
  takeProfitOnFill?: TakeProfitDetails;
  stopLossOnFill?: StopLossDetails;
  trailingStopLossOnFill?: TrailingStopLossDetails;
  tradeClientExtensions?: ClientExtensions;
  clientExtensions?: ClientExtensions;
}

/**
 * Request to create a Take Profit Order
 */
interface TakeProfitOrderRequest extends OrderRequest {
  type: 'TAKE_PROFIT';
  tradeID: string;
  clientTradeID?: string;
  price: string;
  timeInForce?: string;  // GTC, GTD, GFD
  gtdTime?: string;
  triggerCondition?: string;
  clientExtensions?: ClientExtensions;
}

/**
 * Request to create a Stop Loss Order
 */
interface StopLossOrderRequest extends OrderRequest {
  type: 'STOP_LOSS';
  tradeID: string;
  clientTradeID?: string;
  price?: string;
  distance?: string;
  timeInForce?: string;  // GTC, GTD, GFD
  gtdTime?: string;
  triggerCondition?: string;
  guaranteed?: boolean;
  clientExtensions?: ClientExtensions;
}

/**
 * Request to create a Trailing Stop Loss Order
 */
interface TrailingStopLossOrderRequest extends OrderRequest {
  type: 'TRAILING_STOP_LOSS';
  tradeID: string;
  clientTradeID?: string;
  distance: string;
  timeInForce?: string;  // GTC, GTD, GFD
  gtdTime?: string;
  triggerCondition?: string;
  clientExtensions?: ClientExtensions;
}

Order Base Properties

Common properties for all order types:

interface OrderBase {
  id: string;
  createTime: string;
  state: string;  // PENDING, FILLED, TRIGGERED, CANCELLED
  clientExtensions?: ClientExtensions;
}

Market Order

Market Order for immediate execution at current market price.

interface MarketOrder extends OrderBase {
  type: 'MARKET';
  instrument: string;
  units: string;  // Positive for long, negative for short
  timeInForce: string;  // FOK or IOC
  priceBound?: string;  // Worst acceptable price
  positionFill: string;  // DEFAULT, OPEN_ONLY, REDUCE_FIRST, REDUCE_ONLY

  // Position closeout specifications
  tradeClose?: MarketOrderTradeClose;
  longPositionCloseout?: MarketOrderPositionCloseout;
  shortPositionCloseout?: MarketOrderPositionCloseout;
  marginCloseout?: MarketOrderMarginCloseout;
  delayedTradeClose?: MarketOrderDelayedTradeClose;

  // On-fill specifications
  takeProfitOnFill?: TakeProfitDetails;
  stopLossOnFill?: StopLossDetails;
  trailingStopLossOnFill?: TrailingStopLossDetails;
  tradeClientExtensions?: ClientExtensions;

  // Fill details (populated after execution)
  fillingTransactionID?: string;
  filledTime?: string;
  tradeOpenedID?: string;
  tradeReducedID?: string;
  tradeClosedIDs?: string[];

  // Cancellation details
  cancellingTransactionID?: string;
  cancelledTime?: string;
}

Limit Order

Limit Order to be filled at specified price or better.

interface LimitOrder extends OrderBase {
  type: 'LIMIT';
  instrument: string;
  units: string;
  price: string;  // Limit price
  timeInForce: string;  // GTC, GTD, GFD, FOK, IOC
  gtdTime?: string;  // GTD expiry time
  positionFill: string;
  triggerCondition: string;  // DEFAULT, INVERSE, BID, ASK, MID

  // On-fill specifications
  takeProfitOnFill?: TakeProfitDetails;
  stopLossOnFill?: StopLossDetails;
  trailingStopLossOnFill?: TrailingStopLossDetails;
  tradeClientExtensions?: ClientExtensions;

  // Fill details
  fillingTransactionID?: string;
  filledTime?: string;
  tradeOpenedID?: string;
  tradeReducedID?: string;
  tradeClosedIDs?: string[];

  // Cancellation/trigger details
  cancellingTransactionID?: string;
  cancelledTime?: string;
  replacesOrderID?: string;
  replacedByOrderID?: string;
}

Stop Order

Stop Order to be filled when price reaches trigger.

interface StopOrder extends OrderBase {
  type: 'STOP';
  instrument: string;
  units: string;
  price: string;  // Stop price
  priceBound?: string;  // Worst price for fill
  timeInForce: string;  // GTC, GTD, GFD, FOK, IOC
  gtdTime?: string;
  positionFill: string;
  triggerCondition: string;

  // On-fill specifications
  takeProfitOnFill?: TakeProfitDetails;
  stopLossOnFill?: StopLossDetails;
  trailingStopLossOnFill?: TrailingStopLossDetails;
  tradeClientExtensions?: ClientExtensions;

  // Fill/trigger details
  fillingTransactionID?: string;
  filledTime?: string;
  tradeOpenedID?: string;
  tradeReducedID?: string;
  tradeClosedIDs?: string[];

  // Cancellation/replacement details
  cancellingTransactionID?: string;
  cancelledTime?: string;
  replacesOrderID?: string;
  replacedByOrderID?: string;
}

Market-If-Touched Order

Market-if-touched Order becomes a Market Order when price touches trigger.

interface MarketIfTouchedOrder extends OrderBase {
  type: 'MARKET_IF_TOUCHED';
  instrument: string;
  units: string;
  price: string;  // Trigger price
  priceBound?: string;
  timeInForce: string;  // GTC, GTD, GFD
  gtdTime?: string;
  positionFill: string;
  triggerCondition: string;

  // On-fill specifications
  takeProfitOnFill?: TakeProfitDetails;
  stopLossOnFill?: StopLossDetails;
  trailingStopLossOnFill?: TrailingStopLossDetails;
  tradeClientExtensions?: ClientExtensions;

  // Fill/trigger details
  fillingTransactionID?: string;
  filledTime?: string;
  tradeOpenedID?: string;
  tradeReducedID?: string;
  tradeClosedIDs?: string[];

  // Cancellation/replacement details
  cancellingTransactionID?: string;
  cancelledTime?: string;
  replacesOrderID?: string;
  replacedByOrderID?: string;
}

Take Profit Order

Take Profit Order attached to a Trade.

interface TakeProfitOrder extends OrderBase {
  type: 'TAKE_PROFIT';
  tradeID: string;
  clientTradeID?: string;
  price: string;
  timeInForce: string;  // GTC, GTD, GFD
  gtdTime?: string;
  triggerCondition: string;

  // Fill details
  fillingTransactionID?: string;
  filledTime?: string;

  // Cancellation/replacement details
  cancellingTransactionID?: string;
  cancelledTime?: string;
  replacesOrderID?: string;
  replacedByOrderID?: string;
}

Stop Loss Order

Stop Loss Order attached to a Trade.

interface StopLossOrder extends OrderBase {
  type: 'STOP_LOSS';
  tradeID: string;
  clientTradeID?: string;
  price?: string;  // Either price or distance must be specified
  distance?: string;  // Distance from current price
  timeInForce: string;  // GTC, GTD, GFD
  gtdTime?: string;
  triggerCondition: string;
  guaranteed?: boolean;  // Guaranteed execution flag

  // Fill details
  fillingTransactionID?: string;
  filledTime?: string;

  // Cancellation/replacement details
  cancellingTransactionID?: string;
  cancelledTime?: string;
  replacesOrderID?: string;
  replacedByOrderID?: string;
}

Trailing Stop Loss Order

Trailing Stop Loss Order that follows price movements.

interface TrailingStopLossOrder extends OrderBase {
  type: 'TRAILING_STOP_LOSS';
  tradeID: string;
  clientTradeID?: string;
  distance: string;  // Trailing distance from current price
  timeInForce: string;  // GTC, GTD, GFD
  gtdTime?: string;
  triggerCondition: string;

  // Current trailing value
  trailingStopValue?: string;

  // Fill details
  fillingTransactionID?: string;
  filledTime?: string;

  // Cancellation/replacement details
  cancellingTransactionID?: string;
  cancelledTime?: string;
  replacesOrderID?: string;
  replacedByOrderID?: string;
}

Supporting Types

interface OrderIdentifier {
  orderID: string;
  clientOrderID?: string;
}

interface DynamicOrderState {
  id: string;
  trailingStopValue?: string;
  triggerDistance?: string;
  isTriggerDistanceExact?: boolean;
}

interface UnitsAvailable {
  default: UnitsAvailableDetails;
  reduceFirst: UnitsAvailableDetails;
  reduceOnly: UnitsAvailableDetails;
  openOnly: UnitsAvailableDetails;
}

interface UnitsAvailableDetails {
  long: string;
  short: string;
}

interface GuaranteedStopLossOrderEntryData {
  minimumDistance: string;
  premium: string;
  levelRestriction: GuaranteedStopLossOrderLevelRestriction;
}

interface MarketOrderTradeClose {
  tradeID: string;
  clientTradeID?: string;
  units: string;
}

interface MarketOrderPositionCloseout {
  instrument: string;
  units: string;  // "ALL" to close entire position
}

interface MarketOrderMarginCloseout {
  reason: string;
}

interface MarketOrderDelayedTradeClose {
  tradeID: string;
  clientTradeID?: string;
  sourceTransactionID: string;
}

interface TakeProfitDetails {
  price: string;
  timeInForce?: string;
  gtdTime?: string;
  clientExtensions?: ClientExtensions;
}

interface StopLossDetails {
  price?: string;
  distance?: string;
  timeInForce?: string;
  gtdTime?: string;
  clientExtensions?: ClientExtensions;
  guaranteed?: boolean;
}

interface TrailingStopLossDetails {
  distance: string;
  timeInForce?: string;
  gtdTime?: string;
  clientExtensions?: ClientExtensions;
}