public void SendMarketDataRequest(FIXMarketDataRequest request)
        {
            if (!_bMdConnected)
            {
                EmitError(-1, -1, "行情服务器没有连接");
                mdlog.Error("行情服务器没有连接");
                return;
            }

            bool bSubscribe = false;
            bool bTrade = false;
            bool bQuote = false;
            bool bMarketDepth = false;
            if (request.NoMDEntryTypes > 0)
            {
                switch (request.GetMDEntryTypesGroup(0).MDEntryType)
                {
                    case '0':
                    case '1':
                        if (request.MarketDepth != 1)
                        {
                            bMarketDepth = true;
                            break;
                        }
                        bQuote = true;
                        break;
                    case '2':
                        bTrade = true;
                        break;
                }
            }
            bSubscribe = (request.SubscriptionRequestType == DataManager.MARKET_DATA_SUBSCRIBE);

            if (bSubscribe)
            {
                for (int i = 0; i < request.NoRelatedSym; ++i)
                {
                    FIXRelatedSymGroup group = request.GetRelatedSymGroup(i);
                    Instrument inst = InstrumentManager.Instruments[group.Symbol];

                    //将用户合约转成交易所合约
                    string altSymbol = inst.GetSymbol(this.Name);
                    string altExchange = inst.GetSecurityExchange(this.Name);

                    DataRecord record;
                    if (!_dictAltSymbol2Instrument.TryGetValue(altSymbol, out record))
                    {
                        record = new DataRecord();
                        record.Instrument = inst;
                        _dictAltSymbol2Instrument[altSymbol] = record;

                        mdlog.Info("订阅合约 {0} {1}", altSymbol, altExchange);
                        MdApi.MD_Subscribe(m_pMdApi, altSymbol);

                        if (_bTdConnected)
                        {
                            //TraderApi.TD_ReqQryInvestorPosition(m_pTdApi, null);
                            //timerPonstion.Enabled = false;
                            //timerPonstion.Enabled = true;
                        }
                    }

                    //记录行情,同时对用户合约与交易所合约进行映射
                    DFITCDepthMarketDataField DepthMarket;
                    if (!_dictDepthMarketData.TryGetValue(altSymbol, out DepthMarket))
                    {
                        _dictDepthMarketData.Add(altSymbol, DepthMarket);
                    }

                    if (bTrade)
                        record.TradeRequested = true;
                    if (bQuote)
                        record.QuoteRequested = true;
                    if (bMarketDepth)
                        record.MarketDepthRequested = true;

                    if (bMarketDepth)
                    {
                        inst.OrderBook.Clear();
                    }
                }
            }
            else
            {
                for (int i = 0; i < request.NoRelatedSym; ++i)
                {
                    FIXRelatedSymGroup group = request.GetRelatedSymGroup(i);
                    Instrument inst = InstrumentManager.Instruments[group.Symbol];

                    //将用户合约转成交易所合约
                    string altSymbol = inst.GetSymbol(this.Name);
                    string altExchange = inst.GetSecurityExchange(this.Name);

                    DataRecord record;
                    if (!_dictAltSymbol2Instrument.TryGetValue(altSymbol, out record))
                    {
                        break;
                    }

                    if (bTrade)
                        record.TradeRequested = false;
                    if (bQuote)
                        record.QuoteRequested = false;
                    if (bMarketDepth)
                        record.MarketDepthRequested = false;

                    if (!record.TradeRequested && !record.QuoteRequested && !record.MarketDepthRequested)
                    {
                        _dictDepthMarketData.Remove(altSymbol);
                        _dictAltSymbol2Instrument.Remove(altSymbol);
                        mdlog.Info("取消订阅 {0} {1}", altSymbol, altExchange);
                        MdApi.MD_Unsubscribe(m_pMdApi, altSymbol);
                    }
                }
            }
        }
        public void SendMarketDataRequest(FIXMarketDataRequest request)
        {
            if (!_bMdConnected)
            {
                EmitError(-1, -1, "行情服务器没有连接");
                mdlog.Error("行情服务器没有连接");
                return;
            }

            bool bSubscribe   = false;
            bool bTrade       = false;
            bool bQuote       = false;
            bool bMarketDepth = false;

            if (request.NoMDEntryTypes > 0)
            {
                switch (request.GetMDEntryTypesGroup(0).MDEntryType)
                {
                case '0':
                case '1':
                    if (request.MarketDepth != 1)
                    {
                        bMarketDepth = true;
                        break;
                    }
                    bQuote = true;
                    break;

                case '2':
                    bTrade = true;
                    break;
                }
            }
            bSubscribe = (request.SubscriptionRequestType == DataManager.MARKET_DATA_SUBSCRIBE);

            if (bSubscribe)
            {
                for (int i = 0; i < request.NoRelatedSym; ++i)
                {
                    FIXRelatedSymGroup group = request.GetRelatedSymGroup(i);
                    Instrument         inst  = InstrumentManager.Instruments[group.Symbol];

                    //将用户合约转成交易所合约
                    string altSymbol   = inst.GetSymbol(this.Name);
                    string altExchange = inst.GetSecurityExchange(this.Name);

                    DataRecord record;
                    if (!_dictAltSymbol2Instrument.TryGetValue(altSymbol, out record))
                    {
                        record            = new DataRecord();
                        record.Instrument = inst;
                        _dictAltSymbol2Instrument[altSymbol] = record;

                        mdlog.Info("订阅合约 {0} {1}", altSymbol, altExchange);
                        MdApi.MD_Subscribe(m_pMdApi, altSymbol);

                        if (_bTdConnected)
                        {
                            //TraderApi.TD_ReqQryInvestorPosition(m_pTdApi, null);
                            //timerPonstion.Enabled = false;
                            //timerPonstion.Enabled = true;
                        }
                    }

                    //记录行情,同时对用户合约与交易所合约进行映射
                    DFITCDepthMarketDataField DepthMarket;
                    if (!_dictDepthMarketData.TryGetValue(altSymbol, out DepthMarket))
                    {
                        _dictDepthMarketData.Add(altSymbol, DepthMarket);
                    }

                    if (bTrade)
                    {
                        record.TradeRequested = true;
                    }
                    if (bQuote)
                    {
                        record.QuoteRequested = true;
                    }
                    if (bMarketDepth)
                    {
                        record.MarketDepthRequested = true;
                    }

                    if (bMarketDepth)
                    {
                        inst.OrderBook.Clear();
                    }
                }
            }
            else
            {
                for (int i = 0; i < request.NoRelatedSym; ++i)
                {
                    FIXRelatedSymGroup group = request.GetRelatedSymGroup(i);
                    Instrument         inst  = InstrumentManager.Instruments[group.Symbol];

                    //将用户合约转成交易所合约
                    string altSymbol   = inst.GetSymbol(this.Name);
                    string altExchange = inst.GetSecurityExchange(this.Name);

                    DataRecord record;
                    if (!_dictAltSymbol2Instrument.TryGetValue(altSymbol, out record))
                    {
                        break;
                    }

                    if (bTrade)
                    {
                        record.TradeRequested = false;
                    }
                    if (bQuote)
                    {
                        record.QuoteRequested = false;
                    }
                    if (bMarketDepth)
                    {
                        record.MarketDepthRequested = false;
                    }

                    if (!record.TradeRequested && !record.QuoteRequested && !record.MarketDepthRequested)
                    {
                        _dictDepthMarketData.Remove(altSymbol);
                        _dictAltSymbol2Instrument.Remove(altSymbol);
                        mdlog.Info("取消订阅 {0} {1}", altSymbol, altExchange);
                        MdApi.MD_Unsubscribe(m_pMdApi, altSymbol);
                    }
                }
            }
        }