Cleaning up
When you shut down your application, you should detach all event handlers and call the Dispose method for each instance of the TradeSubscription and FillsSubscription classes. For example:
When you shut down your application, you should detach all event handlers and call the Dispose method for each instance of the TradeSubscription and FillsSubscription classes. For example:
TT .NET SDK supports delivering Position-in-Queue (PIQ) for each of you orders. To create a PIQ subscription and start receiving updates:
Typically, you start an EPIQ subscription immediately after initializing the API. The following snippet demonstrates how to instantiate an EstimatedPositionInQueueSubscription instance:
Note: When you have a shared order book or if you have existing orders in the market, you will receive the EPIQ snapshot before receiving the live stream.
After the subscription starts, TT .NET SDK retrieves the EPIQ data for all of your orders and invokes the event handler method you registered with the subscription. Subsequent events are then fired as EPIQ changes.
The following code snippet shows the structure of a sample EPIQ subscription event handler method:
To modify an existing order, you create a new OrderProfileBase object based on the existing Order by calling the GetOrderProfile() method from the Order object. The new Order profile object contains the same property values as the existing Order. You can modify any properties of the Order profile object.
After making the desired changes, set the value of the OrderProfile.Action property to indicate how the existing order should be modified, as follows:
The following code snippet demonstrates how to change the price of an order with a given key assuming that a TradeSubscription object named m_ts has already been created.
In addition to creating a new OrderProfile profile from an existing Order so you can modify the order, you can also create a new OrderProfile profile object to use as a template for a new order. The Order.CreateNewOrderProfile() method creates an Order profile object with the same properties as the Order object; however, you can use it only to submit a new Order.
A trade subscription represents a view of a subset of a trader’s orders and fills. You can create more than one trade subscription in your TT .NET SDK application where each may have a view of a different subset of orders and fills. From within a trade subscription, you can subscribe for order status events to receive updates as orders are added, changed, filled, and deleted. You can also subscribe for notifications when P&L changes.
To create a trade subscription, you must create a TradeSubscription object and call the Start method.
TT .NET SDK allows you to obtain a snapshot of your positions and P&L at any point after the API has successfully synchronized the order books by calling either the TTAPI.GetPositionSnapshot() or TTAPI.GetPositionSnapshots() methods.
The former will return a single Position object for the AccountKey and InstrumentKey that are provided. The latter returns a collection of Position objects for all unique AccountKey / InstrumentKey pairs that you have at least one fill. For example,
Note: You must also set the TTAPIOptions.EnablePositions property to true.
You can also subscribe for position and P&L updates by registering for TTAPI.ProfitLossChanged events as follows.
To send a new order to an Exchange, you must first create an OrderProfile object, using one of its constructors, like the following:
After populating the OrderProfile properties with the appropriate settings that describe the order, you submit it to an exchange by calling the SendOrder() method from a TradeSubscription object. After TT .NET SDK sends the order, it creates an Order object that represents the working order associated with the original OrderProfile and delivers it in the TradeSubscription object’s order update events.
The following code snippet demonstrates a simple order routing example assuming that a TradeSubscription object named “m_ts” has already been created and the OrderBookDownload event has already fired.
TT .NET SDK offers two methods to receive fills.
A FillsSubscription object fires the following events.
If fills have not yet occurred, a FillListStart event will be received followed by a FillListEnd event. A FillBookDownload does not fire if there are no fills.
You can subscribe for update events as follows before calling the FillsSubscription.Start() method. The following example demonstrates this process.
The following code snippet shows the structure for these event handlers.
TT .NET SDK also allows publishing manual fills via the API as demonstrated in the following code snippet.
You can use the FillDownload class to download fills for a specific period of time. The FillDownload class allows you to select a start and end time, provided in nanos past the epoch. The download can be either synchronous via Get() or asynchronous via GetAsync().