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
Comentarios (4)
Iniciar sesión o Crear cuenta, Inicie sesión o regístrese para dejar un comentario
Hello,
Did you tried to start SampleIB, search futures contract (by underlying symbol) and press Level1 for selected securities? No any warning messages?
Hi
I have used SampleIB to search for futures and options and pressed Level1. The sampleIB application returned the correct bid and ask with no warnings.
Regards
Hi
I found the problem. In my SecurityChanged handler, I had code that stopped the code executing past a point. Effectively pausing the thread that does the update. Once I removed that, the updates came through
Regards
Could you please post full code cause currently I cannot see any tech issues with locking.