{"id":8053,"date":"2025-09-04T23:22:22","date_gmt":"2025-09-05T04:22:22","guid":{"rendered":"https:\/\/librarytestdev.wpenginepowered.com\/?post_type=doc&#038;p=8053"},"modified":"2025-09-04T23:23:54","modified_gmt":"2025-09-05T04:23:54","slug":"fetching-a-single-instrument-2","status":"publish","type":"doc","link":"https:\/\/library-staging.tradingtechnologies.com\/apis\/tt-net-sdk\/working-with-instruments-tt-net-sdk\/fetching-a-single-instrument-2\/","title":{"rendered":"Fetching a single instrument"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"steps-for-fetching-a-single-instrument\">Steps for fetching a single instrument<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To fetch a single&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Instrument.html\">Instrument<\/a>, 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.InstrumentLookup.html\">InstrumentLookup<\/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.InstrumentLookup.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 this instrument are available.<\/li>\n\n\n\n<li>Register this event handler with the\u00a0<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentLookup.html\">InstrumentLookup<\/a>\u00a0instance.<\/li>\n\n\n\n<li>Call the\u00a0<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentLookup.html#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-instrumentlookup-class\"><a href=\"\/tt-net-sdk\/articles\/instr-fetch-single-instr.html#instantiating-the-instrumentlookup-class\"><\/a>Instantiating the InstrumentLookup class<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentLookup.html\">InstrumentLookup<\/a>&nbsp;class provides several overloaded constructors that let you identify instruments using different sets of criteria. These are listed below along with code snippets showing their use.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Fetch by instrument keyCreates an instrument subscription given an\u00a0<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentKey.html\">InstrumentKey<\/a>\u00a0instance.<code>InstrumentKey ik = new InstrumentKey( MarketId.CME, ProductType.Future, \"CL\", \u201cCL Dec19\u201d); InstrumentLookup m_instrLookupRequest = new InstrumentLookup( tt_net_sdk.Dispatcher.Current, ik);<\/code><\/li>\n\n\n\n<li>Fetch by Market ID, product key, product name and instrument aliasCreates an instrument subscription given a MarketId, ProductType, product name and instrument alias (ex. &#8220;CL Dec20&#8221;).<code>InstrumentLookup m_instrLookupRequest = new InstrumentLookup( tt_net_sdk.Dispatcher.Current, MarketId.CME, ProductType.Future, \"CL\", \"CL Dec19\"); <\/code>Note\n<ul class=\"wp-block-list\">\n<li>The instrument alias parameter must match the string displayed in TT and TT Desktop, where it is called the &#8220;contract alias&#8221;.<\/li>\n\n\n\n<li>The instrument alias parameter for Autospreader and Aggregator instruments must match the name with which it was created.<\/li>\n\n\n\n<li>The product type for Autospreader and Aggregator instruments is \u201cSynthetic\u201d.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"synchronous-fetch\"><a href=\"\/tt-net-sdk\/articles\/instr-fetch-single-instr.html#synchronous-fetch\"><\/a>Synchronous fetch<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Once an&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentLookup.html\">InstrumentLookup<\/a>&nbsp;object has been created, you can simply call the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentLookup.html#Get\">Get()<\/a>&nbsp;method to perform a synchronous lookup of the instrument 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_instrLookupRequest.Get();\nif (e == ProductDataEvent.Found)\n{\n  \/\/ Instrument was found\n  Instrument instrument = m_instrLookupRequest.Instrument;\n  Console.WriteLine(\"Found: {0}\", instrument);\n}\nelse\n{\n  \/\/ Instrument was 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-single-instr.html#asynchronous-fetch\"><\/a>Asynchronous fetch<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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_instrLookupRequest.OnData += \n    new EventHandler&lt;InstrumentLookupEventArgs&gt;(m_instrLookupRequest_OnData);\nm_instrLookupRequest.GetAsync();\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentLookup.html#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 instrument based on the inputs that it are given. Whether the instrument 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>void m_instrLookupRequest_OnData(object sender, InstrumentLookupEventArgs e)\n{\n  if (e.Event == ProductDataEvent.Found)\n  {\n    \/\/ Instrument was found\n    Instrument instrument = e.Instrument;\n    Console.WriteLine(\"Found: {0}\", instrument);\n  }\n  else \n  {\n    \/\/ Instrument was 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-single-instr.html#cleaning-up\"><\/a>Cleaning up<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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.InstrumentLookup.html\">InstrumentLookup<\/a>&nbsp;class as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>m_instrLookupRequest.OnData -= m_instrLookupRequest_OnData;\nm_instrLookupRequest.Dispose();<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<h2 class=\"wp-block-heading\" id=\"steps-for-fetching-a-single-instrument\">Steps for fetching a single instrument<\/h2>\n<p class=\"wp-block-paragraph\">To fetch a single&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Instrument.html\">Instrument<\/a>, you:<\/p>\n<h2 class=\"wp-block-heading\" id=\"instantiating-the-instrumentlookup-class\"><a href=\"\/tt-net-sdk\/articles\/instr-fetch-single-instr.html#instantiating-the-instrumentlookup-class\"><\/a>Instantiating the InstrumentLookup class<\/h2>\n<p class=\"wp-block-paragraph\">The&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentLookup.html\">InstrumentLookup<\/a>&nbsp;class provides several overloaded constructors that let you identify instruments using different sets of criteria. These are listed below along with code snippets showing their use.<\/p>\n<h2 class=\"wp-block-heading\" id=\"synchronous-fetch\"><a href=\"\/tt-net-sdk\/articles\/instr-fetch-single-instr.html#synchronous-fetch\"><\/a>Synchronous fetch<\/h2>\n<p class=\"wp-block-paragraph\">Once an&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentLookup.html\">InstrumentLookup<\/a>&nbsp;object has been created, you can simply call the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentLookup.html#Get\">Get()<\/a>&nbsp;method to perform a synchronous lookup of the instrument as shown below. Note that although this is normally fairly quick, your execution thread will be blocked until this action is complete.<\/p>\n<h2 class=\"wp-block-heading\" id=\"asynchronous-fetch\"><a href=\"\/tt-net-sdk\/articles\/instr-fetch-single-instr.html#asynchronous-fetch\"><\/a>Asynchronous fetch<\/h2>\n<p class=\"wp-block-paragraph\">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<p class=\"wp-block-paragraph\">After the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentLookup.html#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 instrument based on the inputs that it are given. Whether the instrument is found or not, the specified event handler method is called. The following code snippet illustrates the structure of this event handler.<\/p>\n<h2 class=\"wp-block-heading\" id=\"cleaning-up\"><a href=\"\/tt-net-sdk\/articles\/instr-fetch-single-instr.html#cleaning-up\"><\/a>Cleaning up<\/h2>\n<p class=\"wp-block-paragraph\">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.InstrumentLookup.html\">InstrumentLookup<\/a>&nbsp;class as follows:<\/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-8053","doc","type-doc","status-publish","hentry","docs-category-working-with-instruments-tt-net-sdk"],"acf":[],"_links":{"self":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc\/8053","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc"}],"about":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/types\/doc"}],"author":[{"embeddable":true,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/users\/2"}],"version-history":[{"count":0,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc\/8053\/revisions"}],"wp:attachment":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/media?parent=8053"}],"wp:term":[{"taxonomy":"docs-category","embeddable":true,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/docs-category?post=8053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}