Skip to main content

Order

'Order' object contains order information. It is a object used by Orders interface, and is also returned by Sell or Buy commands.

Orders are created by issuing Buy or Sell commands. The status field is the first indicator we should check to determine if an order was submitted successfully.

var order = Buy(symbol, qty, "day", "limit", price);
if (order.status === 'error') {
Alert.info("Order failed");
Log.error("Order to buy " + qty + " of " + symbol + " failed." );
return;
}

Status codes#

  • accepted: at first an order is in accepted state. This means the broker has successfully received your order - however it has not been processed yet.

  • new: once an order is processed by the broker, it is moved to a new status.

  • duplicate: if your algorithm tries to submit two or more orders with the same parameters: same symbol, same quantity, same limit price, etc. it's status will be set to duplicate and the order WILL NOT be submitted to the broker. This feature can be disabled via configuration, but I'd caution against doing so.

  • rejected or forbidden: in case there is an error, the status may be set to rejected or forbidden with additional information in statusCode field and extendedInfo fields. Such code can result with orders that do not have enough cash or equity to make a transaction. Example: Holding 1000 shares of AMC and issuing two orders to sell 1000 shares of AMC will result in the first order being accepted and the second forbidden.

Order object#

FieldField typeDescription
symbolStringthe symbol of the underlying
statusStringorder status (‘new’, ‘filled’, ‘partfilled’, ‘canceled’, ‘duplicate’, etc.)
statusCodeStringstatus code (as defined by the broker)
sideString‘buy’ or ‘sell’
qtyNumberthe number of shares in the order
typeString‘market’ or ‘limit’
limitPriceFloatlimit price if type is “limit”
timeInForceString‘Day’, ‘GTC’ (GoodTillCanceled), etc.
orderIdStringalphanumeric order id
createdDtDate/timetimestamp, i.e.’2020-10-20T17:30:37.769815’
partiallyFilledDtDate/timetimestamp of the last partial fill
partialFillQtyNumberpartial fill quantity (applicable to partially filled orders)
extendedInfoStringadditional information about the order (if any)
//retrieve all open orders
var orders = Orders.openOrders();
//iterate the orders array and print to the tasks log
orders.forEach(function(order) {
Log.info("Open order for " + order.symbol);
Log.info(" status: " + order.status);
Log.info(" side: " + order.side);
Log.info(" qty: " + order.qty);
Log.info(" type: " + order.type);
Log.info(" limitPrice: " + order.limitPrice);
Log.info(" timeInForce: " + order.timeInForce);
Log.info(" orderId: " + order.orderId);
Log.info("clientOrderId: " + order.clientOrderId);
});
//display some info in the UI
Alert.info("Found " + orders.length + " open orders.");