Handling trade subscriptions
Before you can launch an algo, you must first create an instance of the AlgoTradeSubscription class. Like the [instrtradesub class, the AlgoTradeSubscription class is derived from the TradeSubscription class. The InstrumentTradeSubscription class filters on a given exchange native instrument whereas the AlgoTradeSubscription class filters on a specific algo. The AlgoTradeSubscription class is created as follows.
private AlgoLookup m_alookup = null;
private AlgoTradeSubscription m_ats = null;
public void apiInstance_TTAPIStatusUpdate(object sender, TTAPIStatusUpdateEventArgs e)
{
if (e.IsReady)
{
m_alookup = new AlgoLookup(tt_net_sdk.Dispatcher.Current, “TT Stop”);
ProductDataEvent ev = m_alookup.Get();
if (ev == ProductDataEvent.Found)
{
// Algo was found
m_ats = new AlgoTradeSubscription(tt_net_sdk.Dispatcher.Current, m_alookup.Algo);
m_ats.OrderUpdated += m_ats_OrderUpdated;
m_ats.OrderAdded += m_ats_OrderAdded;
m_ats.OrderDeleted += m_ats_OrderDeleted;
m_ats.OrderFilled += m_ats_OrderFilled;
m_ats.OrderRejected += m_ats_OrderRejected;
m_ats.OrderBookDownload += m_ats_OrderBookDownload;
m_ats.ExportValuesUpdated += m_ats_ExportValuesUpdated;
m_ats.Start();
}
else
{
// Algo was not found
Console.WriteLine("Cannot find algo: {0}", ev.ToString());
}
}
}
After the OrderBookDownload event has fired, you can create an OrderProfile instance by calling the GetOrderProfile() method of the Algo instance, fill in the algo’s parameters and launch an instance of an algo.
Note the new event named ExportValuesUpdated. This optional event is specifically used to receive updates for ADL algos that have exported values.
The following code snippet shows the structure for this event handler.
void m_ats_ExportValuesUpdated(object sender, ExportValuesUpdatedEventArgs e)
{
foreach (string key in e.ExportValues.Keys)
{
Console.WriteLine("Parameter Name = {0} and Parameter Value = {1}", key, e.ExportValues[key]);
}
}
Note: Exported variable updates are coalesced at 250ms.