Example #1
0
        public void TestAppendIQuoteCapture_FillGap()
        {
            _quoteBasic.Add(600, 1, 1, 1, 1, 1);

            IQuoteCapture qc = new QuoteCapture("symbol1");

            // 不填充
            qc.Add(720, 12);
            _quoteBasic.Append(qc, 10, false);
            Assert.AreEqual(600, _quoteBasic.Time[0]);
            Assert.AreEqual(720, _quoteBasic.Time[1]);

            // 填充
            _quoteBasic.Clear();
            _quoteBasic.Add(600, 1, 1, 1, 1, 1);
            _quoteBasic.Append(qc, 10, true);
            Assert.AreEqual(600, _quoteBasic.Time[0]);
            Assert.AreEqual(660, _quoteBasic.Time[1]);
            Assert.AreEqual(720, _quoteBasic.Time[2]);

            qc.Add(840, 12);
            _quoteBasic.Append(qc, 10, true);
            Assert.AreEqual(840, _quoteBasic.Time[4]);

            qc.Add(890, 12);
            _quoteBasic.Append(qc, 10, true);
            Assert.AreEqual(840, _quoteBasic.Time[4]);

            qc.Add(910, 12);
            _quoteBasic.Append(qc, 10, true);
            Assert.AreEqual(900, _quoteBasic.Time[5]);
            Assert.AreEqual(910, _quoteBasic.Time[6]);
        }
Example #2
0
        public void TestAppendStream_Normal()
        {
            var quoteBasicCapture = new QuoteCapture("DAG_2", 5, new List <long>(), new List <double>(), new List <double>());

            for (int i = 0; i <= 2; i++)
            {
                quoteBasicCapture.Add(i, i);
            }

            using (var stream = File.OpenWrite(fileName))
                quoteBasicCapture.AppendStream(stream);
            var contentStr = File.ReadAllText(fileName);

            Assert.AreEqual(contentStr, "Symbol:DAG_2;PipFactor:5\r\nTime;Price;Volume;\r\n0;0;0\r\n1;1;0\r\n2;2;0\r\n");
            var time1 = File.GetLastWriteTime(fileName);

            Thread.Sleep(100);
            using (var stream = File.OpenWrite(fileName))
                quoteBasicCapture.AppendStream(stream);
            // test overrite existing file
            contentStr = File.ReadAllText(fileName);
            Assert.AreEqual(contentStr, "Symbol:DAG_2;PipFactor:5\r\nTime;Price;Volume;\r\n0;0;0\r\n1;1;0\r\n2;2;0\r\n");
            var time2 = File.GetLastWriteTime(fileName);

            Assert.IsTrue(time2 > time1);
            File.Delete(fileName);
        }
Example #3
0
        public void TestAppendIQuoteCapture()
        {
            _quoteBasic.Add(600, 1, 1, 1, 1, 1); // 600

            // 非整数倍
            IQuoteCapture qc = new QuoteCapture("symbol1");

            qc.Add(620, 20);
            _quoteBasic.Append(qc, -1, false, false);
            Assert.AreEqual(1, _quoteBasic.Count);
            Assert.AreEqual(600, _quoteBasic.LastTime);

            // 整数倍
            qc.Add(660, 60);
            _quoteBasic.Append(qc, -1, false, false);
            Assert.AreEqual(2, _quoteBasic.Count);
            Assert.AreEqual(600, _quoteBasic.Time[0]);
            Assert.AreEqual(660, _quoteBasic.Time[1]);

            // 为空
            qc = new QuoteCapture("symbol1");
            _quoteBasic.Append(qc, -1, false, false);
            Assert.AreEqual(2, _quoteBasic.Count);
            Assert.AreEqual(600, _quoteBasic.Time[0]);
            Assert.AreEqual(660, _quoteBasic.Time[1]);;

            // 为null
            qc = null;
            _quoteBasic.Append(qc, -1, false, false);
            Assert.AreEqual(2, _quoteBasic.Count);
            Assert.AreEqual(600, _quoteBasic.Time[0]);
            Assert.AreEqual(660, _quoteBasic.Time[1]);

            //// 不填补空洞
            //qb = new QuoteBasic("symbol1", 20);
            //qb.Add(6000, 1, 1, 1, 1, 1, false);
            //_quoteBasic.Append(qb);
            //Assert.AreEqual(3, _quoteBasic.Count);
            //Assert.AreEqual(600, _quoteBasic.Time[0]);
            //Assert.AreEqual(660, _quoteBasic.Time[1]);
            //Assert.AreEqual(6000, _quoteBasic.Time[2]);
        }
Example #4
0
        public void TestAppend()
        {
            IQuoteCapture qc = null;

            // 测试null
            _quoteCapture.Append(qc);
            Assert.AreEqual(0, _quoteCapture.Count);

            // 测试空
            qc = new QuoteCapture();
            _quoteCapture.Append(qc);
            Assert.AreEqual(0, _quoteCapture.Count);

            // 测试不同的symbol
            qc = new QuoteCapture("symbol1");
            qc.Add(10, 20, 30);
            _quoteCapture.Append(qc);
            Assert.AreEqual(0, _quoteCapture.Count);

            // 测试_quoteCapter.LastTime < qc.LastTime
            qc = new QuoteCapture("symbol0");
            _quoteCapture.Add(10, 20, 15);
            qc.Add(5, 20);
            _quoteCapture.Append(qc);
            Assert.AreEqual(1, _quoteCapture.Count);
            Assert.AreEqual(10, _quoteCapture.Time[0]);
            Assert.AreEqual(20, _quoteCapture.Price[0]);
            Assert.AreEqual(15, _quoteCapture.Volume[0]);

            // 测试不添加小于LastTime的数据
            qc.Add(10, 18, 18);
            qc.Add(20, 30, 17);
            _quoteCapture.Append(qc);
            Assert.AreEqual(2, _quoteCapture.Count);
            Assert.AreEqual(10, _quoteCapture.Time[0]);
            Assert.AreEqual(20, _quoteCapture.Time[1]);
            Assert.AreEqual(20, _quoteCapture.Price[0]);
            Assert.AreEqual(30, _quoteCapture.Price[1]);
            Assert.AreEqual(15, _quoteCapture.Volume[0]);
            Assert.AreEqual(17, _quoteCapture.Volume[1]);
        }
Example #5
0
        public void TestExtract_IntInt()
        {
            IQuoteCapture qc = null;

            // 测试sindex > eindex
            TestHelper.AssertException(() => _quoteCapture.Extract(1, 0), typeof(ArgumentException));

            // 测试sindex < 0
            TestHelper.AssertException(() => _quoteCapture.Extract(-1, 0), typeof(ArgumentException));

            // 测试eindex < 0
            TestHelper.AssertException(() => _quoteCapture.Extract(0, -1), typeof(ArgumentException));

            // 测试eindex > _quoteCapture.Count - 1;
            _quoteCapture.Add(10, 12);
            TestHelper.AssertException(() => _quoteCapture.Extract(0, 5), typeof(ArgumentException));

            _quoteCapture = new QuoteCapture("xyz");
            _quoteCapture.Add(100, 10, 23);
            _quoteCapture.Add(200, 20, 24);
            _quoteCapture.Add(300, 30, 26);
            _quoteCapture.Add(400, 40, 27);
            _quoteCapture.Add(500, 50, 28);

            qc = _quoteCapture.Extract(1, 3);
            Assert.AreEqual(3, qc.Count);
            Assert.AreEqual(200, qc.Time[0]);
            Assert.AreEqual(300, qc.Time[1]);
            Assert.AreEqual(400, qc.Time[2]);
            Assert.AreEqual(20, qc.Price[0]);
            Assert.AreEqual(30, qc.Price[1]);
            Assert.AreEqual(40, qc.Price[2]);
            Assert.AreEqual(24, qc.Volume[0]);
            Assert.AreEqual(26, qc.Volume[1]);
            Assert.AreEqual(27, qc.Volume[2]);
        }
Example #6
0
        public void TestAppendStream_Append()
        {
            var quoteBasic = new QuoteCapture("DAG_2", 5, new List <long>(), new List <double>(), new List <double>());

            for (int i = 0; i <= 2; i++)
            {
                quoteBasic.Add(i, i);
            }

            using (var stream = File.OpenWrite(fileName))
                quoteBasic.AppendStream(stream);

            using (var stream = new FileStream(fileName, FileMode.Append, FileAccess.Write))
                quoteBasic.AppendStream(stream);

            var contentStr = File.ReadAllText(fileName);

            Assert.AreEqual(contentStr, "Symbol:DAG_2;PipFactor:5\r\nTime;Price;Volume;\r\n0;0;0\r\n1;1;0\r\n2;2;0\r\n0;0;0\r\n1;1;0\r\n2;2;0\r\n");
        }
Example #7
0
        public void TestAdd()
        {
            _quoteCapture.Add(10, 20);
            Assert.AreEqual(10, _quoteCapture.Time[0]);
            Assert.AreEqual(20, _quoteCapture.Price[0]);

            _quoteCapture.Add(20, 30);
            Assert.AreEqual(20, _quoteCapture.Time[1]);
            Assert.AreEqual(30, _quoteCapture.Price[1]);
        }
Example #8
0
        public void TestAppendIQuoteCapture_SubInterval()
        {
            _quoteBasic.Add(600, 1, 1, 1, 1, 1, false); // 600

            IQuoteCapture qc = new QuoteCapture("symbol1");

            qc.Add(620, 20);
            _quoteBasic.Append(qc, 20); // 600, 620
            Assert.AreEqual(2, _quoteBasic.Count);
            Assert.AreEqual(600, _quoteBasic.Time[0]);
            Assert.AreEqual(620, _quoteBasic.Time[1]);

            qc = new QuoteCapture("symbol1");
            qc.Add(640, 40);
            _quoteBasic.Append(qc, 20); // 600, 640
            Assert.AreEqual(2, _quoteBasic.Count);
            Assert.AreEqual(600, _quoteBasic.Time[0]);
            Assert.AreEqual(640, _quoteBasic.Time[1]);

            qc.Add(680, 80);
            _quoteBasic.Append(qc, 20); // 600, 660, 680
            Assert.AreEqual(3, _quoteBasic.Count);
            Assert.AreEqual(600, _quoteBasic.Time[0]);
            Assert.AreEqual(660, _quoteBasic.Time[1]);
            Assert.AreEqual(680, _quoteBasic.Time[2]);

            qc.Add(700, 100);
            _quoteBasic.Append(qc, 20); // 600, 660, 700
            Assert.AreEqual(3, _quoteBasic.Count);
            Assert.AreEqual(600, _quoteBasic.Time[0]);
            Assert.AreEqual(660, _quoteBasic.Time[1]);
            Assert.AreEqual(700, _quoteBasic.Time[2]);

            qc.Add(740, 140);
            qc.Add(760, 160);
            _quoteBasic.Append(qc, 20); // 600, 660, 720, 760
            Assert.AreEqual(4, _quoteBasic.Count);
            Assert.AreEqual(600, _quoteBasic.Time[0]);
            Assert.AreEqual(660, _quoteBasic.Time[1]);
            Assert.AreEqual(720, _quoteBasic.Time[2]);
            Assert.AreEqual(760, _quoteBasic.Time[3]);

            qc = new QuoteCapture("symbol1");
            qc.Add(761, 1);
            qc.Add(762, 1);
            qc.Add(763, 1);
            _quoteBasic.Append(qc, 1);
            Assert.AreEqual(4, _quoteBasic.Count);
            Assert.AreEqual(600, _quoteBasic.Time[0]);
            Assert.AreEqual(660, _quoteBasic.Time[1]);
            Assert.AreEqual(720, _quoteBasic.Time[2]);
            Assert.AreEqual(763, _quoteBasic.Time[3]);

            qc.Add(780, 90);
            _quoteBasic.Append(qc, 20);
            Assert.AreEqual(4, _quoteBasic.Count);
            Assert.AreEqual(600, _quoteBasic.Time[0]);
            Assert.AreEqual(660, _quoteBasic.Time[1]);
            Assert.AreEqual(720, _quoteBasic.Time[2]);
            Assert.AreEqual(780, _quoteBasic.Time[3]);
        }