Example #1
0
        public void TestTickMultiplier()
        {
            PbTickCodec codec = new PbTickCodec();

            codec.Config.SetTickSize(0.2);
            codec.Config.ContractMultiplier = 50000;
            codec.Config.Time_ssf_Diff      = 5;
            codec.UseFlat(false);

            PbTick tick1 = new PbTick();

            codec.SetAveragePrice(tick1, 123.45);
            codec.SetSettlementPrice(tick1, 123.45);
            codec.SetTurnover(tick1, 1234567890123456);
            codec.SetOpenInterest(tick1, 9123456789012345678);
            codec.SetVolume(tick1, 1234567890);



            Assert.AreEqual <double>(123.45, codec.GetAveragePrice(tick1));
            Assert.AreEqual <double>(123.45, codec.GetSettlementPrice(tick1));
            Assert.AreEqual <double>(1234567890120000, codec.GetTurnover(tick1));
            Assert.AreEqual <long>(9123456789012345678, codec.GetOpenInterest(tick1));
            Assert.AreEqual <long>(1234567890, codec.GetVolume(tick1));

            codec.Config.ContractMultiplier = 5;
            codec.SetTurnover(tick1, 1234567890123456);
            Assert.AreEqual <double>(1234567890123456, codec.GetTurnover(tick1));

            codec.Config.ContractMultiplier = 0.1;
            codec.SetTurnover(tick1, 12345678901234.56);
            Assert.AreEqual <double>(12345678901234.56, codec.GetTurnover(tick1));
        }
Example #2
0
        // 目前先不处理港股的tickSize变化的那种行情
        PbTick CreateTick(ref DepthMarketDataNClass pDepthMarketData, PbTickCodec codec)
        {
            var tick = new PbTick();

            tick.DepthList = new List <DepthItem>();
            tick.Config    = codec.Config;

            tick.TradingDay     = pDepthMarketData.TradingDay;
            tick.ActionDay      = pDepthMarketData.ActionDay;
            tick.Time_HHmm      = pDepthMarketData.UpdateTime / 100;
            tick.Time_____ssf__ = pDepthMarketData.UpdateTime % 100 * 10 + pDepthMarketData.UpdateMillisec / 100;
            tick.Time________ff = pDepthMarketData.UpdateMillisec % 100;
            // 数据接收器时计算本地与交易所的行情时间差
            // 1.这个地方是否保存?
            // 2.到底是XAPI中提供还是由接收器提供?
            //tick.LocalTime_Msec = (int)(DateTime.Now - codec.GetActionDayDateTime(tick)).TotalMilliseconds;

            codec.SetSymbol(tick, pDepthMarketData.Symbol);
            if (pDepthMarketData.Exchange != ExchangeType.Undefined)
            {
                codec.SetExchange(tick, Enum <ExchangeType> .ToString(pDepthMarketData.Exchange));
            }
            codec.SetLowerLimitPrice(tick, pDepthMarketData.LowerLimitPrice);
            codec.SetUpperLimitPrice(tick, pDepthMarketData.UpperLimitPrice);

            codec.SetOpen(tick, pDepthMarketData.OpenPrice);
            codec.SetHigh(tick, pDepthMarketData.HighestPrice);
            codec.SetLow(tick, pDepthMarketData.LowestPrice);
            codec.SetClose(tick, pDepthMarketData.ClosePrice);

            codec.SetVolume(tick, (long)pDepthMarketData.Volume);
            codec.SetOpenInterest(tick, (long)pDepthMarketData.OpenInterest);
            codec.SetTurnover(tick, pDepthMarketData.Turnover);//一定要设置合约乘数才能最优保存
            codec.SetAveragePrice(tick, pDepthMarketData.AveragePrice);
            codec.SetLastPrice(tick, pDepthMarketData.LastPrice);
            codec.SetSettlementPrice(tick, pDepthMarketData.SettlementPrice);

            codec.SetPreClosePrice(tick, pDepthMarketData.PreClosePrice);
            codec.SetPreSettlementPrice(tick, pDepthMarketData.PreSettlementPrice);
            codec.SetPreOpenInterest(tick, (long)pDepthMarketData.PreOpenInterest);

            for (int i = pDepthMarketData.Bids.Length - 1; i >= 0; --i)
            {
                var bid = pDepthMarketData.Bids[i];
                if (bid.Size == 0)
                {
                    break;
                }

                // 记录卖一价
                if (i == 0)
                {
                    codec.SetAskPrice1(tick, bid.Price);
                    tick.AskPrice1 += 1;
                }

                tick.DepthList.Add(new DepthItem(codec.PriceToTick(bid.Price), bid.Size, bid.Count));
            }

            for (int i = 0; i < pDepthMarketData.Asks.Length; ++i)
            {
                var ask = pDepthMarketData.Asks[i];

                if (ask.Size == 0)
                {
                    break;
                }

                // 记录卖一价
                if (i == 0)
                {
                    codec.SetAskPrice1(tick, ask.Price);
                }

                tick.DepthList.Add(new DepthItem(codec.PriceToTick(ask.Price), ask.Size, ask.Count));
            }

            return(tick);
        }
Example #3
0
        // 目前先不处理港股的tickSize变化的那种行情
        PbTick CreateTick(ref DepthMarketDataField pDepthMarketData, PbTickCodec codec)
        {
            var tick = new PbTick();

            tick.DepthList = new List <DepthItem>();
            tick.Config    = codec.Config;

            tick.TradingDay     = pDepthMarketData.TradingDay;
            tick.ActionDay      = pDepthMarketData.ActionDay;
            tick.Time_HHmm      = pDepthMarketData.UpdateTime / 100;
            tick.Time_____ssf__ = pDepthMarketData.UpdateTime % 100 * 10 + pDepthMarketData.UpdateMillisec / 100;
            tick.Time________ff = pDepthMarketData.UpdateMillisec % 100;
            // 数据接收器时计算本地与交易所的行情时间差
            // 1.这个地方是否保存?
            // 2.到底是XAPI中提供还是由接收器提供?
            //tick.LocalTime_Msec = (int)(DateTime.Now - codec.GetActionDayDateTime(tick)).TotalMilliseconds;

            codec.SetSymbol(tick, pDepthMarketData.Symbol);
            if (pDepthMarketData.Exchange != ExchangeType.Undefined)
            {
                codec.SetExchange(tick, Enum <ExchangeType> .ToString(pDepthMarketData.Exchange));
            }
            codec.SetLowerLimitPrice(tick, pDepthMarketData.LowerLimitPrice);
            codec.SetUpperLimitPrice(tick, pDepthMarketData.UpperLimitPrice);

            codec.SetOpen(tick, pDepthMarketData.OpenPrice);
            codec.SetHigh(tick, pDepthMarketData.HighestPrice);
            codec.SetLow(tick, pDepthMarketData.LowestPrice);
            codec.SetClose(tick, pDepthMarketData.ClosePrice);

            codec.SetVolume(tick, (long)pDepthMarketData.Volume);
            codec.SetOpenInterest(tick, (long)pDepthMarketData.OpenInterest);
            codec.SetTurnover(tick, pDepthMarketData.Turnover);//一定要设置合约乘数才能最优保存
            codec.SetAveragePrice(tick, pDepthMarketData.AveragePrice);
            codec.SetLastPrice(tick, pDepthMarketData.LastPrice);
            codec.SetSettlementPrice(tick, pDepthMarketData.SettlementPrice);

            do
            {
                if (pDepthMarketData.BidVolume1 == 0)
                {
                    break;
                }
                tick.DepthList.Insert(0, new DepthItem(codec.PriceToTick(pDepthMarketData.BidPrice1), pDepthMarketData.BidVolume1, 0));

                // 先记录一个假的,防止只有买价没有卖价的情况
                codec.SetAskPrice1(tick, pDepthMarketData.BidPrice1);
                tick.AskPrice1 += 1;

                if (pDepthMarketData.BidVolume2 == 0)
                {
                    break;
                }
                tick.DepthList.Insert(0, new DepthItem(codec.PriceToTick(pDepthMarketData.BidPrice2), pDepthMarketData.BidVolume2, 0));

                if (pDepthMarketData.BidVolume3 == 0)
                {
                    break;
                }
                tick.DepthList.Insert(0, new DepthItem(codec.PriceToTick(pDepthMarketData.BidPrice3), pDepthMarketData.BidVolume3, 0));

                if (pDepthMarketData.BidVolume4 == 0)
                {
                    break;
                }
                tick.DepthList.Insert(0, new DepthItem(codec.PriceToTick(pDepthMarketData.BidPrice4), pDepthMarketData.BidVolume4, 0));

                if (pDepthMarketData.BidVolume5 == 0)
                {
                    break;
                }
                tick.DepthList.Insert(0, new DepthItem(codec.PriceToTick(pDepthMarketData.BidPrice5), pDepthMarketData.BidVolume5, 0));
            } while (false);

            do
            {
                if (pDepthMarketData.AskVolume1 == 0)
                {
                    break;
                }
                tick.DepthList.Add(new DepthItem(codec.PriceToTick(pDepthMarketData.AskPrice1), pDepthMarketData.AskVolume1, 0));
                // 记录卖一价
                codec.SetAskPrice1(tick, pDepthMarketData.AskPrice1);

                if (pDepthMarketData.AskVolume2 == 0)
                {
                    break;
                }
                tick.DepthList.Add(new DepthItem(codec.PriceToTick(pDepthMarketData.AskPrice2), pDepthMarketData.AskVolume2, 0));

                if (pDepthMarketData.AskVolume3 == 0)
                {
                    break;
                }
                tick.DepthList.Add(new DepthItem(codec.PriceToTick(pDepthMarketData.AskPrice3), pDepthMarketData.AskVolume3, 0));

                if (pDepthMarketData.AskVolume4 == 0)
                {
                    break;
                }
                tick.DepthList.Add(new DepthItem(codec.PriceToTick(pDepthMarketData.AskPrice4), pDepthMarketData.AskVolume4, 0));

                if (pDepthMarketData.AskVolume5 == 0)
                {
                    break;
                }
                tick.DepthList.Add(new DepthItem(codec.PriceToTick(pDepthMarketData.AskPrice5), pDepthMarketData.AskVolume5, 0));
            } while (false);

            return(tick);
        }