Fetching a single algo
Steps for fetching a full algo definition
To fetch the full definition of a single algo, you:
- Instantiate the AlgoLookup class.
- Choose a fetch type:
Synchronous
- Call the Get() method.
Asynchronous
- Create an event handler method that will be called when notifications regarding this algo are available.
- Register this event handler with the AlgoLookup instance.
- Call the GetAsync() method of the InstrumentLookup instance.
Instantiating the AlgoLookup class
The AlgoLookup class provides the following constructor.
public AlgoLookup(tt_net_sdk.Dispatcher dispatcher, string algoName)
When instantiating the AlgoLookup class, you must pass the name of the algo. For ADL, it is the name that you gave the algo. For TT Order Types, the names are as follows (including capitalization and spaces).
- TT Bracket
- TT Iceberg
- TT If Touched
- TT OBV
- TT OCO
- TT Retry
- TT Stop
- TT Time Sliced
- TT Time Duration
- TT Timed
- TT Trailing Limit
- TT With A Tick
So, for example:
AlgoLookup m_alookup = new AlgoLookup(tt_net_sdk.Dispatcher.Current, “TT Stop”);
Synchronous fetch
Once an AlgoLookup object has been created, you can simply call the Get() method to perform a synchronous lookup of the algo definition as shown below. Note that although this is normally fairly quick, your execution thread will be blocked until this action is complete.
ProductDataEvent e = m_alookup.Get();
if (e == ProductDataEvent.Found)
{
// Algo was found
Console.WriteLine("Algo Found: {0}", m_alookup.Algo.Alias);
}
else
{
// Algo was not found
Console.WriteLine("Cannot find algo: {0}", e.ToString());
}
Asynchronous fetch
If you prefer not to be blocked, you can register a callback function to be called once the fetching has been completed as shown below.
m_alookup.OnData += new EventHandler<AlgoLookupEventArgs>(m_alookup_OnData);
m_alookup.GetAsync();
After the GetAsync() method of the InstrumentLookup instance is called, TT .NET SDK performs a lookup for the algo definition based on the inputs that it was given. Whether the algo is found or not, the specified event handler method is called. The following code snippet illustrates the structure of this event handler.
private void m_alookup_OnData(object sender, AlgoLookupEventArgs e)
{
if (e.Event == ProductDataEvent.Found)
{
// Algo was found
Console.WriteLine("Algo Found: {0}", e.AlgoLookup.Algo.Alias);
}
else
{
// Algo was not found
Console.WriteLine("Cannot find algo: {0}", e.Message);
}
}
Cleaning up
When you shut down your application, you should detach all event handlers and call the Dispose()
method for each instance of the AlgoLookup class as follows:
m_alookup.OnData -= m_alookup_OnData;
m_alookup.Dispose();
About the Algo class
The Algo class provides the full definition of a given algo. Its members include:
// Algo’s alias
public string Alias;
// Category -- ADL, Vendor, SSE, TT, etc.
public AlgoCategory Category;
// Whether this algo is owned by you or shared with you
public bool IsMyAlgo;
// Whether this algo is deployed or not
public bool IsDeployed;
// Algo’s parameters
public IReadOnlyCollection<AlgoParameters> AlgoParameters;
The AlgoParameters class provides all of the details about a parameter. Its members include:
// Parameter’s name
public string Name;
// Indicates whether the parameter is required or optional
public string IsRequired;
// Indicates whether the parameter can be updated after the algo is launched
public string IsUpdateable
// Parameter’s data type
public string Type;
// Where to set this parameter
public string FieldLocation;
If the FieldLocation
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.