Show / Hide Table of Contents

Fetching a list of all algos

Launching an algo requires that you first fetch its full definition. You can fetch a partial definition of all of your algos as well as any that have been shared with you using the AlgoCatalog class. You can then fetch an individual algo’s full definition using the AlgoLookup class.

Steps for fetching a list of algo definitions

To fetch a partial definition of all of your algos as well as any that have been shared with you, you:

  1. Instantiate the AlgoCatalog class.
  2. Choose a fetch type:
    • Synchronous
      1. Call the Get() method.
    • Asynchronous
      1. Create an event handler method that will be called when notifications regarding this algo are available.
      2. Register this event handler with the AlgoCatalog instance.
      3. Call the GetAsync() method of the AlgoCatalog instance.

Instantiating the AlgoCatalog class

The AlgoCatalog class provides the following constructor.

public AlgoCatalog(Dispatcher dispatcher);

The following code snippet illustrates how to instantiate this class.

AlgoCatalog algo_cat = new AlgoCatalog(tt_net_sdk.Dispatcher.Current);

Synchronous fetch

Once an AlgoCatalog object has been created, you can simply call the Get() method to perform a synchronous lookup of the algos as shown below. Note that although this is normally fairly quick, your execution thread will be blocked until this action is complete.

ProductDataEvent e = algo_cat.Get();
if (e == ProductDataEvent.Found)
{
  // Algos were found
  foreach (AlgoInfo ai in algo_cat.Algos)
  {
      Console.WriteLine("Alias = {0}", ai.Alias);
  }
}
else
{
  // Algos were not found
  Console.WriteLine("Cannot find algos: {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.

algo_cat.OnData += new EventHandler<AlgoCatalogEventArgs>(algo_cat_OnData);
algo_cat.GetAsync();

After the GetAsync() method of the ProductCatalog instance is called, TT .NET SDK performs the lookup. Whether any algos were found or not, the specified event handler method is called. The following code snippet illustrates the structure of this event handler.

private void algo_cat_OnData(object sender, AlgoCatalogEventArgs e)
{
  if (e.Event == ProductDataEvent.Found)
  {
    // Algos were found
    foreach (AlgoInfo ai in algo_cat.Algos)
    {
      Console.WriteLine("Name = {0}", ai.Alias);
    }
  }
  else
  {
    // Algos were not found
    Console.WriteLine("Cannot find algos: {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 AlgoCatalog class as follows:

algo_cat.OnData -= algo_cat_OnData;
algo_cat.Dispose();

About the AlgoInfo struct

The AlgoInfo struct provides the basic data as it relates to 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;
In this article
Back to top