Пример #1
0
        public void TestTickDiff()
        {
            PbTickCodec codec = new PbTickCodec();

            codec.Config.SetTickSize(0.2);
            codec.TickSize = codec.Config.GetTickSize();
            codec.Config.Time_ssf_Diff = 5;

            PbTick tick1 = new PbTick();

            tick1.Config = codec.Config;

            codec.SetLastPrice(tick1, 1234);
            codec.SetVolume(tick1, 1);
            codec.SetActionDay(tick1, DateTime.Today);
            codec.SetTradingDay(tick1, DateTime.Today.AddDays(-1));
            //codec.Set
            codec.SetAskPrice(tick1, 1, 1234.2);
            codec.SetAskSize(tick1, 1, 1);
            //codec.SetAskPrice(tick1, 2, 1234.4);
            //codec.SetAskSize(tick1, 2, 1);
            //codec.SetAskPrice(tick1, 3, 1234.6);
            //codec.SetAskSize(tick1, 3, 3);
            //codec.SetAskPrice(tick1, 4, 1234.8);
            //codec.SetAskSize(tick1, 4, 4);
            //codec.SetAskPrice(tick1, 5, 1235.0);
            //codec.SetAskSize(tick1, 5, 5);
            //codec.SetAskPrice(tick1, 6, 1235.2);
            //codec.SetAskSize(tick1, 6, 6);

            codec.SetBidPrice(tick1, 1, 1234);
            codec.SetBidSize(tick1, 1, 1);
            //codec.SetBidPrice(tick1, 2, 1233.8);
            //codec.SetBidSize(tick1, 2, 2);
            //codec.SetBidPrice(tick1, 3, 1233.6);
            //codec.SetBidSize(tick1, 3, 3);
            //codec.SetBidPrice(tick1, 4, 1233.4);
            //codec.SetBidSize(tick1, 4, 4);
            //codec.SetBidPrice(tick1, 5, 1233.2);
            //codec.SetBidSize(tick1, 5, 5);
            //codec.SetBidPrice(tick1, 6, 1232.0);
            //codec.SetBidSize(tick1, 6, 6);

            codec.SetLowerLimitPrice(tick1, 123.4);
            codec.SetUpperLimitPrice(tick1, 567.8);
            codec.SetSettlementPrice(tick1, 123.4);

            codec.SetOpen(tick1, 10);
            codec.SetHigh(tick1, 10);
            codec.SetLow(tick1, 10);
            codec.SetClose(tick1, 10);
            codec.SetBarSize(tick1, 10);

            tick1.Time_HHmm = 1234;
            tick1.Time_____ssf__ = 567;
            tick1.Time________ff = 0;

            PbTick tick2 = new PbTick();
            codec.SetLastPrice(tick2, 1234.2);
            codec.SetVolume(tick2, 2);

            codec.SetActionDay(tick2, DateTime.Today);
            codec.SetTradingDay(tick2, DateTime.Today.AddDays(-1));
            codec.SetAskPrice(tick2, 1, 1234.2);
            codec.SetAskSize(tick2, 1, 1);
            codec.SetAskPrice(tick2, 2, 1234.4);
            codec.SetAskSize(tick2, 2, 2);
            codec.SetAskPrice(tick2, 3, 1234.6);
            codec.SetAskSize(tick2, 3, 3);

            codec.SetBidPrice(tick2, 1, 1234);
            codec.SetBidSize(tick2, 1, 1);
            codec.SetBidPrice(tick2, 2, 1233.8);
            codec.SetBidSize(tick2, 2, 2);
            codec.SetBidPrice(tick2, 3, 1233.6);
            codec.SetBidSize(tick2, 3, 3);

            codec.SetLowerLimitPrice(tick2, 123.4);
            codec.SetUpperLimitPrice(tick2, 567.8);
            codec.SetSettlementPrice(tick2, 123.4);

            codec.SetOpen(tick2, 10);
            codec.SetHigh(tick2, 10);
            codec.SetLow(tick2, 10);
            codec.SetClose(tick2, 10);
            codec.SetBarSize(tick2, 10);

            tick2.Time_HHmm = 1234;
            tick2.Time_____ssf__ = 572;
            tick2.Time________ff = 0;

            var diff = codec.Diff(tick1, tick2);

            Assert.AreEqual(0, diff.ActionDay);
            Assert.AreEqual(0, diff.TradingDay);
            Assert.AreEqual(null, diff.Static);
            Assert.AreEqual(null, diff.Bar);
            Assert.AreEqual(0, diff.Depth1_3.AskPrice1, "AskPrice1");
            Assert.AreEqual(0, diff.Depth1_3.AskSize1, "AskSize1");
            Assert.AreEqual(0, diff.Depth1_3.AskPrice2, "AskPrice2");
            Assert.AreEqual(2, diff.Depth1_3.AskSize2, "AskSize2");
            Assert.AreEqual(0, diff.Depth1_3.AskPrice3, "AskPrice3");
            Assert.AreEqual(3, diff.Depth1_3.AskSize3, "AskSize3");

            Assert.AreEqual(0, diff.Time_____ssf__);


            var tick3 = codec.Restore(tick1, diff);

            Assert.AreEqual(tick2.Depth1_3.AskPrice1, tick3.Depth1_3.AskPrice1);
            Assert.AreEqual(tick2.Depth1_3.AskPrice2, tick3.Depth1_3.AskPrice2);
            Assert.AreEqual(tick2.Depth1_3.AskPrice3, tick3.Depth1_3.AskPrice3);
            Assert.AreEqual(tick2.Depth1_3.AskSize1, tick3.Depth1_3.AskSize1);
            Assert.AreEqual(tick2.Depth1_3.AskSize2, tick3.Depth1_3.AskSize2);
            Assert.AreEqual(tick2.Depth1_3.AskSize3, tick3.Depth1_3.AskSize3);

            Assert.AreEqual(tick2.Depth1_3.BidPrice1, tick3.Depth1_3.BidPrice1);
            Assert.AreEqual(tick2.Depth1_3.BidPrice2, tick3.Depth1_3.BidPrice2);
            Assert.AreEqual(tick2.Depth1_3.BidPrice3, tick3.Depth1_3.BidPrice3);
            Assert.AreEqual(tick2.Depth1_3.BidSize1, tick3.Depth1_3.BidSize1);
            Assert.AreEqual(tick2.Depth1_3.BidSize2, tick3.Depth1_3.BidSize2);
            Assert.AreEqual(tick2.Depth1_3.BidSize3, tick3.Depth1_3.BidSize3);

            Assert.AreEqual(codec.GetLowerLimitPrice(tick1), codec.GetLowerLimitPrice(tick3));
            Assert.AreEqual(codec.GetUpperLimitPrice(tick1), codec.GetUpperLimitPrice(tick3));
            Assert.AreEqual(codec.GetSettlementPrice(tick1), codec.GetSettlementPrice(tick3));

            Assert.AreEqual(codec.GetOpen(tick1), codec.GetOpen(tick3));
            Assert.AreEqual(codec.GetHigh(tick1), codec.GetHigh(tick3));
            Assert.AreEqual(codec.GetLow(tick1), codec.GetLow(tick3));
            Assert.AreEqual(codec.GetClose(tick1), codec.GetClose(tick3));

            Assert.AreEqual(572, tick3.Time_____ssf__);
        }