コード例 #1
0
        public void TestGetData1_RunIndependently()
        {
            while (IbLock)
            {
                Thread.Sleep(500);
            }
            IbLock = true;


            IDataProvider data = new IbkrDataProvider(Port);

            data.Connect();

            int timeout = 30;

            while (!data.Connected)
            {
                Thread.Sleep(100);
                if (--timeout <= 0)
                {
                    break;
                }
            }

            Assert.IsTrue(data.Connected);

            bool     requestComplete = false;
            DateTime requestDate     = new DateTime(2019, 11, 20);

            data.OnSecurityDataResponse += (s, e) =>
            {
                Assert.AreEqual(1, e.security.PriceBarData.Count);
                Assert.AreEqual(requestDate, e.security.PriceBarData[0].BarDateTime);
                requestComplete = true;
                data.Disconnect();
                IbLock = false;
            };


            Security reqSec = new Security("F");

            data.RequestPriceData(reqSec, requestDate, requestDate);

            timeout = 100;
            while (!requestComplete)
            {
                Thread.Sleep(100);
                Assert.IsTrue(--timeout > 0);
            }

            data.Disconnect();
            IbLock = false;
        }
コード例 #2
0
        /// <summary>
        /// Request the earliest price bar available for a security
        /// </summary>
        // [TestMethod] Long running
        public void TestGetData4_RunIndependently()
        {
            while (IbLock)
            {
                Thread.Sleep(500);
            }
            IbLock = true;

            IDataProvider data = new IbkrDataProvider(Port);

            data.Connect();

            int timeout = 30;

            while (!data.Connected)
            {
                Thread.Sleep(100);
                if (--timeout <= 0)
                {
                    break;
                }
            }

            Assert.IsTrue(data.Connected);

            bool requestComplete = false;

            DateTime requestDateEnd = new DateTime(2019, 11, 22);

            Security reqSec1 = new Security("AMZN");

            data.OnSecurityDataResponse += (s, e) =>
            {
                Console.WriteLine($"Received {e.security.PriceBarData.Count} bars. " +
                                  $"First DateTime: {e.security.GetPriceBars()[0].BarDateTime}, " +
                                  $"last DateTime {e.security.GetPriceBars()[e.security.PriceBarData.Count - 1].BarDateTime}");

                requestComplete = true;
            };

            data.RequestPriceData(reqSec1, requestDateEnd);

            timeout = 100;
            while (!requestComplete)
            {
                Thread.Sleep(100);
            }

            Assert.IsTrue(true);
            data.Disconnect();
            IbLock = false;
        }
コード例 #3
0
        public void TestConnect()
        {
            IDataProvider data = new IbkrDataProvider(Port);

            data.Connect();

            int timeout = 30;

            while (!data.Connected)
            {
                Thread.Sleep(100);
                if (--timeout <= 0)
                {
                    break;
                }
            }

            Assert.IsTrue(data.Connected);

            data.Disconnect();
        }
コード例 #4
0
        public void TestGetData3_RunIndependently()
        {
            while (IbLock)
            {
                Thread.Sleep(500);
            }
            IbLock = true;

            IDataProvider data = new IbkrDataProvider(Port);

            data.Connect();

            int timeout = 30;

            while (!data.Connected)
            {
                Thread.Sleep(100);
                if (--timeout <= 0)
                {
                    break;
                }
            }

            Assert.IsTrue(data.Connected);

            bool requestComplete = false;

            int receivedCount = 0;

            DateTime requestDateStart = new DateTime(2019, 11, 18);
            DateTime requestDateEnd   = new DateTime(2019, 11, 22);

            Security reqSec1 = new Security("AMZN");
            Security reqSec2 = new Security("AAPL");
            Security reqSec3 = new Security("MAR");
            Security reqSec4 = new Security("F");
            Security reqSec5 = new Security("DIS");

            data.OnSecurityDataResponse += (s, e) =>
            {
                switch (e.security.Ticker)
                {
                case "AMZN":
                    if (e.security.PriceBarData.Count == 5)
                    {
                        receivedCount += 1;
                    }

                    break;

                case "AAPL":
                    if (e.security.PriceBarData.Count == 5)
                    {
                        receivedCount += 1;
                    }

                    break;

                case "MAR":
                    if (e.security.PriceBarData.Count == 5)
                    {
                        receivedCount += 1;
                    }
                    break;

                case "F":
                    if (e.security.PriceBarData.Count == 5)
                    {
                        receivedCount += 1;
                    }
                    break;

                case "DIS":
                    if (e.security.PriceBarData.Count == 5)
                    {
                        receivedCount += 1;
                    }
                    break;
                }

                if (receivedCount == 3)
                {
                    requestComplete = true;
                    data.Disconnect();
                    IbLock = false;
                }
            };

            data.RequestPriceData(reqSec1, requestDateStart, requestDateEnd);
            data.RequestPriceData(reqSec2, requestDateStart, requestDateEnd);
            data.RequestPriceData(reqSec3, requestDateStart, requestDateEnd);
            data.RequestPriceData(reqSec4, requestDateStart, requestDateEnd);
            data.RequestPriceData(reqSec5, requestDateStart, requestDateEnd);

            timeout = 50;
            while (!requestComplete)
            {
                Thread.Sleep(100);
                Assert.IsTrue(--timeout > 0);
            }

            data.Disconnect();
            IbLock = false;
        }