﻿<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/css' href='https://stocksharp.com/css/style.css'?>
<?xml-stylesheet type='text/css' href='https://stocksharp.com/css/bbeditor.css'?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="html">lookupsecurities. StockSharp</title>
  <id>https://stocksharp.com/handlers/atom.ashx?category=tag&amp;id=lookupsecurities&amp;type=forum</id>
  <rights type="text">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  <updated>2026-06-10T10:33:02Z</updated>
  <logo>https://stocksharp.com/images/logo.png</logo>
  <link href="https://stocksharp.com/handlers/atom.ashx?category=tag&amp;id=lookupsecurities&amp;type=forum" rel="self" type="application/rss+xml" />
  <entry>
    <id>https://stocksharp.com/topic/8770/</id>
    <title type="text">Problems with lookup of security</title>
    <published>2017-10-30T22:07:51Z</published>
    <updated>2017-10-31T22:39:52Z</updated>
    <author>
      <name>Johan Kirsten</name>
      <uri>https://stocksharp.com/users/99799/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <category term="LookupSecurities" />
    <category term="SecurityLookupMessage" />
    <content type="html">&lt;p&gt;I have a windows service that hosts a web api interface. The service connects to an interactive broker TWS. A call to the web api must lookup the security and return the Id. The code to do this is:
var criteria = new SecurityLookupMessage()
{
Class = &amp;quot;&amp;quot;,
ExpiryDate = DateTimeOffset.Parse(expiryDate),
OptionType = optionType == null ? default(OptionTypes?) : (OptionTypes)Enum.Parse(typeof(OptionTypes), optionType),
Strike = strike,
UnderlyingSecurityCode = underlyingSecurityCode,
SecurityType = securityType == null ? default(SecurityTypes?) : (SecurityTypes)Enum.Parse(typeof(SecurityTypes), securityType),
};&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;                    var security = _connector.Securities.FirstOrDefault(s =&amp;gt;
                        (s.UnderlyingSecurityId.StartsWith(criteria.UnderlyingSecurityCode)) &amp;amp;&amp;amp;
                        (s.Board?.Code == boardCode) &amp;amp;&amp;amp;
                        (s.Class == @class) &amp;amp;&amp;amp;
                        (s.Type == criteria.SecurityType) &amp;amp;&amp;amp;
                        (s.ExpiryDate == criteria.ExpiryDate) &amp;amp;&amp;amp;
                        (s.OptionType == criteria.OptionType) &amp;amp;&amp;amp;
                        (s.Strike == criteria.Strike));

                    if (security == null)
                    {
                        var onNewSecurity = new Action&amp;lt;Security&amp;gt;(s =&amp;gt;
                        {
                            if ((!s.UnderlyingSecurityId.StartsWith(criteria.UnderlyingSecurityCode)) ||
                                (s.Type != criteria.SecurityType) ||
                                (s.Board?.Code != boardCode) ||
                                (s.Class != @class) || 
                                (s.ExpiryDate != criteria.ExpiryDate) ||
                                (s.OptionType != criteria.OptionType) ||
                                (s.Strike != criteria.Strike) )
                                return;

                            waitHandle.Set();
                        });

                        _connector.NewSecurity += onNewSecurity;

                        _connector.LookupSecurities(criteria);

                        waitHandle.WaitOne(30000);

                        _connector.NewSecurity -= onNewSecurity;

                        security = _connector.Securities.FirstOrDefault(s =&amp;gt;
                            (s.UnderlyingSecurityId.StartsWith(criteria.UnderlyingSecurityCode)) &amp;amp;&amp;amp;
                            (s.Board?.Code == boardCode) &amp;amp;&amp;amp;
                            (s.Class == @class) &amp;amp;&amp;amp;
                            (s.Type == criteria.SecurityType) &amp;amp;&amp;amp;
                            (s.ExpiryDate == criteria.ExpiryDate) &amp;amp;&amp;amp;
                            (s.OptionType == criteria.OptionType) &amp;amp;&amp;amp;
                            (s.Strike == criteria.Strike));
                    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If I search for &amp;quot;SPZ7@GLOBEX&amp;quot; and then &amp;quot;SPXW  171215C02580000@SMART&amp;quot; it works fine. But if I first search for &amp;quot;SPXW  171215C02580000@SMART&amp;quot;, then it cannot find &amp;quot;SPZ7@GLOBEX&amp;quot;. It is like the option prohibits the searching of the future. Also, sometimes if I search for the option first, then it only finds  &amp;quot;SPXW  171215C02580000@ALL&amp;quot; and  &amp;quot;SPXW  171215C02580000@CBOE&amp;quot;, but then if I search again no search returns &amp;quot;SPXW  171215C02580000@SMART&amp;quot;. It is like the incomplete loaded results prohibit the later loading of extra results.&lt;/p&gt;
</content>
  </entry>
</feed>