Problems registering security for level 1 price updates
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 register the security to receive level 1 price updates. The code to do this is:
if (_connector.RegisteredSecurities.Count(s => s.Id == securityId) == 0)
{
var onSecurityChanged = new Action<Security>(s =>
{
if (s.Id != securityId)
return;
if (s.BestBid != null && s.BestAsk != null)
waitHandle.Set();
});
_connector.SecurityChanged += onSecurityChanged;
_connector.RegisterSecurity(security);
waitHandle.WaitOne(30000);
_connector.SecurityChanged -= onSecurityChanged;
}
if ((security.BestBid == null) || (security.BestAsk == null))
{
throw new InvalidOperationException("Unable to obtain quotes");
}
The problem is the security does not get registered. Even on a second or third pass. The RegisteredSecurities collection stays empty.
I have tested it with securities with the following ids: "SPZ7@GLOBEX", "SPXW 171215C02580000@SMART"
Any help would be greatly appreciated
Regards
Johan Kirsten