TT CORE SDK
0.1
TT CORE SDK documentation
|
The OrderManager class handles the management of orders that are submitted through them. As such, you must create one or more instances of the OrderManager class class in order to submit, change, and cancel orders.
The OrderManager class is defined in the orders.hpp header file. It has a default constructor that can be used to create an instance as follows.
Before you submit an order, you must first create an instance of the order_profile struct. You then set the attributes of your order. This struct is defined in the orders.hpp header file. The attributes available are as follows:
Public Attributes | Description |
---|---|
account | Account ID |
instrument | Reference to a valid instance of an Instrument class The Instrument class is defined in the instrument.hpp file. |
price | Limit price in decimal (Points) |
quantity | Order quantity |
side | Order side The order_side enum is defined in the enums.hpp file. |
tif | Time in force The time_in_force enum is defined in the enums.hpp file. |
trigger_price | Stop order trigger price in decimal (Point); only required when order_type = STOP or STOP_LIMIT. |
type | Order type The order_type enum is defined in the enums.hpp file. |
The following example demonstrates how to create an instance of the order_profile struct for a limit order.
After you populate this structure, you must then create a handle to this order as follows:
The OrderHandle instance is a pointer to the internal representation of the order data that will be put on the wire when it is submitted. For the sake of efficiency, it is useful to pre-create one or more of these for the orders that you will be submitting.
An order is submitted by calling the PlaceOrder() method of the same instance of the OrderManager class that was used to create the OrderHandle instance.
A request ID that will be returned with the acknowledgements in order to correlate order events with their request is also passed.
The OrderHandle class provides the following methods for manipulating orders. Note: When the order referenced by the OrderHandle
reaches a terminal state (i.e. fully filled, deleted, rejected, etc.) the OrderHandle can no longer manipulate the order. In this case, a new OrderHandle
should be constructed.
Member Function | Description |
---|---|
ChangeOrder() | Change the order. void tt_core_sdk::OrderHandle::ChangeOrder(change_request & request); The change_request struct is defined in the orders.hpp file. |
ChangePrice() | Change the order price. |
ChangePriceQuantity() | Change the order price and quantity. void tt_core_sdk::OrderHandle::ChangePriceQuantity(double price, int32_t quantity, uint32_t request_id = 0); |
ChangeQuantity() | Change the order quantity. void tt_core_sdk::OrderHandle::ChangeQuantity(int32_t quantity, uint32_t request_id = 0); |
DeleteOrder() | Delete the order from the market. void tt_core_sdk::OrderHandle::DeleteOrder(uint32_t request_id = 0); |
GetOrderId() | TT Order ID. |
GetOrderQuantity() | Order quantity (0 if not available). |
GetPrice() | Order price (NAN if not available). |
GetWorkingQuantity() | Quantity working in the market (0 if not available). |
So, for example, the following code snippet demonstrates how to change an order’s quantity to ten.
As discussed, orders are submitted by calling the PlaceOrder() method of an instance of the OrderManager class. The TT Core SDK will fire the the inherited OrderEventListener() function associated with the instance of the OrderManager class for the initial order acknowledgment as well as all subsequent events for this order. To provide a listener to the OrderManager
, call the Subscribe() method.
The pure virtual methods of the OrderEventListener that must be overridden include:
In the above snippet one of the callbacks will be fired for every request. The parameter in each of the callbacks contains a request_id
that represents the id provided when making the request.
When the OnExecutionReport() callback is called, an instance of the execution_report_response struct is passed. This struct contain the following attributes.
Public Attribute | Description |
---|---|
er | Response details. Returns a ExecutionReport object, which is defined in the orders.hpp file. |
handle | Order tied to the response. Returns a OrderHandle object, which is defined in the orders.hpp file. |
request_id | Id of the request generating the response. |
Internally, TT uses the logical flows prescribed by the FIX Protocol (https://www.fixtrading.org/) to convey order state transitions. The er
variable is an instance of the ExecutionReport class, which communicates the data that is part of the FIX Protocol Execution Report message. This includes the reason for the Execution Report (“What happened?”) as well as the current state of the order. The ExecutionReport
class provides the following methods for extracting this data.
Member Function | Description |
---|---|
GetAccountId() | Account ID. |
GetAccountName() | Account name. |
GetBrokerId() | Broker ID. |
GetCumQty() | Total number of contracts that have filled over the life of this order. |
GetExecId() | Unique identifier for this execution report. |
GetExecType() | The reason that this execution report is being sent. |
IsDelete() | Helper method for determining if the reason for this message is because the order was deleted. |
IsFill() | Helper method for determining if the reason for this message is because the order was filled. |
IsFullFill() | Helper method for determining if the reason for this message is because the order was fully filled. |
IsPending() | helper method for determining if the reason for this message is because the order is in a pending state. |
IsReject() | Helper method for determining if the reason for this message is because the order was rejected. |
IsTriggerActivated() | Helper method for determining if the reason for this message is because the order was triggered. |
GetInstrumentId() | The TT ID for the instrument. |
GetLastFillPrice() | The price of the most recent fill. |
GetLastFillQty() | The quantity of the most recent fill. |
GetLeavesQty() | Number of contracts that are still working in the market. |
GetMarket() | The instrument’s market. |
GetOrderId() | The TT order ID. |
GetOrderQty() | The order's quantity. |
GetOrderRejectReason() | Reject details. The ord_rej_reason enum is defined in the enums.hpp file. |
GetOrderStatus() | Current status of the order. The order_status enum is defined in the enums.hpp file. |
GetOrderType() | Order type. The order_type enum is defined in the enums.hpp file. |
GetPrice() | The current price of the order. std::pair<bool, double> tt_core_sdk::ExecutionReport::GetLastPrice(void) const; |
GetRejectCode() | The reason for the rejection. The reject_code enum is defined in the enums.hpp file. |
GetRejectSource() | The source of the rejection. The reject_source enum is defined in the enums.hpp file. |
GetSide() | Order side. The order_side enum is defined in the enums.hpp file. |
GetText() | Any text included in the message. |
GetTimeInForce() | Order’s time if force. The time_in_force enum is defined in the enums.hpp file. |
GetTriggerPrice() | Order's trigger price. Only populated if the order type is STOP or STOP_LIMIT. |
With the exception of the Is…()
helper methods, all of these methods return a std::pair
. The “first” parameter is a bool
that indicates whether the data is present in the message. The “second” parameter is the actual data if the “first” parameter returns true
.
The following code snippet shows a sample OnExecutionReport() callback implementation.
When the OnOrderCancelReject() callback is called, an instance of the order_cancel_reject_response struct is passed. This struct contain the following attributes.
Public Attribute | Description |
---|---|
handle | Order tied to the response. Returns a OrderHandle object, which is defined in the orders.hpp file. |
ocr | Response details. Returns a OrderCancelReject object, which is defined in the orders.hpp file. |
request_id | Id of the request generating the response. |
As discussed, internally, TT uses the logical flows prescribed by the FIX Protocol (https://www.fixtrading.org/) to convey order state transitions. The ocr
variable is an instance of the OrderCancelReject class, which communicates the data that is part of the FIX Protocol Order Cancel Reject message. This includes the reason for the Order Cancel Reject (“What happened?”) as well as the current state of the order. The OrderCancelReject
class provides the following methods for extracting this data.
Member Function | Description |
---|---|
GetAccountId() | Account ID. |
GetAccountName() | Account name. |
GetBrokerId() | Broker ID. |
GetCancelRejectReason() | Reject details. std::pair<bool, cxl_rej_reason> tt_core_sdk::OrderCancelReject::GetOrderRejectReason(void) const; The cxl_rej_reason enum is defined in the enums.hpp file. |
GetInstrumentId() | TT ID for the instrument. The Instrument class is defined in the instrument.hpp file. |
GetMarket() | Instrument's market. |
GetOrderId() | TT order ID. |
GetOrderStatus() | Current status of the order. The order_status enum is defined in the enums.hpp file. |
GetOrderType() | Order type. The order_type enum is defined in the enums.hpp file. |
GetRejectCode() | Reason for the rejection. The reject_code enum is defined in the enums.hpp file. |
GetRejectSource() | Source of the rejection. The reject_source enum is defined in the enums.hpp file. |
GetSide() | Order side. The order_side enum is defined in the enums.hpp file. |
GetText() | Any text included in the message. |
GetTimeInForce() | Order’s time if force. The time_in_force enum is defined in the enums.hpp file. |
All of these methods return a std::pair
. The “first” parameter is a bool
that indicates whether the data is present in the message. The “second” parameter is the actual data if the “first” parameter returns true
.
The following code snippet shows a sample OnOrderCancelReject() callback implementation.
When the OnOrderTimeout() callback is called, an instance of the order_timeout_response struct is passed. This struct contains the following attributes.
Public Attribute | Description |
---|---|
handle | Order tied to the response. Returns a OrderHandle object, which is defined in the orders.hpp file. |
request_id | Id of the request generating the response. |
The following code snippet shows a sample OnOrderTimeout() callback implementation.
When the OnRequestFailed() callback is called, an instance of the request_failed_response struct is passed. This struct contains the following attributes.
Public Attribute | Description |
---|---|
handle | Order tied to the response. Returns a OrderHandle object, which is defined in the orders.hpp file. |
message | Message describing the failure. |
request_id | Id of the request generating the response. |
When an algo submits a new order or changes an existing order, the TT Core SDK stores the request ID provided with the request. The request IDs are then passed to the algo in the OrderEventListener callbacks to allow developers to determine which order request that a given event is in response to. When an algo submits a change request for an order, the TT Core SDK will immediately route the message to the exchange if no other change request is in flight.
If, however, there is another change request in flight, the TT Core SDK will queue the submitted change request as well as any further change requests for this order. Once a response for the in flight change request has been received, the TT Core SDK will conflate all request messages in the queue and route a single change request to the exchange. In other words, an algo may not receive an order event for every request that it submits. The request ID can be used to detect when this happens. For example, assume that the following order change messages were submitted prior to the algo receiving the acknowledgment for the initial order submission.
When the response is received for the initial order, a single message would be routed to the exchange with a quantity of 12 and a price of 155'07. And the algo would receive one order event callback with request ID set to 6.