{"id":8054,"date":"2025-09-04T23:22:21","date_gmt":"2025-09-05T04:22:21","guid":{"rendered":"https:\/\/librarytestdev.wpenginepowered.com\/?post_type=doc&#038;p=8054"},"modified":"2025-09-04T23:23:54","modified_gmt":"2025-09-05T04:23:54","slug":"fetching-all-instruments-for-a-given-product","status":"publish","type":"doc","link":"https:\/\/library-test.tradingtechnologies.com\/apis\/tt-net-sdk\/working-with-instruments-tt-net-sdk\/fetching-all-instruments-for-a-given-product\/","title":{"rendered":"Fetching all instruments for a given product"},"content":{"rendered":"\n<p>To fetch all instruments for a single product, you:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Instantiate the InstrumentCatalog class.<\/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.InstrumenCatalog.html#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 these instruments are available.<\/li>\n\n\n\n<li>Register this event handler with the\u00a0<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumenCatalog.html\">InstrumentCatalog<\/a>\u00a0instance.<\/li>\n\n\n\n<li>Call the\u00a0<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumenCatalog.html#GetAsync\">GetAsync()<\/a>\u00a0method of the\u00a0<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumenCatalog.html\">InstrumentCatalog<\/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-instrumentcatalog-class\"><a href=\"\/tt-net-sdk\/articles\/instr-fetch-product-instrs.html#instantiating-the-instrumentcatalog-class\"><\/a>Instantiating the InstrumentCatalog class<\/h2>\n\n\n\n<p>The&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumenCatalog.html\">InstrumentCatalog<\/a>&nbsp;class provides several constructors that let you identify a product using specific criteria.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public InstrumentCatalog(Product product, Dispatcher dispatcher);\npublic InstrumentCatalog(MarketId marketId, ProductType productType, string productName, Dispatcher dispatcher);\n<\/code><\/pre>\n\n\n\n<p>The following code snippet shows how to instantiate an&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumenCatalog.html\">InstrumentCatalog<\/a>&nbsp;object for the CME ES Future product.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>InstrumentCatalog instr_cat = new InstrumentCatalog(MarketId.CME, ProductType.Future, \"ES\", \n    tt_net_sdk.Dispatcher.Current);\n<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Note<\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The product name for Autospreader instruments is \u201cASE\u201d and the product name for Aggregator instruments is \u201cAGGREGATOR\u201d.<\/li>\n\n\n\n<li>The product type for Autospreader and Aggregator instruments is \u201cSynthetic\u201d.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"synchronous-fetch\"><a href=\"\/tt-net-sdk\/articles\/instr-fetch-product-instrs.html#synchronous-fetch\"><\/a>Synchronous fetch<\/h2>\n\n\n\n<p>Once an&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumenCatalog.html\">InstrumentCatalog<\/a>&nbsp;object has been created, you can simply call the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumenCatalog.html#Get\">Get()<\/a>&nbsp;method to perform a synchronous lookup of the product&#8217;s instruments 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 = instr_cat.Get();\nif (e == ProductDataEvent.Found)\n{\n  \/\/ Instruments were found\n  foreach (KeyValuePair&lt;InstrumentKey, Instrument&gt; kvp in instr_cat.Instruments)\n  {\n    Console.WriteLine(\"Key = {0} : Value = {1}\", kvp.Key, kvp.Value);\n  }\n}\nelse\n{\n  \/\/ Instruments were not found\n  Console.WriteLine(\"Cannot find instrument: {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\/instr-fetch-product-instrs.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>instr_cat.OnData += new EventHandler&lt;InstrumentCatalogEventArgs&gt;(instr_cat_OnData);\ninstr_cat.GetAsync();\n<\/code><\/pre>\n\n\n\n<p>After the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumenCatalog.html#GetAsync\">GetAsync()<\/a>&nbsp;method of the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumenCatalog.html\">InstrumentCatalog<\/a>&nbsp;instance is called, TT .NET SDK performs a lookup for the instruments based on the inputs that it is given. Whether the instruments were 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 instr_cat_OnData(object sender, InstrumentCatalogEventArgs e)\n{\n  if (e.Event == ProductDataEvent.Found)\n  {\n    \/\/ Instruments were found\n    foreach (KeyValuePair&lt;InstrumentKey, Instrument&gt; kvp in e.InstrumentCatalog.Instruments)\n    {\n      Console.WriteLine(\"Key = {0} : Value = {1}\", kvp.Key, kvp.Value);\n    }\n  }\n  else\n  {\n    \/\/ Instruments were not found\n    Console.WriteLine(\"Cannot find instrument: {0}\", e.Message);\n  }\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"cleaning-up\"><a href=\"\/tt-net-sdk\/articles\/instr-fetch-product-instrs.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.InstrumenCatalog.html\">InstrumentCatalog<\/a>&nbsp;class as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>instr_cat.OnData -= instr_req_OnData;\ninstr_cat.Dispose();<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To fetch all instruments for a single product, you: Instantiating the InstrumentCatalog class The&nbsp;Instrum [&hellip;]<\/p>\n","protected":false},"author":2,"template":"wp-custom-template-single-doc-tt-net-sdk","meta":{"_acf_changed":true,"footnotes":""},"docs-category":[772],"class_list":["post-8054","doc","type-doc","status-publish","hentry","docs-category-working-with-instruments-tt-net-sdk"],"acf":[],"_links":{"self":[{"href":"https:\/\/library-test.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc\/8054","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\/8054\/revisions"}],"wp:attachment":[{"href":"https:\/\/library-test.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/media?parent=8054"}],"wp:term":[{"taxonomy":"docs-category","embeddable":true,"href":"https:\/\/library-test.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/docs-category?post=8054"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}