Example #1
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     if (_brokerage != null)
     {
         _brokerage.Disconnect();
         _brokerage.Dispose();
     }
 }
        public void GetsTickDataAfterDisconnectionConnectionCycle()
        {
            using (var ib = new InteractiveBrokersBrokerage(new QCAlgorithm(), new OrderProvider(), new SecurityProvider(), new AggregationManager(), new LocalDiskMapFileProvider()))
            {
                ib.Connect();
                var cancelationToken = new CancellationTokenSource();
                var gotUsdData       = false;
                var gotEurData       = false;

                ProcessFeed(
                    ib.Subscribe(GetSubscriptionDataConfig <TradeBar>(Symbols.AAPL, Resolution.Second), (s, e) => { gotUsdData = true; }),
                    cancelationToken,
                    (tick) => Log(tick));

                ProcessFeed(
                    ib.Subscribe(GetSubscriptionDataConfig <TradeBar>(Symbols.SPY, Resolution.Second), (s, e) => { gotEurData = true; }),
                    cancelationToken,
                    (tick) => Log(tick));

                Thread.Sleep(2000);

                Assert.IsTrue(gotUsdData);
                Assert.IsTrue(gotEurData);

                ib.Disconnect();
                gotUsdData = false;
                gotEurData = false;

                Thread.Sleep(2000);

                ib.Connect();
                Thread.Sleep(2000);

                cancelationToken.Cancel();
                cancelationToken.Dispose();

                Assert.IsTrue(gotUsdData);
                Assert.IsTrue(gotEurData);
            }
        }
Example #3
0
        public void GetsTickDataAfterDisconnectionConnectionCycle()
        {
            InteractiveBrokersGatewayRunner.StartFromConfiguration();
            var ib = new InteractiveBrokersBrokerage(new QCAlgorithm(), new OrderProvider(), new SecurityProvider());

            ib.Connect();
            ib.Subscribe(null, new List <Symbol> {
                Symbols.USDJPY, Symbols.EURGBP
            });
            ib.Disconnect();
            Thread.Sleep(1000);
            for (var i = 0; i < 20; i++)
            {
                foreach (var tick in ib.GetNextTicks()) // we need to make sure we consumer the already sent data, if any
                {
                    Console.WriteLine("{0}: {1} - {2} @ {3}", tick.Time, tick.Symbol, tick.Price, ((Tick)tick).Quantity);
                }
            }

            ib.Connect();
            Thread.Sleep(1000);

            var gotUsdData = false;
            var gotEurData = false;

            for (var i = 0; i < 20; i++)
            {
                foreach (var tick in ib.GetNextTicks())
                {
                    Console.WriteLine("{0}: {1} - {2} @ {3}", tick.Time, tick.Symbol, tick.Price, ((Tick)tick).Quantity);
                    gotUsdData |= tick.Symbol == Symbols.USDJPY;
                    gotEurData |= tick.Symbol == Symbols.EURGBP;
                }
            }
            Assert.IsTrue(gotUsdData);
            Assert.IsTrue(gotEurData);
            InteractiveBrokersGatewayRunner.Stop();
        }
Example #4
0
 public void Dispose()
 {
     _brokerage.Disconnect();
 }