{"id":8055,"date":"2025-09-04T23:22:21","date_gmt":"2025-09-05T04:22:21","guid":{"rendered":"https:\/\/librarytestdev.wpenginepowered.com\/?post_type=doc&#038;p=8055"},"modified":"2025-09-04T23:23:54","modified_gmt":"2025-09-05T04:23:54","slug":"searching-instruments-by-query-text","status":"publish","type":"doc","link":"https:\/\/library-staging.tradingtechnologies.com\/apis\/tt-net-sdk\/working-with-instruments-tt-net-sdk\/searching-instruments-by-query-text\/","title":{"rendered":"Searching Instruments by Query text"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"steps-for-searching-instruments-by-query\">Steps for searching instruments by Query<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To search for an Instrument, you must perform the following tasks:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Instantiate the\u00a0<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentSearcher.html\">InstrumentSearcher<\/a>\u00a0class.<\/li>\n\n\n\n<li>Choose whether to use a synchronous or asynchronous a search 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.ProductCatalog.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 search are available.<\/li>\n\n\n\n<li>Register this event handler with the\u00a0<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentSearcher.html\">InstrumentSearcher<\/a>\u00a0instance.<\/li>\n\n\n\n<li>Call the\u00a0<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentSearcher.html#GetAsync\">GetAsync()<\/a>\u00a0method of the\u00a0<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentSearcher.html\">InstrumentSearcher<\/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-instrumentsearcher-class\"><a href=\"\/tt-net-sdk\/articles\/instr-search.html#instantiating-the-instrumentsearcher-class\"><\/a>Instantiating the InstrumentSearcher class<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentSearcher.html\">InstrumentSearcher<\/a>&nbsp;class provides several ways via constructors that let you search instruments by text query using different sets of filters. These are listed below along with code snippets showing their use.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To use a query to search for instruments from a given list of markets. Create an instrument subscription given an\u00a0<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentSearcher.html\">InstrumentSearcher<\/a>\u00a0instance as below.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;MarketId&gt; marketIds = new List&lt;MarketId&gt;();\nmarketIds.Add(MarketId.CME);\nmarketIds.Add(MarketId.ICE);\n\nInstrumentSearcher instrumentSearcher = new\n    InstrumentSearcher(tt_net_sdk.Dispatcher.Current,\n    \"CL Dec23\", marketIds, ProductType.NotSet, 0);\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To search for instruments by using the given product type<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>InstrumentSearcher instrumentSearcher = new\n    InstrumentSearcher(tt_net_sdk.Dispatcher.Current,\n    \"CL Dec23\", null, ProductType.Future, 0);\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To search for instruments from the list of markets and by using the given product type.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;MarketId&gt; marketIds = new List&lt;MarketId&gt;();\nmarketIds.Add(MarketId.CME);\nmarketIds.Add(MarketId.ICE);\n\nInstrumentSearcher instrumentSearcher = new\n    InstrumentSearcher(tt_net_sdk.Dispatcher.Current,\n    \"CL Dec23\", marketIds, ProductType.Future, 0);\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"synchronous-search\"><a href=\"\/tt-net-sdk\/articles\/instr-search.html#synchronous-search\"><\/a>Synchronous search<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Once an&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentSearcher.html\">InstrumentSearcher<\/a>&nbsp;object has been created, you can simply call the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentSearcher.html#Get\">Get()<\/a>&nbsp;method to perform a synchronous search of the instruments as shown below.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong>: Although this process normally completes fairly quickly, your execution thread will remain blocked until this action completes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ProductDataEvent e = instrumentSearcher.Get();\nif (e == ProductDataEvent.Found)\n{\n  \/\/ Instrument was found\n  LinkedList&lt;InstrumentSearchResult&gt; instruments  =\n                                    instrumentSearcher.Results;\n  Console.WriteLine(\"Found: {0} instruments\",\n                                    instruments.Count);\n}\nelse\n{\n\n\n  \/\/ Instrument was not found\n  Console.WriteLine(\"Cannot find instrument: {0}\", e.ToString());\n}\n\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"asynchronous-fetch\"><a href=\"\/tt-net-sdk\/articles\/instr-search.html#asynchronous-fetch\"><\/a>Asynchronous fetch<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can register a callback function to be called once the searching has been completed as shown below.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong>: This approach allows the execution thread to remain unblocked.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>instrumentSearcher.OnData +=\n    new\nEventHandler&lt;InstrumentSearcherEventArgs&gt;(instrumentSearcher_OnData);\ninstrumentSearcher.GetAsync();\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentSearcher.html#GetAsync\">GetAsync()<\/a>&nbsp;method of the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentSearcher.html\">InstrumentSearcher<\/a>&nbsp;instance is called, TT .NET SDK performs a search for the instrument based on the given inputs. 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 instrumentSearcher_OnData(object sender, InstrumentSearcherEventArgs e)\n{\n  if (e.Event == ProductDataEvent.Found)\n  {\n    \/\/ Instrument was found\n    InstrumentSearcher instrumentSearcher = e.InstrumentSearcher;\n    LinkedList&lt;InstrumentSearchResult&gt; instruments  =\ninstrumentSearcher.Results;\n    Console.WriteLine(\"Found: {0} instruments\",\ninstruments.Count);\n\n  }\n  else\n  {\n    \/\/ Instrument was not found\n    Console.WriteLine(\"No results were found for the query: {0}\", e.Message);\n  }\n}\n\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"cleaning-up\"><a href=\"\/tt-net-sdk\/articles\/instr-search.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.InstrumentSearcher.html\">InstrumentSearcher<\/a>&nbsp;class as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>instrumentSearcher.OnData -= instrumentSearcher_OnData;\ninstrumentSearcher.Dispose();<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<h2 class=\"wp-block-heading\" id=\"steps-for-searching-instruments-by-query\">Steps for searching instruments by Query<\/h2>\n<p class=\"wp-block-paragraph\">To search for an Instrument, you must perform the following tasks:<\/p>\n<h2 class=\"wp-block-heading\" id=\"instantiating-the-instrumentsearcher-class\"><a href=\"\/tt-net-sdk\/articles\/instr-search.html#instantiating-the-instrumentsearcher-class\"><\/a>Instantiating the InstrumentSearcher class<\/h2>\n<p class=\"wp-block-paragraph\">The&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentSearcher.html\">InstrumentSearcher<\/a>&nbsp;class provides several ways via constructors that let you search instruments by text query using different sets of filters. These are listed below along with code snippets showing their use.<\/p>\n<h2 class=\"wp-block-heading\" id=\"synchronous-search\"><a href=\"\/tt-net-sdk\/articles\/instr-search.html#synchronous-search\"><\/a>Synchronous search<\/h2>\n<p class=\"wp-block-paragraph\">Once an&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentSearcher.html\">InstrumentSearcher<\/a>&nbsp;object has been created, you can simply call the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentSearcher.html#Get\">Get()<\/a>&nbsp;method to perform a synchronous search of the instruments as shown below.<\/p>\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong>: Although this process normally completes fairly quickly, your execution thread will remain blocked until this action completes.<\/p>\n<h2 class=\"wp-block-heading\" id=\"asynchronous-fetch\"><a href=\"\/tt-net-sdk\/articles\/instr-search.html#asynchronous-fetch\"><\/a>Asynchronous fetch<\/h2>\n<p class=\"wp-block-paragraph\">You can register a callback function to be called once the searching has been completed as shown below.<\/p>\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong>: This approach allows the execution thread to remain unblocked.<\/p>\n<p class=\"wp-block-paragraph\">After the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentSearcher.html#GetAsync\">GetAsync()<\/a>&nbsp;method of the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentSearcher.html\">InstrumentSearcher<\/a>&nbsp;instance is called, TT .NET SDK performs a search for the instrument based on the given inputs. 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-search.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.InstrumentSearcher.html\">InstrumentSearcher<\/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-8055","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\/8055","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\/8055\/revisions"}],"wp:attachment":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/media?parent=8055"}],"wp:term":[{"taxonomy":"docs-category","embeddable":true,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/docs-category?post=8055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}