Launching an algo
Construct an OrderProfile
Algos are treated in the same way as exchange native orders in TT. As such, to launch an algo, you need to create an OrderProfile instance. An algo’s OrderProfile instance must be created from the AlgoLookup instance by calling the Algo.GetOrderProfile() method. This method has two overloads.
OrderProfile GetOrderProfile();
OrderProfile GetOrderProfile(Instrument);
Set the algo parameters
If your algo has a parameter with "Name" = "Instrument" and "FieldLocation" = "OrderProfile", then you must use the second of these. All TT Algos have such a parameter as do ADL algos that have declared one of its required instrument inputs as an Order Instrument. Otherwise, you use the first of these.
You then set the rest of the parameters in the OrderProfile. Some of the parameters are set using specific OrderProfile properties and some are set in the UserParameters collection as shown below. Specifically, if the "FieldLocation" of a parameter is equal to "OrderProfile", then the parameter is set on the OrderProfile instance directly via the property indicated by its "Name". If the "FieldLocation" is equal to "UserParameters", then the parameter is set as part of the UserParameters property of the OrderProfile instance.
For example, the following are the parameters of the TT Stop algo.
Name | Type | Required | Updatable | FieldLocation | Algo-Specific Enum |
---|---|---|---|---|---|
OrderInstrumentID | Instrument | true | true | OrderProfile | |
OrderQty | Quantity | true | false | OrderProfile | |
OrderSide | Enum | true | false | OrderProfile | tt_net_sdk.OrderSide |
OrderAccount | String | true | false | OrderProfile | |
TriggerPrice | Price | false | true | OrderProfile | |
OrderType | Enum | true | false | OrderProfile | tt_net_sdk.OrderType |
LimitPrice | Price | true | true | OrderProfile | |
ChildTIF | Int_t | true | false | UserParameters | |
ParentTIF | Int_t | true | false | UserParameters | tt_net_sdk.tt_stop.ParentTIF |
TriggerPriceType | Int_t | true | false | UserParameters | tt_net_sdk.tt_stop.TriggerPriceType |
IsTrlTrg | Boolean_t | false | false | UserParameters | |
TriggerTicksAway | Int_t | false | true | UserParameters | |
TriggerQtyType | Int_t | false | false | UserParameters | tt_net_sdk.tt_stop.TriggerQtyType |
TriggerQtyCompare | Int_t | false | false | UserParameters | tt_net_sdk.tt_stop.TriggerQtyCompare |
TriggerQty | Qty_t | false | true | UserParameters | |
SecondConditionIsOn | Boolean_t | false | false | UserParameters | |
SecondTriggerPriceType | Int_t | true | false | UserParameters | tt_net_sdk.tt_stop.SecondTriggerPriceType |
SecondTriggerTicksAway | Int_t | false | true | UserParameters | |
SecondTriggerQtyType | Int_t | false | false | UserParameters | tt_net_sdk.tt_stop.SecondTriggerQtyType |
SecondTriggerQtyCompare | Int_t | false | false | UserParameters | tt_net_sdk.tt_stop.SecondTriggerQtyCompare |
SecondTriggerQty | Qty_t | false | true | UserParameters | |
TriggerLTPReset | Boolean_t | false | false | UserParameters | |
Payup | Int_t | false | true | UserParameters | |
LimitPriceType | Int_t | false | false | UserParameters | tt_net_sdk.tt_stop.LimitPriceType |
WithATickType | Int_t | false | false | UserParameters | tt_net_sdk.tt_stop.WithATickType |
WithATick | Qty_t | false | true | UserParameters | |
STime | UTCTimestamp_t | false | true | UserParameters | |
ETime | UTCTimestamp_t | false | true | UserParameters | |
ETimeAct | Int_t | false | false | UserParameters | tt_net_sdk.tt_stop.ETimeAct |
NoImplies | Boolean_t | false | false | UserParameters | |
AutoResubExpiredGTD | Boolean_t | false | false | UserParameters | |
WaitingOption | Int_t | true | false | UserParameters | tt_net_sdk.tt_stop.WaitingOption |
Set the User Disconnect Action
When your application launches an ADL algo, TT monitors the connection from your application to the TT ecosystem. If TT detects that your application has disconnected, you can specify the action to be taken on your algo. This can be done by specifying a single action for all algos when you initialize the API as follows.
string appSecretKey = "Your App Key";
tt_net_sdk.ServiceEnvironment environment = tt_net_sdk.ServiceEnvironment.UatCert;
tt_net_sdk.TTAPIOptions apiConfig = new tt_net_sdk.TTAPIOptions(
environment,
appSecretKey,
5000);
apiConfig.UserDisconnectAction = UserDisconnectAction.Cancel;
You can also specify this behavior on a per algo basis by setting the UserDisconnectAction property of the OrderProfile instance.
// Assume that the name of your OrderProfile object is ‘op’
op.UserDisconnectAction = UserDisconnectAction.Pause;
Set the co-location facility
TT has a pool of Algo Servers in each major data center. You must specify in which data center that you want your algo to execute as follows.
// Assume that the name of your OrderProfile object is ‘op’
op.CoLocation = MarketId.CME;
Launch the algo
Once your OrderProfile is ready, you can launch an algo by calling the SendOrder() method of the AlgoTradeSubscription instance. The following code snippet demonstrates the launching of the TT Stop algo.
private InstrumentLookup m_instrLookupRequest = null;
private Instrument m_inst = null;
private void m_ats_OrderBookDownload(object sender, OrderBookDownloadEventArgs e)
{
m_instrLookupRequest = new InstrumentLookup(
tt_net_sdk.Dispatcher.Current,
MarketId.CME,
ProductType.Future,
"ES",
"ES Dec19");
ProductDataEvent ev = m_instrLookupRequest.Get();
if (ev == ProductDataEvent.Found)
{
// Instrument was found
m_inst = m_instrLookupRequest.Instrument;
OrderProfile op = m_alookup.Algo.GetOrderProfile(m_inst);
Dictionary<string, object> userparams = new Dictionary<string, object>
{
{"TriggerPriceType", tt_net_sdk.tt_stop.TriggerPriceType.Ltp },
{"ChildTIF" , tt_net_sdk.TimeInForce.Day },
{"ParentTIF" , tt_net_sdk.tt_stop.ParentTIF.Day },
};
op.UserParameters = userparams;
op.AccountName = "ATRcert";
op.Side = OrderSide.Buy;
op.OrderType = OrderType.Limit;
op.OrderQuantity = Quantity.FromDecimal(m_inst, 10);
op.TriggerPrice = Price.FromString(m_inst, "2887.00");
op.LimitPrice = Price.FromString(m_inst, "2887.50");
if (!m_ats.SendOrder(op))
{
Console.WriteLine("Launch algo Failed.");
}
else
{
Console.WriteLine("Launched new algo: " + " SOK=" + op.SiteOrderKey);
}
}
else
{
// Instrument was not found
Console.WriteLine("Cannot find instrument: {0}", ev.ToString());
return;
}
}
Pause and resume ADL algos
ADL algos can be paused and then resumed. To accomplish this through the API, you simply set the OrderAction to the appropriate value as follows.
OrderProfile op = new OrderProfile(e.Fields.Instrument);
op.Action = OrderAction.Pause;
OrderProfile op = new OrderProfile(e.Fields.Instrument);
op.Action = OrderAction.Resume;