Пример #1
0
        public static bool TryConvert(OpenQuant.API.Trade trade, ref StructRcvReport DepthMarketData)
        {
            if (tradeField == null)
            {
                tradeField = typeof(OpenQuant.API.Trade).GetField("trade", BindingFlags.NonPublic | BindingFlags.Instance);
            }

            TongShiTrade t = tradeField.GetValue(trade) as TongShiTrade;
            if (null != t)
            {
                DepthMarketData = t.DepthMarketData;
                return true;
            }
            return false;
        }
        void StockService_OnRcvReport(object sender, RcvReportEventArgs e)
        {
            _dateTime = Clock.Now;

            lock (_dictDepthMarketData)
            {
                for (int i = 0; i < e.RcvReports.Length; ++i)
                {
                    StructRcvReport pDepthMarketData = e.RcvReports[i];
                    
                    StructRcvReport DepthMarket;
                    _dictDepthMarketData.TryGetValue(pDepthMarketData.MarketStockCode, out DepthMarket);

                    _dictDepthMarketData[pDepthMarketData.MarketStockCode] = pDepthMarketData;

                    DataRecord record;
                    if (_dictAltSymbol2Instrument.TryGetValue(pDepthMarketData.MarketStockCode, out record))
                    {
                        if (record.TradeRequested)
                        {
                            if (DepthMarket.NewPrice == pDepthMarketData.NewPrice
                            && DepthMarket.Volume == pDepthMarketData.Volume)
                            { }
                            else
                            {
                                float volume = pDepthMarketData.Volume - DepthMarket.Volume;
                                if (0 == DepthMarket.Volume)
                                {
                                    //没有接收到最开始的一条,所以这计算每个Bar的数据时肯定超大,强行设置为0
                                    volume = 0;
                                }
                                else if (volume < 0)
                                {
                                    //如果隔夜运行,会出现今早成交量0-昨收盘成交量,出现负数,所以当发现为负时要修改
                                    volume = pDepthMarketData.Volume;
                                }


                                TongShiTrade trade = new TongShiTrade(_dateTime,
                                    pDepthMarketData.NewPrice,
                                    (int)volume);

                                EmitNewTradeEvent(record.Instrument, trade);
                            }
                        }

                        if (record.QuoteRequested)
                        {
                            TongShiQuote quote = new TongShiQuote(_dateTime,
                                    (double)pDepthMarketData.BuyPrice1,
                                    (int)pDepthMarketData.BuyVolume1,
                                    (double)pDepthMarketData.SellPrice1,
                                    (int)pDepthMarketData.SellVolume1
                                );

                            quote.DepthMarketData = pDepthMarketData;

                            EmitNewQuoteEvent(record.Instrument, quote);
                        }

                        if (record.MarketDepthRequested)
                        {
                            bool bAsk = true;
                            bool bBid = true;

                            if(bAsk)
                                bAsk = EmitNewMarketDepth(record.Instrument, _dateTime, 0, MDSide.Ask, (double)pDepthMarketData.SellPrice1, (int)pDepthMarketData.SellVolume1);
                            if(bBid)
                                bBid = EmitNewMarketDepth(record.Instrument, _dateTime, 0, MDSide.Bid, (double)pDepthMarketData.BuyPrice1, (int)pDepthMarketData.BuyVolume1);

                            if (bAsk)
                                bAsk = EmitNewMarketDepth(record.Instrument, _dateTime, 1, MDSide.Ask, (double)pDepthMarketData.SellPrice2, (int)pDepthMarketData.SellVolume2);
                            if (bBid)
                                bBid = EmitNewMarketDepth(record.Instrument, _dateTime, 1, MDSide.Bid, (double)pDepthMarketData.BuyPrice2, (int)pDepthMarketData.BuyVolume2);

                            if (bAsk)
                                bAsk = EmitNewMarketDepth(record.Instrument, _dateTime, 2, MDSide.Ask, (double)pDepthMarketData.SellPrice3, (int)pDepthMarketData.SellVolume3);
                            if (bBid)
                                bBid = EmitNewMarketDepth(record.Instrument, _dateTime, 2, MDSide.Bid, (double)pDepthMarketData.BuyPrice3, (int)pDepthMarketData.BuyVolume3);

                            if (bAsk)
                                bAsk = EmitNewMarketDepth(record.Instrument, _dateTime, 3, MDSide.Ask, (double)pDepthMarketData.SellPrice4, (int)pDepthMarketData.SellVolume4);
                            if (bBid)
                                bBid = EmitNewMarketDepth(record.Instrument, _dateTime, 3, MDSide.Bid, (double)pDepthMarketData.BuyPrice4, (int)pDepthMarketData.BuyVolume4);

                            if (bAsk)
                                bAsk = EmitNewMarketDepth(record.Instrument, _dateTime, 4, MDSide.Ask, (double)pDepthMarketData.SellPrice5, (int)pDepthMarketData.SellVolume5);
                            if (bBid)
                                bBid = EmitNewMarketDepth(record.Instrument, _dateTime, 4, MDSide.Bid, (double)pDepthMarketData.BuyPrice5, (int)pDepthMarketData.BuyVolume5);
                        }
                    }
                }
            }
        }