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); } } }
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()); } }