public void GetsTickData()
        {
            using (var ib = new InteractiveBrokersBrokerage(new QCAlgorithm(), new OrderProvider(), new SecurityProvider(), new AggregationManager(), new LocalDiskMapFileProvider()))
            {
                ib.Connect();
                var gotUsdData = false;
                var gotEurData = false;

                var cancelationToken = new CancellationTokenSource();

                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);
                cancelationToken.Cancel();
                cancelationToken.Dispose();

                Assert.IsTrue(gotUsdData);
                Assert.IsTrue(gotEurData);
            }
        }
        public void FutureSubscriptions()
        {
            using (var ib = new InteractiveBrokersBrokerage(new QCAlgorithm(), new OrderProvider(), new SecurityProvider(), new AggregationManager(), TestGlobals.MapFileProvider))
            {
                ib.Connect();
                var gotEsData  = false;
                var gotHsiData = false;

                var cancelationToken = new CancellationTokenSource();

                var es      = Symbols.CreateFuturesCanonicalSymbol("ES");
                var firstEs = ib.LookupSymbols(es, includeExpired: false).First();
                ProcessFeed(
                    ib.Subscribe(GetSubscriptionDataConfig <TradeBar>(firstEs, Resolution.Second), (s, e) => { gotEsData = true; }),
                    cancelationToken,
                    (tick) => Log(tick));

                // non USD quote currency, HDK
                var hsi      = Symbols.CreateFuturesCanonicalSymbol("HSI");
                var firstHsi = ib.LookupSymbols(hsi, includeExpired: false).First();
                ProcessFeed(
                    ib.Subscribe(GetSubscriptionDataConfig <TradeBar>(firstHsi, Resolution.Second), (s, e) => { gotHsiData = true; }),
                    cancelationToken,
                    (tick) => Log(tick));

                Thread.Sleep(2000);
                cancelationToken.Cancel();
                cancelationToken.Dispose();

                Assert.IsTrue(gotEsData);
                Assert.IsTrue(gotHsiData);
            }
        }
Example #3
0
        public void GetsTickData()
        {
            InteractiveBrokersGatewayRunner.StartFromConfiguration();

            var ib = new InteractiveBrokersBrokerage(new QCAlgorithm(), new OrderProvider(), new SecurityProvider());

            ib.Connect();

            ib.Subscribe(null, new List <Symbol> {
                Symbols.USDJPY, Symbols.EURGBP
            });

            Thread.Sleep(1000);

            var gotUsdData = false;
            var gotEurData = false;

            for (int 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();
        }
        public void GetsTickData()
        {
            InteractiveBrokersGatewayRunner.StartFromConfiguration();

            var ib = new InteractiveBrokersBrokerage(new OrderProvider());

            ib.Connect();

            ib.Subscribe(null, new Dictionary <SecurityType, List <string> >
            {
                { SecurityType.Forex, new List <string> {
                      "USDJPY", "EURGBP"
                  } }
            });

            Thread.Sleep(1000);

            for (int i = 0; i < 10; i++)
            {
                foreach (var tick in ib.GetNextTicks())
                {
                    Console.WriteLine("{0}: {1} - {2} @ {3}", tick.Time, tick.Symbol, tick.Price, ((Tick)tick).Quantity);
                }
            }

            InteractiveBrokersGatewayRunner.Stop();
        }
Example #5
0
        public void GetsTickDataAfterDisconnectionConnectionCycle()
        {
            using (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(2000);

                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(2000);

                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);
            }
        }