Exemplo n.º 1
0
        public void SendMarketDataRequest(FIXMarketDataRequest request)
        {
            bool flag = (int)request.SubscriptionRequestType == 49;

            for (int i = 0; i < request.NoRelatedSym; ++i)
            {
                this.V6Aetvk5jr(InstrumentManager.Instruments[request.GetRelatedSymGroup(i).Symbol], request.GetRelatedSymGroup(i).GetStringValue(10001), flag);
            }
        }
Exemplo n.º 2
0
        public void SendMarketDataRequest(FIXMarketDataRequest request)
        {
            bool subscribe = request.SubscriptionRequestType == '1';

            for (int i = 0; i < request.NoRelatedSym; i++)
            {
                Instrument instrument  = InstrumentManager.Instruments[request.GetRelatedSymGroup(i).Symbol];
                string     stringValue = request.GetRelatedSymGroup(i).GetStringValue(10001);
                this.AddSimulatedSeries(instrument, stringValue, subscribe);
            }
        }
Exemplo n.º 3
0
 public override void SendMarketDataRequest(FIXMarketDataRequest request)
 {
     if (this.IsConnected)
     {
         this.application.Send(request);
     }
     else
     {
         this.EmitError(nvcneRd3YWS84l4984.Ey6KSwFglw(804));
     }
 }
Exemplo n.º 4
0
        public virtual void SendMarketDataRequest(FIXMarketDataRequest request)
        {
            if (this.IsConnected)
            {
                switch (request.SubscriptionRequestType)
                {
                case '1':
                    string        str1 = this.agD49enOqk(request.GetRelatedSymGroup(0));
                    RequestRecord requestRecord1;
                    if (str1 == null)
                    {
                        ++this.mdReqCount;
                        string str2 = string.Format(BeAEwTZGlZaeOmY5cm.J00weU3cM6(3836), (object)Clock.Now, (object)this.mdReqCount);
                        request.MDReqID = str2;
                        requestRecord1  = new RequestRecord(request.GetRelatedSymGroup(0).Symbol, request);
                        this.mdRequests.Add((object)str2, (object)requestRecord1);
                        this.application.Send(request);
                    }
                    else
                    {
                        requestRecord1 = this.mdRequests[(object)str1] as RequestRecord;
                    }
                    ++requestRecord1.RequestCount;
                    break;

                case '2':
                    string str3 = this.agD49enOqk(request.GetRelatedSymGroup(0));
                    if (str3 == null)
                    {
                        break;
                    }
                    RequestRecord requestRecord2 = this.mdRequests[(object)str3] as RequestRecord;
                    --requestRecord2.RequestCount;
                    if (requestRecord2.RequestCount != 0)
                    {
                        break;
                    }
                    request.MDReqID = str3;
                    this.application.Send(request);
                    this.mdRequests.Remove((object)str3);
                    break;
                }
            }
            else
            {
                if (this.j4t4Wyi2Ea == null)
                {
                    return;
                }
                this.j4t4Wyi2Ea(new ProviderErrorEventArgs((IProvider)this, -1, -1, BeAEwTZGlZaeOmY5cm.J00weU3cM6(3894)));
            }
        }
Exemplo n.º 5
0
        public void SendMarketDataRequest(FIXMarketDataRequest request)
        {
            SubscriptionDataType subscriptionDataType = (SubscriptionDataType)0;

            for (int i = 0; i < request.NoMDEntryTypes; i++)
            {
                FIXMDEntryTypesGroup mDEntryTypesGroup = request.GetMDEntryTypesGroup(i);
                switch (mDEntryTypesGroup.MDEntryType)
                {
                case '0':
                case '1':
                    if (request.MarketDepth == 1)
                    {
                        subscriptionDataType |= SubscriptionDataType.Quotes;
                    }
                    else
                    {
                        subscriptionDataType |= SubscriptionDataType.OrderBook;
                    }
                    break;

                case '2':
                    subscriptionDataType |= SubscriptionDataType.Trades;
                    break;
                }
            }
            for (int j = 0; j < request.NoRelatedSym; j++)
            {
                FIXRelatedSymGroup relatedSymGroup           = request.GetRelatedSymGroup(j);
                SmartQuant.Instruments.Instrument key        = SmartQuant.Instruments.InstrumentManager.Instruments[relatedSymGroup.Symbol];
                global::OpenQuant.API.Instrument  instrument = Map.SQ_OQ_Instrument[key] as global::OpenQuant.API.Instrument;
                switch (request.SubscriptionRequestType)
                {
                case '1':
                    this.provider.CallSubscribe(instrument, subscriptionDataType);
                    break;

                case '2':
                    this.provider.CallUnsubscribe(instrument, subscriptionDataType);
                    break;

                default:
                    throw new Exception("Unknown subscription request type " + request.SubscriptionRequestType);
                }
            }
        }
Exemplo n.º 6
0
        public void SendMarketDataRequest(FIXMarketDataRequest request)
        {
            SubscriptionDataType subscriptionDataType = (SubscriptionDataType)0;

            for (int i = 0; i < request.NoMDEntryTypes; ++i)
            {
                switch (request.GetMDEntryTypesGroup(i).MDEntryType)
                {
                case '0':
                case '1':
                    if (request.MarketDepth == 1)
                    {
                        subscriptionDataType |= SubscriptionDataType.Quotes;
                        break;
                    }
                    else
                    {
                        subscriptionDataType |= SubscriptionDataType.OrderBook;
                        break;
                    }

                case '2':
                    subscriptionDataType |= SubscriptionDataType.Trades;
                    break;
                }
            }
            for (int i = 0; i < request.NoRelatedSym; ++i)
            {
                FreeQuant.Instruments.Instrument instrument1 = FreeQuant.Instruments.InstrumentManager.Instruments[request.GetRelatedSymGroup(i).Symbol];
                Instrument instrument2 = Map.FQ_OQ_Instrument[(object)instrument1] as Instrument;
                switch (request.SubscriptionRequestType)
                {
                case '1':
                    this.provider.CallSubscribe(instrument2, subscriptionDataType);
                    break;

                case '2':
                    this.provider.CallUnsubscribe(instrument2, subscriptionDataType);
                    break;

                default:
                    throw new Exception("Unknown subscription request type " + (object)request.SubscriptionRequestType);
                }
            }
        }
Exemplo n.º 7
0
        public void SendMarketDataRequest(FIXMarketDataRequest request)
        {
            lock (this)
            {
                if (!IsConnected)
                {
                    EmitError(1, "The current market data provider not connected.");
                    return;
                }
                switch (request.SubscriptionRequestType)
                {
                case DataManager.MARKET_DATA_SUBSCRIBE:
                    for (int i = 0; i < request.NoRelatedSym; i++)
                    {
                        FIXRelatedSymGroup group = request.GetRelatedSymGroup(i);
                        if (!this.subscribedSymbols.Contains(group.Symbol))
                        {
                            this.SubscribeSymbol(group.Symbol);
                            this.subscribedSymbols.Add(group.Symbol);
                        }
                    }
                    break;

                case DataManager.MARKET_DATA_UNSUBSCRIBE:
                    for (int i = 0; i < request.NoRelatedSym; i++)
                    {
                        FIXRelatedSymGroup group = request.GetRelatedSymGroup(i);
                        if (this.subscribedSymbols.Contains(group.Symbol))
                        {
                            this.UnsubscribeSymbol(group.Symbol);
                            this.subscribedSymbols.Remove(group.Symbol);
                        }
                    }
                    break;

                default:
                    throw new ArgumentException("Unknown subscription type: " + request.SubscriptionRequestType.ToString());
                }
            }
        }
Exemplo n.º 8
0
 public virtual void SendMarketDataRequest(FIXMarketDataRequest request)
 {
 }
Exemplo n.º 9
0
        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;
                        }
                    }

                    //记录行情,同时对用户合约与交易所合约进行映射
                    CThostFtdcDepthMarketDataField 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);
                    }
                }
            }
        }
Exemplo n.º 10
0
 public RequestRecord(string symbol, FIXMarketDataRequest request)
 {
     this.Symbol       = symbol;
     this.Request      = request;
     this.RequestCount = 0;
 }
        public override void Send(FIXMarketDataRequest Request)
        {
            //Console.WriteLine("REQUEST");

            QuickFix42.MarketDataRequest request = new QuickFix42.MarketDataRequest(
                new QuickFix.MDReqID(Request.MDReqID),
                new QuickFix.SubscriptionRequestType(SubscriptionRequestType.SNAPSHOT), //GS FIX
                new QuickFix.MarketDepth(5));                                           //GS FIX

            //request.set(new QuickFix.MDUpdateType(Request.MDUpdateType));
            //request.set(new QuickFix.AggregatedBook(Request.AggregatedBook));

            QuickFix42.MarketDataRequest.NoMDEntryTypes typeGroup;

            typeGroup = new QuickFix42.MarketDataRequest.NoMDEntryTypes();
            typeGroup.set(new MDEntryType(FIXMDEntryType.Bid));
            request.addGroup(typeGroup);
            typeGroup.Dispose();

            typeGroup = new QuickFix42.MarketDataRequest.NoMDEntryTypes();
            typeGroup.set(new MDEntryType(FIXMDEntryType.Offer));
            request.addGroup(typeGroup);
            typeGroup.Dispose();

            typeGroup = new QuickFix42.MarketDataRequest.NoMDEntryTypes();
            typeGroup.set(new MDEntryType(FIXMDEntryType.Trade));
            request.addGroup(typeGroup);
            typeGroup.Dispose();

            //typeGroup = new QuickFix42.MarketDataRequest.NoMDEntryTypes();
            //typeGroup.set(new MDEntryType(FIXMDEntryType.Open));
            //request.addGroup(typeGroup);
            //typeGroup.Dispose();

            //typeGroup = new QuickFix42.MarketDataRequest.NoMDEntryTypes();
            //typeGroup.set(new MDEntryType(FIXMDEntryType.Close));
            //request.addGroup(typeGroup);
            //typeGroup.Dispose();

            //typeGroup = new QuickFix42.MarketDataRequest.NoMDEntryTypes();
            //typeGroup.set(new MDEntryType(FIXMDEntryType.High));
            //request.addGroup(typeGroup);
            //typeGroup.Dispose();

            //typeGroup = new QuickFix42.MarketDataRequest.NoMDEntryTypes();
            //typeGroup.set(new MDEntryType(FIXMDEntryType.Low));
            //request.addGroup(typeGroup);
            //typeGroup.Dispose();

            QuickFix42.MarketDataRequest.NoRelatedSym symGroup = new QuickFix42.MarketDataRequest.NoRelatedSym();

            FIXRelatedSymGroup Group = Request.GetRelatedSymGroup(0);

            symGroup.set(new QuickFix.Symbol(Group.Symbol.Substring(0, 6)));

            if (Group.Symbol.StartsWith("60") || Group.Symbol.StartsWith("51"))
            {
                //order.set(new QuickFix.SecurityExchange("XSHG"));// 上海
                symGroup.set(new QuickFix.SecurityExchange("SS"));// 上海
            }
            else if (Group.Symbol.StartsWith("00") || Group.Symbol.StartsWith("30") || Group.Symbol.StartsWith("15"))
            {
                //order.set(new QuickFix.SecurityExchange("XSHE"));// 深圳
                symGroup.set(new QuickFix.SecurityExchange("SZ"));// 深圳
            }

            //if (Group.ContainsField(EFIXField.SecurityType)) symGroup.set(new QuickFix.SecurityType(Group.SecurityType));
            //if (Group.ContainsField(EFIXField.MaturityMonthYear)) symGroup.set(new QuickFix.MaturityMonthYear(Group.MaturityMonthYear));
            //if (Group.ContainsField(EFIXField.MaturityDay           )) symGroup.set(new QuickFix.MaturityDay           (Group.MaturityDay           ));
            //if (Group.ContainsField(EFIXField.PutOrCall             )) symGroup.set(new QuickFix.PutOrCall             (Group.PutOrCall             ));
            //if (Group.ContainsField(EFIXField.StrikePrice)) symGroup.set(new QuickFix.StrikePrice(Group.StrikePrice));
            //if (Group.ContainsField(EFIXField.OptAttribute)) symGroup.set(new QuickFix.OptAttribute(Group.OptAttribute));
            //if (Group.ContainsField(EFIXField.SecurityID)) symGroup.set(new QuickFix.SecurityID(Group.SecurityID));
            //if (Group.ContainsField(EFIXField.SecurityExchange)) symGroup.set(new QuickFix.SecurityExchange(Group.SecurityExchange));

            request.addGroup(symGroup);

            symGroup.Dispose();

            if (base.priceSessionID == null)
            {
                Session.sendToTarget(request, orderSessionID);
            }
            else
            {
                Session.sendToTarget(request, priceSessionID);
            }
        }
Exemplo n.º 12
0
        public override void Send(FIXMarketDataRequest Request)
        {
            //Console.WriteLine("REQUEST");

            QuickFix42.MarketDataRequest request = new QuickFix42.MarketDataRequest(
                new QuickFix.MDReqID(Request.MDReqID),
                new QuickFix.SubscriptionRequestType(SubscriptionRequestType.SNAPSHOT), //GS FIX
                new QuickFix.MarketDepth(5)); //GS FIX

            //request.set(new QuickFix.MDUpdateType(Request.MDUpdateType));
            //request.set(new QuickFix.AggregatedBook(Request.AggregatedBook));

            QuickFix42.MarketDataRequest.NoMDEntryTypes typeGroup;

            typeGroup = new QuickFix42.MarketDataRequest.NoMDEntryTypes();
            typeGroup.set(new MDEntryType(FIXMDEntryType.Bid));
            request.addGroup(typeGroup);
            typeGroup.Dispose();

            typeGroup = new QuickFix42.MarketDataRequest.NoMDEntryTypes();
            typeGroup.set(new MDEntryType(FIXMDEntryType.Offer));
            request.addGroup(typeGroup);
            typeGroup.Dispose();

            typeGroup = new QuickFix42.MarketDataRequest.NoMDEntryTypes();
            typeGroup.set(new MDEntryType(FIXMDEntryType.Trade));
            request.addGroup(typeGroup);
            typeGroup.Dispose();

            //typeGroup = new QuickFix42.MarketDataRequest.NoMDEntryTypes();
            //typeGroup.set(new MDEntryType(FIXMDEntryType.Open));
            //request.addGroup(typeGroup);
            //typeGroup.Dispose();

            //typeGroup = new QuickFix42.MarketDataRequest.NoMDEntryTypes();
            //typeGroup.set(new MDEntryType(FIXMDEntryType.Close));
            //request.addGroup(typeGroup);
            //typeGroup.Dispose();

            //typeGroup = new QuickFix42.MarketDataRequest.NoMDEntryTypes();
            //typeGroup.set(new MDEntryType(FIXMDEntryType.High));
            //request.addGroup(typeGroup);
            //typeGroup.Dispose();

            //typeGroup = new QuickFix42.MarketDataRequest.NoMDEntryTypes();
            //typeGroup.set(new MDEntryType(FIXMDEntryType.Low));
            //request.addGroup(typeGroup);
            //typeGroup.Dispose();

            QuickFix42.MarketDataRequest.NoRelatedSym symGroup = new QuickFix42.MarketDataRequest.NoRelatedSym();

            FIXRelatedSymGroup Group = Request.GetRelatedSymGroup(0);

            symGroup.set(new QuickFix.Symbol(Group.Symbol.Substring(0, 6)));

            if (Group.Symbol.StartsWith("60") || Group.Symbol.StartsWith("51"))
            {
                //order.set(new QuickFix.SecurityExchange("XSHG"));// 上海
                symGroup.set(new QuickFix.SecurityExchange("SS"));// 上海
            }
            else if (Group.Symbol.StartsWith("00") || Group.Symbol.StartsWith("30") || Group.Symbol.StartsWith("15"))
            {
                //order.set(new QuickFix.SecurityExchange("XSHE"));// 深圳
                symGroup.set(new QuickFix.SecurityExchange("SZ"));// 深圳
            }

            //if (Group.ContainsField(EFIXField.SecurityType)) symGroup.set(new QuickFix.SecurityType(Group.SecurityType));
            //if (Group.ContainsField(EFIXField.MaturityMonthYear)) symGroup.set(new QuickFix.MaturityMonthYear(Group.MaturityMonthYear));
            //if (Group.ContainsField(EFIXField.MaturityDay           )) symGroup.set(new QuickFix.MaturityDay           (Group.MaturityDay           ));
            //if (Group.ContainsField(EFIXField.PutOrCall             )) symGroup.set(new QuickFix.PutOrCall             (Group.PutOrCall             ));
            //if (Group.ContainsField(EFIXField.StrikePrice)) symGroup.set(new QuickFix.StrikePrice(Group.StrikePrice));
            //if (Group.ContainsField(EFIXField.OptAttribute)) symGroup.set(new QuickFix.OptAttribute(Group.OptAttribute));
            //if (Group.ContainsField(EFIXField.SecurityID)) symGroup.set(new QuickFix.SecurityID(Group.SecurityID));
            //if (Group.ContainsField(EFIXField.SecurityExchange)) symGroup.set(new QuickFix.SecurityExchange(Group.SecurityExchange));

            request.addGroup(symGroup);

            symGroup.Dispose();

            if(base.priceSessionID == null)
                Session.sendToTarget(request, orderSessionID);
            else
                Session.sendToTarget(request, priceSessionID);
        }
        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 FIXMDEntryType.Bid:
                case FIXMDEntryType.Offer:
                    if (request.MarketDepth != 1)
                    {
                        bMarketDepth = true;
                        break;
                    }
                    bQuote = true;
                    break;

                case FIXMDEntryType.Trade:
                    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);
                    string apiSymbol   = GetApiSymbol(altSymbol);
                    string apiExchange = altExchange;
#if CTPZQ
                    altSymbol = GetYahooSymbol(apiSymbol, apiExchange);
#endif
                    CThostFtdcInstrumentField _Instrument;
                    if (_dictInstruments.TryGetValue(altSymbol, out _Instrument))
                    {
                        apiSymbol   = _Instrument.InstrumentID;
                        apiExchange = _Instrument.ExchangeID;
                    }

#if CTPZQ
                    altSymbol = GetYahooSymbol(apiSymbol, apiExchange);
#endif
                    DataRecord record;
                    if (!_dictAltSymbol2Instrument.TryGetValue(altSymbol, out record))
                    {
                        record            = new DataRecord();
                        record.Instrument = inst;
                        record.Symbol     = apiSymbol;
                        record.Exchange   = apiExchange;
                        _dictAltSymbol2Instrument[altSymbol] = record;

                        mdlog.Info("订阅合约/订阅询价 {0} {1} {2}", altSymbol, record.Symbol, record.Exchange);

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

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

                    // 多次订阅也无所谓
                    MdApi.MD_Subscribe(m_pMdApi, record.Symbol, record.Exchange);
                    MdApi.MD_SubscribeQuote(m_pMdApi, record.Symbol, record.Exchange);

                    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} {2}", altSymbol, record.Symbol, record.Exchange);
                        MdApi.MD_Unsubscribe(m_pMdApi, record.Symbol, record.Exchange);
                        MdApi.MD_UnsubscribeQuote(m_pMdApi, record.Symbol, record.Exchange);
                    }
                    else
                    {
                        // 只要有一种类型说要订阅,就给订上
                        MdApi.MD_Subscribe(m_pMdApi, record.Symbol, record.Exchange);
                        MdApi.MD_SubscribeQuote(m_pMdApi, record.Symbol, record.Exchange);
                    }
                }
            }
        }
        public void SendMarketDataRequest(FIXMarketDataRequest request)
        {
            lock (this)
            {
                switch (request.SubscriptionRequestType)
                {
                    case DataManager.MARKET_DATA_SUBSCRIBE:
                        if (!_bMdConnected)
                        {
                            EmitError(-1,-1,"行情服务器没有连接,无法订阅行情");
                            return;
                        }
                        for (int i = 0; i < request.NoRelatedSym; ++i)
                        {
                            FIXRelatedSymGroup group = request.GetRelatedSymGroup(i);

                            //通过订阅的方式,由平台传入合约对象,在行情接收处将要使用到合约
                            CZQThostFtdcDepthMarketDataField DepthMarket;
                            Instrument inst = InstrumentManager.Instruments[group.Symbol];
                            string altSymbol = inst.GetSymbol(this.Name);
                            string altExchange = inst.GetSecurityExchange(this.Name);

                            if (!_dictDepthMarketData.TryGetValue(altSymbol, out DepthMarket))
                            {
                                DepthMarket = new CZQThostFtdcDepthMarketDataField();
                                _dictDepthMarketData.Add(altSymbol, DepthMarket);
                            }

                            _dictAltSymbol2Instrument[altSymbol] = inst;
                            Console.WriteLine("MdApi:订阅合约 {0} {1}",altSymbol,altExchange);
                            MdApi.MD_Subscribe(m_pMdApi, altSymbol, altExchange);

                        }
                        if (!_bTdConnected)
                        {
                            EmitError(-1, -1, "交易服务器没有连接,无法保证持仓真实");
                            return;
                        }
                        TraderApi.TD_ReqQryInvestorPosition(m_pTdApi, null);
                        timerPonstion.Enabled = false;
                        timerPonstion.Enabled = true;
                        break;
                    case DataManager.MARKET_DATA_UNSUBSCRIBE:
                        if (!_bMdConnected)
                        {
                            EmitError(-1, -1, "行情服务器没有连接,退订合约无效");
                            return;
                        }
                        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);

                            _dictDepthMarketData.Remove(altSymbol);

                            Console.WriteLine("MdApi:取消订阅 {0} {1}", altSymbol,altExchange);
                            MdApi.MD_Unsubscribe(m_pMdApi, altSymbol,altExchange);
                        }
                        break;
                    default:
                        throw new ArgumentException("Unknown subscription type: " + request.SubscriptionRequestType.ToString());
                }
            }
        }
Exemplo n.º 15
0
        public void SendMarketDataRequest(FIXMarketDataRequest request)
        {
            lock (this)
            {
                switch (request.SubscriptionRequestType)
                {
                case DataManager.MARKET_DATA_SUBSCRIBE:
                    if (!_bMdConnected)
                    {
                        EmitError(-1, -1, "行情服务器没有连接,无法订阅行情");
                        return;
                    }
                    for (int i = 0; i < request.NoRelatedSym; ++i)
                    {
                        FIXRelatedSymGroup group = request.GetRelatedSymGroup(i);

                        //通过订阅的方式,由平台传入合约对象,在行情接收处将要使用到合约
                        CThostFtdcDepthMarketDataField DepthMarket;
                        Instrument inst      = InstrumentManager.Instruments[group.Symbol];
                        string     altSymbol = inst.GetSymbol(this.Name);

                        if (!_dictDepthMarketData.TryGetValue(altSymbol, out DepthMarket))
                        {
                            DepthMarket = new CThostFtdcDepthMarketDataField();
                            _dictDepthMarketData.Add(altSymbol, DepthMarket);
                        }

                        _dictAltSymbol2Instrument[altSymbol] = inst;

                        MdApi.MD_Subscribe(m_pMdApi, altSymbol);
                    }
                    if (!_bTdConnected)
                    {
                        EmitError(-1, -1, "交易服务器没有连接,无法保证持仓真实");
                        return;
                    }
                    TraderApi.TD_ReqQryInvestorPosition(m_pTdApi, null);
                    timerPonstion.Enabled = false;
                    timerPonstion.Enabled = true;
                    break;

                case DataManager.MARKET_DATA_UNSUBSCRIBE:
                    if (!_bMdConnected)
                    {
                        EmitError(-1, -1, "行情服务器没有连接,退订合约无效");
                        return;
                    }
                    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);

                        _dictDepthMarketData.Remove(altSymbol);

                        MdApi.MD_Unsubscribe(m_pMdApi, altSymbol);
                    }
                    break;

                default:
                    throw new ArgumentException("Unknown subscription type: " + request.SubscriptionRequestType.ToString());
                }
            }
        }
Exemplo n.º 16
0
		public void SendMarketDataRequest(FIXMarketDataRequest request)
		{
			SubscriptionDataType subscriptionDataType = (SubscriptionDataType)0;
			for (int i = 0; i < request.NoMDEntryTypes; i++)
			{
				FIXMDEntryTypesGroup mDEntryTypesGroup = request.GetMDEntryTypesGroup(i);
				switch (mDEntryTypesGroup.MDEntryType)
				{
				case '0':
				case '1':
					if (request.MarketDepth == 1)
					{
						subscriptionDataType |= SubscriptionDataType.Quotes;
					}
					else
					{
						subscriptionDataType |= SubscriptionDataType.OrderBook;
					}
					break;
				case '2':
					subscriptionDataType |= SubscriptionDataType.Trades;
					break;
				}
			}
			for (int j = 0; j < request.NoRelatedSym; j++)
			{
				FIXRelatedSymGroup relatedSymGroup = request.GetRelatedSymGroup(j);
				SmartQuant.Instruments.Instrument key = SmartQuant.Instruments.InstrumentManager.Instruments[relatedSymGroup.Symbol];
				global::OpenQuant.API.Instrument instrument = Map.SQ_OQ_Instrument[key] as global::OpenQuant.API.Instrument;
				switch (request.SubscriptionRequestType)
				{
				case '1':
					this.provider.CallSubscribe(instrument, subscriptionDataType);
					break;
				case '2':
					this.provider.CallUnsubscribe(instrument, subscriptionDataType);
					break;
				default:
					throw new Exception("Unknown subscription request type " + request.SubscriptionRequestType);
				}
			}
		}
Exemplo n.º 17
0
        public void SendMarketDataRequest(FIXMarketDataRequest request)
        {
            // need to request as iqfeed's native symbol type, but return as a generic symbol

            FIXRelatedSymGroup      symgrp;
            IQFeedDataRequestRecord rr;

            bool tradeRequest       = false;
            bool quoteRequest       = false;
            bool marketDepthRequest = false;

            if (request.NoMDEntryTypes > 0)
            {
                FIXMDEntryTypesGroup mdEntryTypesGroup = request.GetMDEntryTypesGroup(0);

                switch (mdEntryTypesGroup.MDEntryType)
                {
                case FIXMDEntryType.Trade: {
                    tradeRequest = true;
                }
                break;

                case FIXMDEntryType.Bid:
                case FIXMDEntryType.Offer: {
                    if (request.MarketDepth == 1)
                    {
                        quoteRequest = true;
                    }
                    else
                    {
                        marketDepthRequest = true;
                    }
                }
                break;
                }
            }

            switch (request.SubscriptionRequestType)
            {
            case DataManager.MARKET_DATA_SUBSCRIBE:
                for (int i = 0; i < request.NoRelatedSym; i++)
                {
                    symgrp = request.GetRelatedSymGroup(i);

                    string     sWatchedSymbol = symgrp.Symbol;
                    Instrument instrument     = InstrumentManager.Instruments[symgrp.Symbol];

                    foreach (FIXSecurityAltIDGroup grp in symgrp.SecurityAltIDGroup)
                    {
                        if (Name == grp.SecurityAltIDSource)
                        {
                            sWatchedSymbol = grp.SecurityAltID;
                        }
                    }

                    if (tradeRequest || quoteRequest)
                    {
                        if (htL1WatchedSymbols.ContainsKey(sWatchedSymbol))
                        {
                            rr = htL1WatchedSymbols[sWatchedSymbol] as IQFeedDataRequestRecord;
                            rr.cnt++;
                            rr = null;
                        }
                        else
                        {
                            rr            = new IQFeedDataRequestRecord();
                            rr.request    = request;
                            rr.instrument = instrument;
                            // Symbol		= instrument.GetSymbol(Name); <== hint for other code

                            rr.sCurrency         = symgrp.Currency;
                            rr.sSecurityType     = symgrp.SecurityType;
                            rr.sSecurityExchange = symgrp.SecurityExchange;

                            htL1WatchedSymbols.Add(sWatchedSymbol, rr);
                            Console.WriteLine("MARKET_DATA_SUBSCRIBE {0}", sWatchedSymbol);
                            if (1 == htL1WatchedSymbols.Count)
                            {
                                iqf.HandleFundamentalMessage += new FundamentalMessageHandler(EmitFundamental);
                                iqf.HandleSummaryMessage     += new SummaryMessageHandler(EmitTradeSummary);
                                iqf.HandleUpdateMessage      += new UpdateMessageHandler(EmitQuoteTrade);
                            }
                            iqf.startWatch(sWatchedSymbol);
                            rr = null;
                        }
                    }

                    if (marketDepthRequest)
                    {
                        if (htL2WatchedSymbols.ContainsKey(sWatchedSymbol))
                        {
                            rr = htL1WatchedSymbols[sWatchedSymbol] as IQFeedDataRequestRecord;
                            rr.cnt++;
                            rr = null;
                        }
                        else
                        {
                            instrument.OrderBook.Clear();

                            rr            = new IQFeedDataRequestRecord();
                            rr.request    = request;
                            rr.instrument = instrument;
                            // Symbol		= instrument.GetSymbol(Name); <== hint for other code

                            rr.sCurrency         = symgrp.Currency;
                            rr.sSecurityType     = symgrp.SecurityType;
                            rr.sSecurityExchange = symgrp.SecurityExchange;

                            htL2WatchedSymbols.Add(sWatchedSymbol, rr);
                            Console.WriteLine("MARKETDEPTH_DATA_SUBSCRIBE {0}", sWatchedSymbol);
                            iqfl2.StartWatch(sWatchedSymbol, new LevelIIUpdateMessageHandler(EmitMarketDepth));
                            rr = null;
                        }
                    }
                }
                break;

            case DataManager.MARKET_DATA_UNSUBSCRIBE:
                for (int i = 0; i < request.NoRelatedSym; i++)
                {
                    symgrp = request.GetRelatedSymGroup(i);

                    string     sWatchedSymbol = symgrp.Symbol;
                    Instrument instrument     = InstrumentManager.Instruments[symgrp.Symbol];

                    foreach (FIXSecurityAltIDGroup grp in symgrp.SecurityAltIDGroup)
                    {
                        if (Name == grp.SecurityAltIDSource)
                        {
                            sWatchedSymbol = grp.SecurityAltID;
                        }
                    }

                    if (tradeRequest || quoteRequest)
                    {
                        if (htL1WatchedSymbols.ContainsKey(sWatchedSymbol))
                        {
                            rr = htL1WatchedSymbols[sWatchedSymbol] as IQFeedDataRequestRecord;
                            rr.cnt--;
                            if (0 == rr.cnt)
                            {
                                Console.WriteLine("MARKET_DATA_UNSUBSCRIBE {0}", sWatchedSymbol);
                                iqf.stopWatch(sWatchedSymbol);
                                if (0 == htL1WatchedSymbols.Count)
                                {
                                    iqf.HandleFundamentalMessage -= new FundamentalMessageHandler(EmitFundamental);
                                    iqf.HandleSummaryMessage     -= new SummaryMessageHandler(EmitTradeSummary);
                                    iqf.HandleUpdateMessage      -= new UpdateMessageHandler(EmitQuoteTrade);
                                }

                                rr.request    = null;
                                rr.instrument = null;
                            }
                            rr = null;
                        }
                        else
                        {
                            throw new ArgumentException("No to stop l1 for symbol " + symgrp.Symbol + "/" + sWatchedSymbol);
                        }
                    }

                    if (marketDepthRequest)
                    {
                        if (htL2WatchedSymbols.ContainsKey(sWatchedSymbol))
                        {
                            rr = htL2WatchedSymbols[sWatchedSymbol] as IQFeedDataRequestRecord;
                            rr.cnt--;
                            if (0 == rr.cnt)
                            {
                                Console.WriteLine("MARKETDEPTH_DATA_UNSUBSCRIBE {0}", sWatchedSymbol);
                                iqfl2.StopWatch(sWatchedSymbol, new LevelIIUpdateMessageHandler(EmitMarketDepth));

                                rr.request    = null;
                                rr.instrument = null;
                            }
                            rr = null;
                        }
                        else
                        {
                            throw new ArgumentException("No to stop l2 for symbol " + symgrp.Symbol + "/" + sWatchedSymbol);
                        }
                    }
                }
                break;

            default:
                throw new ArgumentException("Unknown subscription type: " + request.SubscriptionRequestType.ToString());
            }
        }
        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 FIXMDEntryType.Bid:
                    case FIXMDEntryType.Offer:
                        if (request.MarketDepth != 1)
                        {
                            bMarketDepth = true;
                            break;
                        }
                        bQuote = true;
                        break;
                    case FIXMDEntryType.Trade:
                        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);
                    string apiSymbol = GetApiSymbol(altSymbol);
                    string apiExchange = altExchange;
#if CTPZQ
                    altSymbol = GetYahooSymbol(apiSymbol, apiExchange);
#endif
                    CThostFtdcInstrumentField _Instrument;
                    if (_dictInstruments.TryGetValue(altSymbol, out _Instrument))
                    {
                        apiSymbol = _Instrument.InstrumentID;
                        apiExchange = _Instrument.ExchangeID;
                    }

#if CTPZQ
                    altSymbol = GetYahooSymbol(apiSymbol, apiExchange);
#endif
                    DataRecord record;
                    if (!_dictAltSymbol2Instrument.TryGetValue(altSymbol, out record))
                    {
                        record = new DataRecord();
                        record.Instrument = inst;
                        record.Symbol = apiSymbol;
                        record.Exchange = apiExchange;
                        _dictAltSymbol2Instrument[altSymbol] = record;

                        mdlog.Info("订阅合约/订阅询价 {0} {1} {2}", altSymbol, record.Symbol, record.Exchange);

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

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

                    // 多次订阅也无所谓
                    MdApi.MD_Subscribe(m_pMdApi, record.Symbol, record.Exchange);
                    MdApi.MD_SubscribeQuote(m_pMdApi, record.Symbol, record.Exchange);

                    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} {2}", altSymbol, record.Symbol, record.Exchange);
                        MdApi.MD_Unsubscribe(m_pMdApi, record.Symbol, record.Exchange);
                        MdApi.MD_UnsubscribeQuote(m_pMdApi, record.Symbol, record.Exchange);
                    }
                    else
                    {
                        // 只要有一种类型说要订阅,就给订上
                        MdApi.MD_Subscribe(m_pMdApi, record.Symbol, record.Exchange);
                        MdApi.MD_SubscribeQuote(m_pMdApi, record.Symbol, record.Exchange);
                    }
                }
            }
        }
Exemplo n.º 19
0
        private static void DoFixRequest(IMarketDataProvider provider, Instrument instrument, MarketDataType type, char subCh, string suffix)
        {
            FIXMarketDataRequest request = new FIXMarketDataRequest();

            request.MDReqID = DataManager.GetRequestId();
            request.SubscriptionRequestType = subCh;
            switch (type)
            {
            case MarketDataType.Trade:
                request.AddGroup(new FIXMDEntryTypesGroup('2'));
                break;

            case MarketDataType.Quote:
                request.AddGroup(new FIXMDEntryTypesGroup('0'));
                request.AddGroup(new FIXMDEntryTypesGroup('1'));
                request.MarketDepth = 1;      // Top of Book
                break;

            case MarketDataType.MarketDepth:
                request.AddGroup(new FIXMDEntryTypesGroup('0'));
                request.AddGroup(new FIXMDEntryTypesGroup('1'));
                request.MarketDepth = 0;      // Full Book
                break;
            }
            if (!instrument.ContainsField(15))
            {
                instrument.Currency = Framework.Configuration.DefaultCurrency;
            }
            FIXRelatedSymGroup symGrp = new FIXRelatedSymGroup();

            request.AddGroup(symGrp);
            symGrp.Symbol            = instrument.Symbol;
            symGrp.SecurityType      = instrument.SecurityType;
            symGrp.SecurityExchange  = instrument.SecurityExchange;
            symGrp.Currency          = instrument.Currency;
            symGrp.SecurityID        = instrument.SecurityID;
            symGrp.SecurityIDSource  = instrument.SecurityIDSource;
            symGrp.MaturityDate      = instrument.MaturityDate;
            symGrp.MaturityMonthYear = instrument.MaturityMonthYear;
            symGrp.StrikePrice       = instrument.StrikePrice;
            symGrp.PutOrCall         = ((FIXInstrument)instrument).PutOrCall;
            foreach (FIXSecurityAltIDGroup group2 in instrument.SecurityAltIDGroup)
            {
                symGrp.AddGroup(group2);
            }
            symGrp.SetStringValue(10001, suffix);
            if (provider == ProviderManager.MarketDataSimulator)
            {
                provider.SendMarketDataRequest(request);
            }
            else
            {
                switch (subCh)
                {
                case MARKET_DATA_SUBSCRIBE:
                    bool flag1 = false;
                    lock (DataManager.providers)
                    {
                        Hashtable local_4 = DataManager.providers[provider] as Hashtable;
                        if (local_4 == null)
                        {
                            local_4 = new Hashtable();
                            DataManager.providers.Add(provider, local_4);
                        }
                        Hashtable local_5 = local_4[instrument] as Hashtable;
                        if (local_5 == null)
                        {
                            local_5 = new Hashtable();
                            local_4.Add(instrument, local_5);
                        }
                        RequestItem local_6 = local_5[type] as RequestItem;
                        if (local_6 == null)
                        {
                            local_6 = new RequestItem(request);
                            local_5.Add(type, local_6);
                            flag1 = true;
                        }
                        RequestItem temp_91 = local_6;
                        int         temp_94 = temp_91.GetRequestId() + 1;
                        temp_91.SetRequestId(temp_94);
                    }
                    if (!flag1)
                    {
                        break;
                    }
                    provider.SendMarketDataRequest(request);
                    break;

                case MARKET_DATA_UNSUBSCRIBE:
                    bool   canSend = false;
                    string msg     = null;
                    lock (DataManager.providers)
                    {
                        Hashtable local_10 = DataManager.providers[provider] as Hashtable;
                        if (local_10 != null)
                        {
                            Hashtable local_11 = local_10[instrument] as Hashtable;
                            if (local_11 != null)
                            {
                                RequestItem local_12 = local_11[type] as RequestItem;
                                if (local_12 != null)
                                {
                                    RequestItem temp_152 = local_12;
                                    int         temp_155 = temp_152.GetRequestId() - 1;
                                    temp_152.SetRequestId(temp_155);
                                    if (local_12.GetRequestId() == 0)
                                    {
                                        local_11.Remove(type);
                                        if (local_11.Count == 0)
                                        {
                                            local_10.Remove(instrument);
                                            if (local_10.Count == 0)
                                            {
                                                DataManager.providers.Remove(provider);
                                            }
                                        }
                                        canSend = true;
                                    }
                                }
                                else
                                {
                                    msg = "No this RequestItem";
                                }
                            }
                            else
                            {
                                msg = "No Request for this instrument";
                            }
                        }
                        else
                        {
                            msg = "No Request for this provider";
                        }
                    }
                    if (msg != null)
                    {
                        DataManager.LogRequestMessage(provider, instrument, type, msg);
                    }
                    if (!canSend)
                    {
                        break;
                    }
                    provider.SendMarketDataRequest(request);
                    break;
                }
            }
        }
        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;
                        }
                    }

                    //记录行情,同时对用户合约与交易所合约进行映射
                    CThostFtdcDepthMarketDataField 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 FIXMDEntryType.Bid:
                    case FIXMDEntryType.Offer:
                        if (request.MarketDepth != 1)
                        {
                            bMarketDepth = true;
                            break;
                        }
                        bQuote = true;
                        break;
                    case FIXMDEntryType.Trade:
                        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);
                    string MarketStockCode = altExchange.ToLower() + altSymbol;

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

                        mdlog.Info("订阅合约 {0} {1} {2}", MarketStockCode, record.Symbol, record.Exchange);
                    }

                    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);
                    string MarketStockCode = altExchange.ToLower() + altSymbol;

                    DataRecord record;
                    if (!_dictAltSymbol2Instrument.TryGetValue(MarketStockCode, 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)
                    {
                        _dictAltSymbol2Instrument.Remove(MarketStockCode);
                        mdlog.Info("取消合约 {0} {1} {2}", MarketStockCode, record.Symbol, record.Exchange);
                    }
                }
            }
        }
Exemplo n.º 22
0
 internal RequestItem(FIXMarketDataRequest request)
 {
     this.request = request;
     this.id      = 0;
 }
Exemplo n.º 23
0
        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 FIXMDEntryType.Bid:
                case FIXMDEntryType.Offer:
                    if (request.MarketDepth != 1)
                    {
                        bMarketDepth = true;
                        break;
                    }
                    bQuote = true;
                    break;

                case FIXMDEntryType.Trade:
                    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);
                    string MarketStockCode = altExchange.ToLower() + altSymbol;

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

                        mdlog.Info("订阅合约 {0} {1} {2}", MarketStockCode, record.Symbol, record.Exchange);
                    }

                    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);
                    string MarketStockCode = altExchange.ToLower() + altSymbol;

                    DataRecord record;
                    if (!_dictAltSymbol2Instrument.TryGetValue(MarketStockCode, 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)
                    {
                        _dictAltSymbol2Instrument.Remove(MarketStockCode);
                        mdlog.Info("取消合约 {0} {1} {2}", MarketStockCode, record.Symbol, record.Exchange);
                    }
                }
            }
        }