Problems registering security for level 1 price updates


Problems registering security for level 1 price updates
Atom
10/30/2017


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


Support

Avatar
Date: 10/31/2017
Reply


Hello,

Did you tried to start SampleIB, search futures contract (by underlying symbol) and press Level1 for selected securities? No any warning messages?
Thanks:

Johan Kirsten

Avatar
Date: 10/31/2017
Reply


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
Thanks:

Johan Kirsten

Avatar
Date: 11/1/2017
Reply


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
Thanks: Mikhail Sukhov Support

Support

Avatar
Date: 11/2/2017
Reply


Could you please post full code cause currently I cannot see any tech issues with locking.
Thanks:


Attach files by dragging & dropping, , or pasting from the clipboard.

loading
clippy