Copyright © 2014, Rotman School of Management. 15
Sample Code 4 – Using AddQueuedOrder:
Similar to AddOrder, you can also use AddQueuedOrder to submit a limit or market, buy or sell order.
While all the parameters for AddQueuedOrder are the same as for AddOrder, the difference lies in
the return value. While AddOrder returns True/False, AddQueuedOrder will return -1 (for failure to
submit an order when the case is inactive) or an internal queued order ID* (for successful order
submission).
Dim status as variant
status = API.AddQueuedOrder("CRZY", 1000, 5, API.BUY, API.LMT)
*When an order is submitted using either AddOrder or AddQueuedOrder API command, the RIT
Server ‘queues’ an order before processing it in the system. Hence, when each order is queued, an
internal queued order ID is first provided, and is converted later to an order ID when it appears on
the Market Depth Book. This entire order submission process is generally completed in a fraction of
a second when there are not many orders. However, one may choose to specifically use
AddQueuedOrder in order to retrieve an internal queued order ID and cancel it individually before
an order is processed. For more detailed information, please refer to ‘Sample Code 3 – Using
CancelQueuedOrder’ under the ‘Cancelling an Order’ section below.
In addition, you can use the IsOrderQueued command to see if any particular order is currently
queued. The command requires an internal queue ID as an input, and returns “True” for the order
that is queued (at the moment), and “False” for any orders that are not queued (i.e. whether the order
has been queued previously but successfully submitted, or simply the order has failed to be queued).
Dim status as variant
status = API.AddQueuedOrder("CRZY", 1000, 5, API.BUY, API.LMT)
API.IsOrderQueued(status)
From the above example, the IsOrderQueued command will return “False” because by the time that
the VBA code reaches the “
API.IsOrderQueued(status)” line, the order has been already
queued and submitted from the API.AddQueuedOrder command. Hence, the command will return
“False” since the order is not queued anymore. If there are several orders submitted by the API code,
the IsOrderQueued command may return “True” if it is still queued.
Cancelling an Order
The following command cancels an order based on the order ID specified by the parameter.
General command Syntax:
API.CancelOrder (order_id)