Beispiel #1
0
 static void OnRtnDepthMarketData(object sender, ref DepthMarketDataNClass marketData)
 {
     Debugger.Log(0, null, "CTP:C#");
     Console.WriteLine(marketData.InstrumentID);
     Console.WriteLine(marketData.Exchange);
     Console.WriteLine(marketData.LastPrice);
 }
Beispiel #2
0
 static void OnRtnDepthMarketData(object sender, ref DepthMarketDataNClass marketData)
 {
     Debugger.Log(0, null, "CTP:C#");
     Console.WriteLine(marketData.InstrumentID);
     Console.WriteLine(marketData.Exchange);
     Console.WriteLine(marketData.LastPrice);
 }
Beispiel #3
0
        public static DateTime ExchangeDateTime([In] this DepthMarketDataNClass field)
        {
            int HH = field.UpdateTime / 10000;

            int mm = field.UpdateTime % 10000 / 100;
            int ss = field.UpdateTime % 100;

            int yyyy = field.ActionDay / 10000;
            int MM   = field.ActionDay % 10000 / 100;
            int dd   = field.ActionDay % 100;

            return(new DateTime(yyyy, MM, dd, HH, mm, ss, field.UpdateMillisec));
        }
Beispiel #4
0
        public static DepthMarketDataNClass GetDepthMarketDataNClass(IntPtr ptr)
        {
            DepthMarketDataNField obj = (DepthMarketDataNField)Marshal.PtrToStructure(ptr, typeof(DepthMarketDataNField));

            DepthMarketDataNClass cls = new DepthMarketDataNClass();

            //obj.Size;
            cls.TradingDay         = obj.TradingDay;
            cls.ActionDay          = obj.ActionDay;
            cls.UpdateTime         = obj.UpdateTime;
            cls.UpdateMillisec     = obj.UpdateMillisec;
            cls.Exchange           = obj.Exchange;
            cls.Symbol             = obj.Symbol;
            cls.InstrumentID       = obj.InstrumentID;
            cls.LastPrice          = obj.LastPrice;
            cls.Volume             = obj.Volume;
            cls.Turnover           = obj.Turnover;
            cls.OpenInterest       = obj.OpenInterest;
            cls.AveragePrice       = obj.AveragePrice;
            cls.OpenPrice          = obj.OpenPrice;
            cls.HighestPrice       = obj.HighestPrice;
            cls.LowestPrice        = obj.LowestPrice;
            cls.ClosePrice         = obj.ClosePrice;
            cls.SettlementPrice    = obj.SettlementPrice;
            cls.UpperLimitPrice    = obj.UpperLimitPrice;
            cls.LowerLimitPrice    = obj.LowerLimitPrice;
            cls.PreSettlementPrice = obj.PreSettlementPrice;
            cls.PreOpenInterest    = obj.PreOpenInterest;
            cls.TradingPhase       = obj.TradingPhase;
            //obj.BidCount;

            int    size     = Marshal.SizeOf(typeof(DepthField));
            IntPtr pBid     = new IntPtr(ptr.ToInt64() + Marshal.SizeOf(typeof(DepthMarketDataNField)));
            int    AskCount = (obj.Size - Marshal.SizeOf(typeof(DepthMarketDataNField))) / size - obj.BidCount;
            IntPtr pAsk     = new IntPtr(ptr.ToInt64() + Marshal.SizeOf(typeof(DepthMarketDataNField)) + obj.BidCount * size);

            cls.Bids = new DepthField[obj.BidCount];
            cls.Asks = new DepthField[AskCount];

            for (int i = 0; i < obj.BidCount; ++i)
            {
                cls.Bids[i] = (DepthField)Marshal.PtrToStructure(new IntPtr(pBid.ToInt64() + i * size), typeof(DepthField));
            }

            for (int i = 0; i < AskCount; ++i)
            {
                cls.Asks[i] = (DepthField)Marshal.PtrToStructure(new IntPtr(pAsk.ToInt64() + i * size), typeof(DepthField));
            }

            return(cls);
        }
Beispiel #5
0
        public static DateTime ExchangeDateTime_([In] this DepthMarketDataNClass field)
        {
            // 表示传回来的时间可能有问题,要检查一下
            if (field.UpdateTime == 0)
            {
                DateTime now = DateTime.Now;

                int HH       = now.Hour;
                int mm       = now.Minute;
                int ss       = now.Second;
                int datetime = HH * 10000 + mm * 100 + ss;

                if (datetime > 1500 && datetime < 234500)
                {
                    return(now);
                }
            }

            {
                int HH = field.UpdateTime / 10000;
                int mm = field.UpdateTime % 10000 / 100;
                int ss = field.UpdateTime % 100;

                DateTime now = DateTime.Now;
                if (HH >= 23)
                {
                    if (now.Hour < 1)
                    {
                        // 表示行情时间慢了,系统日期减一天即可
                        now = now.AddDays(-1);
                    }
                }
                else if (HH < 1)
                {
                    if (now.Hour >= 23)
                    {
                        // 表示本地时间慢了,本地时间加一天即可
                        now = now.AddDays(1);
                    }
                }

                return(now.Date.AddSeconds(HH * 3600 + mm * 60 + ss).AddMilliseconds(field.UpdateMillisec));
            }
        }
Beispiel #6
0
        public static DateTime ExchangeDateTime([In] this DepthMarketDataNClass field)
        {
            // 大商所夜盘时,ActionDay可能已经是指向的第二天
            int HH = field.UpdateTime / 10000;

            // 这个功能写入到C层中
            //if (HH > 20)
            //{
            //    if (field.ExchangeID.CompareTo("DCE") == 0)
            //    {
            //        return field.ExchangeDateTime_();
            //    }
            //}

            int mm = field.UpdateTime % 10000 / 100;
            int ss = field.UpdateTime % 100;

            int yyyy = field.ActionDay / 10000;
            int MM   = field.ActionDay % 10000 / 100;
            int dd   = field.ActionDay % 100;

            return(new DateTime(yyyy, MM, dd, HH, mm, ss, field.UpdateMillisec));
        }
 public void OnInputMarketData(DepthMarketDataNClass pDepthMarketData)
 {
     TickWriter.Write(ref pDepthMarketData);
 }
 private void OnRtnDepthMarketData(object sender, ref DepthMarketDataNClass marketData)
 {
     Input.Post(marketData);
 }
        private DepthMarketDataNClass PbTick2DepthMarketDataNClass(PbTickCodec codec, PbTickView tickView)
        {
            DepthMarketDataNClass marketData = new DepthMarketDataNClass();
            codec.GetUpdateTime(tickView, out marketData.UpdateTime, out marketData.UpdateMillisec);

            marketData.TradingDay = tickView.TradingDay;
            marketData.ActionDay = tickView.ActionDay;
            marketData.LastPrice = tickView.LastPrice;
            marketData.Volume = tickView.Volume;
            if (SubscribeExternData)
            {
                marketData.Turnover = tickView.Turnover;
                marketData.OpenInterest = tickView.OpenInterest;
                marketData.AveragePrice = tickView.AveragePrice;
                if (tickView.Bar != null)
                {
                    marketData.OpenPrice = tickView.Bar.Open;
                    marketData.HighestPrice = tickView.Bar.High;
                    marketData.LowestPrice = tickView.Bar.Low;
                    marketData.ClosePrice = tickView.Bar.Close;
                }
                if (tickView.Static != null)
                {
                    marketData.LowerLimitPrice = tickView.Static.LowerLimitPrice;
                    marketData.UpperLimitPrice = tickView.Static.UpperLimitPrice;
                    marketData.SettlementPrice = tickView.Static.SettlementPrice;
                    marketData.Symbol = tickView.Static.Symbol;
                    if (!string.IsNullOrWhiteSpace(tickView.Static.Exchange))
                    {
                        marketData.Exchange = Enum<ExchangeType>.Parse(tickView.Static.Exchange);
                    }
                    marketData.PreClosePrice = tickView.Static.PreClosePrice;
                    marketData.PreSettlementPrice = tickView.Static.PreSettlementPrice;
                    marketData.PreOpenInterest = tickView.Static.PreOpenInterest;
                }
            }

            int count = tickView.DepthList == null ? 0 : tickView.DepthList.Count;
            if (count > 0)
            {
                int AskPos = DepthListHelper.FindAsk1Position(tickView.DepthList, tickView.AskPrice1);
                int BidPos = AskPos - 1;
                int BidCount = BidPos + 1;
                int AskCount = count - AskPos;

                marketData.Bids = new DepthField[0];
                marketData.Asks = new DepthField[0];

                if(SubscribeBid)
                {
                    if(BidCount>0)
                    {
                        marketData.Bids = new DepthField[BidCount];
                        int j = 0;
                        for (int i = BidPos; i >= 0; --i)
                        {
                            marketData.Bids[j] = new DepthField()
                            {
                                Price = tickView.DepthList[i].Price,
                                Size = tickView.DepthList[i].Size,
                                Count = tickView.DepthList[i].Count,
                            };
                            ++j;
                        }
                    }
                }
                if (SubscribeAsk)
                {
                    if (AskCount > 0)
                    {
                        marketData.Asks = new DepthField[AskCount];

                        int j = 0;
                        for (int i = AskPos; i < count; ++i)
                        {
                            marketData.Asks[j] = new DepthField()
                            {
                                Price = tickView.DepthList[i].Price,
                                Size = tickView.DepthList[i].Size,
                                Count = tickView.DepthList[i].Count,
                            };
                            ++j;
                        }
                    }
                }
            }
            return marketData;
        }
Beispiel #10
0
 public static string ToFormattedStringExchangeDateTime([In] this DepthMarketDataNClass field)
 {
     return(string.Format("[TradingDay={0};ActionDay={1};UpdateTime={2},UpdateMillisec={3}]",
                          field.TradingDay, field.ActionDay, field.UpdateTime, field.UpdateMillisec));
 }
 public bool Write(ref DepthMarketDataNClass pDepthMarketData)
 {
     QuantBox.Data.Serializer.V2.TickWriter.WriterDataItem item;
     if (Items.TryGetValue(pDepthMarketData.Symbol, out item))
     {
         item.Tick = CreateTick(ref pDepthMarketData, item.Serializer.Codec);
         base.Write(item, item.Tick);
         return true;
     }
     return false;
 }
        // 目前先不处理港股的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;
        }