{"id":8095,"date":"2025-09-04T23:21:37","date_gmt":"2025-09-05T04:21:37","guid":{"rendered":"https:\/\/librarytestdev.wpenginepowered.com\/?post_type=doc&#038;p=8095"},"modified":"2025-09-04T23:23:48","modified_gmt":"2025-09-05T04:23:48","slug":"fetching-a-single-algo","status":"publish","type":"doc","link":"https:\/\/library-test.tradingtechnologies.com\/apis\/tt-net-sdk\/working-with-algos\/algo-server\/fetching-a-single-algo\/","title":{"rendered":"Fetching a single algo"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"steps-for-fetching-a-full-algo-definition\">Steps for fetching a full algo definition<\/h2>\n\n\n\n<p>To fetch the full definition of a single algo, you:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Instantiate the\u00a0<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.AlgoLookup.html\">AlgoLookup<\/a>\u00a0class.<\/li>\n\n\n\n<li>Choose a fetch type:\n<ul class=\"wp-block-list\">\n<li>Synchronous\n<ol class=\"wp-block-list\">\n<li>Call the\u00a0<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.AlgoLookup.html#tt_net_sdk_AlgoLookup_Get\">Get()<\/a>\u00a0method.<\/li>\n<\/ol>\n<\/li>\n\n\n\n<li>Asynchronous\n<ol class=\"wp-block-list\">\n<li>Create an event handler method that will be called when notifications regarding this algo are available.<\/li>\n\n\n\n<li>Register this event handler with the\u00a0<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.AlgoLookup.html\">AlgoLookup<\/a>\u00a0instance.<\/li>\n\n\n\n<li>Call the\u00a0<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.AlgoLookup.html#tt_net_sdk_AlgoLookup_GetAsync\">GetAsync()<\/a>\u00a0method of the\u00a0<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentLookup.html\">InstrumentLookup<\/a>\u00a0instance.<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"instantiating-the-algolookup-class\"><a href=\"\/tt-net-sdk\/articles\/as-fetch-one.html#instantiating-the-algolookup-class\"><\/a>Instantiating the AlgoLookup class<\/h2>\n\n\n\n<p>The&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.AlgoLookup.html\">AlgoLookup<\/a>&nbsp;class provides the following constructor.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public AlgoLookup(tt_net_sdk.Dispatcher dispatcher, string algoName)\n<\/code><\/pre>\n\n\n\n<p>When instantiating the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.AlgoLookup.html\">AlgoLookup<\/a>&nbsp;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).<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>TT Bracket<\/li>\n\n\n\n<li>TT Iceberg<\/li>\n\n\n\n<li>TT If Touched<\/li>\n\n\n\n<li>TT OBV<\/li>\n\n\n\n<li>TT OCO<\/li>\n\n\n\n<li>TT Retry<\/li>\n\n\n\n<li>TT Stop<\/li>\n\n\n\n<li>TT Time Sliced<\/li>\n\n\n\n<li>TT Time Duration<\/li>\n\n\n\n<li>TT Timed<\/li>\n\n\n\n<li>TT Trailing Limit<\/li>\n\n\n\n<li>TT With A Tick<\/li>\n<\/ul>\n\n\n\n<p>So, for example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>AlgoLookup m_alookup = new AlgoLookup(tt_net_sdk.Dispatcher.Current, \u201cTT Stop\u201d);\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"synchronous-fetch\"><a href=\"\/tt-net-sdk\/articles\/as-fetch-one.html#synchronous-fetch\"><\/a>Synchronous fetch<\/h2>\n\n\n\n<p>Once an&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.AlgoLookup.html\">AlgoLookup<\/a>&nbsp;object has been created, you can simply call the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.AlgoLookup.html#tt_net_sdk_AlgoLookup_Get\">Get()<\/a>&nbsp;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.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ProductDataEvent e = m_alookup.Get();\nif (e == ProductDataEvent.Found)\n{\n    \/\/ Algo was found\n    Console.WriteLine(\"Algo Found: {0}\", m_alookup.Algo.Alias);\n}\nelse\n{\n    \/\/ Algo was not found\n    Console.WriteLine(\"Cannot find algo: {0}\", e.ToString());\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"asynchronous-fetch\"><a href=\"\/tt-net-sdk\/articles\/as-fetch-one.html#asynchronous-fetch\"><\/a>Asynchronous fetch<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>m_alookup.OnData += new EventHandler&lt;AlgoLookupEventArgs&gt;(m_alookup_OnData);\nm_alookup.GetAsync();\n<\/code><\/pre>\n\n\n\n<p>After the&nbsp;<a href=\"\/api\/tt_net_sdk.AlgoLookup.html#tt_net_sdk_AlgoLookup_GetAsync\">GetAsync()<\/a>&nbsp;method of the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentLookup.html\">InstrumentLookup<\/a>&nbsp;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.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>private void m_alookup_OnData(object sender, AlgoLookupEventArgs e)\n{\n\tif (e.Event == ProductDataEvent.Found)\n\t{\n\t\t\/\/ Algo was found\n\t\tConsole.WriteLine(\"Algo Found: {0}\", e.AlgoLookup.Algo.Alias);\n\t}\n\telse\n\t{\n\t\t\/\/ Algo was not found\n\t\tConsole.WriteLine(\"Cannot find algo: {0}\", e.Message);\n\t}\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"cleaning-up\"><a href=\"\/tt-net-sdk\/articles\/as-fetch-one.html#cleaning-up\"><\/a>Cleaning up<\/h2>\n\n\n\n<p>When you shut down your application, you should detach all event handlers and call the&nbsp;<code>Dispose()<\/code>&nbsp;method for each instance of the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.AlgoLookup.html\">AlgoLookup<\/a>&nbsp;class as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>m_alookup.OnData -= m_alookup_OnData;\nm_alookup.Dispose();\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"about-the-algo-class\"><a href=\"\/tt-net-sdk\/articles\/as-fetch-one.html#about-the-algo-class\"><\/a>About the Algo class<\/h2>\n\n\n\n<p>The&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Algo.html\">Algo<\/a>&nbsp;class provides the full definition of a given algo. Its members include:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/  Algo\u2019s alias\npublic string        Alias;\n\/\/ Category -- ADL, Vendor, SSE, TT, etc.\npublic AlgoCategory  Category;\n\/\/ Whether this algo is owned by you or shared with you\npublic bool          IsMyAlgo;\n\/\/ Whether this algo is deployed or not\npublic bool          IsDeployed;\n\n\/\/ Algo\u2019s parameters\npublic IReadOnlyCollection&lt;AlgoParameters&gt; AlgoParameters;\n<\/code><\/pre>\n\n\n\n<p>The&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.AlgoParameters.html\">AlgoParameters<\/a>&nbsp;class provides all of the details about a parameter. Its members include:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/  Parameter\u2019s name\npublic string Name;\n\/\/  Indicates whether the parameter is required or optional\npublic string IsRequired;\n\/\/  Indicates whether the parameter can be updated after the algo is launched\npublic string IsUpdateable\n\/\/  Parameter\u2019s data type\npublic string Type;\n\/\/  Where to set this parameter\npublic string FieldLocation;\n<\/code><\/pre>\n\n\n\n<p>If the&nbsp;<code>FieldLocation<\/code>&nbsp;is equal to \u201cOrderProfile\u201d, then the parameter is set on the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.OrderProfile.html\">OrderProfile<\/a>&nbsp;instance directly via the property indicated by its&nbsp;<code>Name<\/code>. If the&nbsp;<code>FieldLocation<\/code>&nbsp;is equal to \u201cUserParameters\u201d, then the parameter is set as part of the&nbsp;<code>UserParameters<\/code>&nbsp;property of the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.OrderProfile.html\">OrderProfile<\/a>&nbsp;instance.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Steps for fetching a full algo definition To fetch the full definition of a single algo, you: Instantiating th [&hellip;]<\/p>\n","protected":false},"author":2,"template":"wp-custom-template-single-doc-tt-net-sdk","meta":{"_acf_changed":true,"footnotes":""},"docs-category":[780],"class_list":["post-8095","doc","type-doc","status-publish","hentry","docs-category-algo-server"],"acf":[],"_links":{"self":[{"href":"https:\/\/library-test.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc\/8095","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/library-test.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc"}],"about":[{"href":"https:\/\/library-test.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/types\/doc"}],"author":[{"embeddable":true,"href":"https:\/\/library-test.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/users\/2"}],"version-history":[{"count":0,"href":"https:\/\/library-test.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc\/8095\/revisions"}],"wp:attachment":[{"href":"https:\/\/library-test.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/media?parent=8095"}],"wp:term":[{"taxonomy":"docs-category","embeddable":true,"href":"https:\/\/library-test.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/docs-category?post=8095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}