or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

account.mdcore.mdindex.mdinstruments.mdorders.mdpositions.mdpricing.mdtrades.mdtransactions.mdusers.md
tile.json

orders.mddocs/

Order Management

Create, list, modify, cancel orders. Supports market, limit, stop, take profit, stop loss, trailing stop loss.

API Methods

create

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);
  }
});

Convenience Methods

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

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 }

listPending

List all pending orders.

listPending(accountID: string, responseHandler: (response: Response) => void): void;

Response: { orders: Order[], lastTransactionID: string }

get

Get specific order details.

get(accountID: string, orderSpecifier: string, responseHandler: (response: Response) => void): void;

Response: { order: Order, lastTransactionID: string }

replace

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

Cancel a pending order.

cancel(accountID: string, orderSpecifier: string, responseHandler: (response: Response) => void): void;

Response: { orderCancelTransaction: Transaction, lastTransactionID: string }

setClientExtensions

Set or modify client extensions on an order.

setClientExtensions(
  accountID: string,
  orderSpecifier: string,
  bodyParams: {
    clientExtensions?: ClientExtensions;
    tradeClientExtensions?: ClientExtensions;
  },
  responseHandler: (response: Response) => void
): void;

Order Types

MarketOrderRequest

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;
}

LimitOrderRequest

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;
}

StopOrderRequest

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;
}

MarketIfTouchedOrderRequest

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;
}

TakeProfitOrderRequest

interface TakeProfitOrderRequest {
  type: 'TAKE_PROFIT';
  tradeID: string;
  clientTradeID?: string;
  price: string;
  timeInForce?: 'GTC' | 'GFD' | 'GTD';
  gtdTime?: string;
  triggerCondition?: string;
  clientExtensions?: ClientExtensions;
}

StopLossOrderRequest

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;
}

TrailingStopLossOrderRequest

interface TrailingStopLossOrderRequest {
  type: 'TRAILING_STOP_LOSS';
  tradeID: string;
  clientTradeID?: string;
  distance: string;
  timeInForce?: 'GTC' | 'GFD' | 'GTD';
  gtdTime?: string;
  triggerCondition?: string;
  clientExtensions?: ClientExtensions;
}

Supporting Types

ClientExtensions

interface ClientExtensions {
  id?: string;
  tag?: string;
  comment?: string;
}

TakeProfitDetails

interface TakeProfitDetails {
  price: string;
  timeInForce?: 'GTC' | 'GFD' | 'GTD';
  gtdTime?: string;
  clientExtensions?: ClientExtensions;
}

StopLossDetails

interface StopLossDetails {
  price?: string;
  distance?: string;
  timeInForce?: 'GTC' | 'GFD' | 'GTD';
  gtdTime?: string;
  guaranteed?: boolean;
  clientExtensions?: ClientExtensions;
}

TrailingStopLossDetails

interface TrailingStopLossDetails {
  distance: string;
  timeInForce?: 'GTC' | 'GFD' | 'GTD';
  gtdTime?: string;
  clientExtensions?: ClientExtensions;
}

Enumerations

OrderState

  • PENDING - Order is pending execution
  • FILLED - Order has been filled
  • TRIGGERED - Order has been triggered
  • CANCELLED - Order has been cancelled

OrderType

  • MARKET - Immediate execution
  • LIMIT - Buy/sell at specified price or better
  • STOP - Triggered when price reaches stop price
  • MARKET_IF_TOUCHED - Becomes market order when price touched
  • TAKE_PROFIT - Close trade at profit target
  • STOP_LOSS - Close trade at loss limit
  • TRAILING_STOP_LOSS - Close trade with trailing stop
  • FIXED_PRICE - Execute at fixed price

TimeInForce

  • GTC - Good Till Cancelled
  • GTD - Good Till Date
  • GFD - Good For Day
  • FOK - Fill Or Kill
  • IOC - Immediate Or Cancel

OrderPositionFill

  • DEFAULT - Use account's default behavior
  • OPEN_ONLY - Only open new positions
  • REDUCE_FIRST - Reduce existing positions first
  • REDUCE_ONLY - Only reduce existing positions

OrderTriggerCondition

  • DEFAULT - Ask for buy orders, bid for sell orders
  • INVERSE - Ask for sell orders, bid for buy orders
  • BID - Use bid price
  • ASK - Use ask price
  • MID - Use mid price

Error Handling

ctx.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:

  • 400 Bad Request - Invalid parameters, insufficient margin, instrument not tradeable
  • 401 Unauthorized - Invalid or missing token
  • 403 Forbidden - Operation not allowed
  • 404 Not Found - Account or order not found