// // ***************************************************************** // **** Request Instruments() **** // ***************************************************************** /// <summary> /// There may be more than one instrument associated with a product (such as with /// future instruments with differing expirations), request all information about a specific product family. /// </summary> /// <param name="product">The product family to request all instruments for.</param> public virtual bool RequestInstruments(Product product) { MarketHubRequest request = GetRequest(MarketHubRequest.RequestType.RequestInstruments); request.Data.Add(product); return(this.HubEventEnqueue(request)); }
public virtual bool RequestInstrumentSubscription(InstrumentName instrument) { MarketHubRequest request = GetRequest(MarketHubRequest.RequestType.RequestInstrumentSubscription); request.Data.Add(instrument); return(this.HubEventEnqueue(request)); }
// // // **************************************************************** // **** Request Products() *** // **************************************************************** /// <summary> /// Request info about the provided products. /// </summary> public virtual bool RequestProducts(List <Product> productList) { MarketHubRequest request = GetRequest(MarketHubRequest.RequestType.RequestProducts); request.Data.Add(productList); return(this.HubEventEnqueue(request)); }
}//TryCreateNewBook() // // // ************************************************************* // **** GetRequest() **** // ************************************************************* /// <summary> /// This utility method uses the RequestFactory for request to create /// and clear a request for new use. /// </summary> /// <param name="request"></param> /// <returns></returns> protected MarketHubRequest GetRequest(MarketHubRequest.RequestType request) { MarketHubRequest eventArg = m_RequestFactory.Get(); eventArg.Request = request; eventArg.Data.Clear(); return(eventArg); }//GetRequest()
/// <summary> /// Alternatively request all products with just an exchange name. /// </summary> public virtual bool RequestProducts(string mktServerName = "") { MarketHubRequest request = GetRequest(MarketHubRequest.RequestType.RequestProducts); if (!string.IsNullOrEmpty(mktServerName)) { request.Data.Add(mktServerName); } return(this.HubEventEnqueue(request)); }
} //ProcessHubRequestInstruments() // // // // ************************************************************************* // **** Process Hub Request Instruments() **** // ************************************************************************* private void ProcessHubRequestInstrumentPrice(Misty.Lib.MarketHubs.MarketHubRequest request) { if (request.Data == null || request.Data.Count < 1) { return; } foreach (object dataObj in request.Data) { Type dataType = dataObj.GetType(); if (dataType == typeof(InstrumentName)) { InstrumentName instr = (InstrumentName)dataObj; InstrumentDetails details; lock (m_InstrumentLock) { if (m_InstrumentDetails.TryGetValue(instr, out details)) { // found desired instrument. if (m_InstrumentMarkets.ContainsKey(instr)) { // We have already subscribed to this instrument. Log.NewEntry(LogLevel.Minor, "ProcessHubRequestInstrumentPrice: We already have a subscription to {0}. Ignore request {1}.", instr.SeriesName, request.ToString()); } else { // We do not have a subscription to this instrument. TryCreateNewBook(instr); // m_InstrumentDetails[instr].Key.MarketKey.Name); m_PriceListener.SubscribeTo(details.Key, new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket)); } } else { // The user has not previously request info about this Product family. //Log.NewEntry(LogLevel.Warning, "ProcessHubRequestInstrumentPrice: Failed to locate TT version of {0} for request {1}.", instr.SeriesName, request.ToString()); } } } else if (dataType == typeof(InstrumentKey)) { InstrumentKey instrKey = (InstrumentKey)dataObj; lock (m_InstrumentLock) { bool isFoundInstrument = false; InstrumentName instrName = new MistyProds.InstrumentName(); foreach (InstrumentName i in m_InstrumentDetails.Keys) { if (m_InstrumentDetails[i].Key.Equals(instrKey)) { instrName = i; isFoundInstrument = true; break; } } if (!isFoundInstrument) { // Unknown instrument. Log.NewEntry(LogLevel.Warning, "ProcessHubRequestInstrumentPrice: Price subscription request with unknown instrKey = {0}", instrKey.ToString()); } else { // We actually know this instrument. if (!m_InstrumentMarkets.ContainsKey(instrName)) { TryCreateNewBook(instrName); //, m_InstrumentDetails[instrName].Key.MarketKey.Name); m_PriceListener.SubscribeTo(instrKey, new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket)); } } } } else { Log.NewEntry(LogLevel.Warning, "ProcessHubRequestInstrumentPrice: Failed to recognize data object {0} for request {1}.", dataType.Name, request.ToString()); } } //next data } // ProcessHubRequestInstrumentPrice()
}// ProcessHubRequestProducts(). // // // ************************************************************************* // **** Process Hub Request Instruments() **** // ************************************************************************* /// <summary> /// Process users request for a list of Misty Instruments associated with a collection /// of user-provided Misty Products. /// </summary> private void ProcessHubRequestInstruments(Misty.Lib.MarketHubs.MarketHubRequest request) { if (request.Data == null || request.Data.Count < 1) { return; } foreach (object o in request.Data) { Type dataType = o.GetType(); if (dataType == typeof(Misty.Lib.Products.Product)) { // User has provided a Product object. Misty.Lib.Products.Product mistyProduct = (Misty.Lib.Products.Product)o; Product ttProduct = null; lock (m_ProductMapLock) { ProductKey productKey; if (m_ProductMap.TryGetValue(mistyProduct, out productKey)) { ttProduct = m_Products[productKey]; } } if (ttProduct != null) { m_PriceListener.SubscribeTo(ttProduct); // we have this product in our lists. } else { // User has given us a one-off specific product. Log.NewEntry(LogLevel.Warning, "ProcessHubRequestInstruments: Failed to find Product {0}.", mistyProduct.ToString()); } } else if (dataType == typeof(InstrumentName)) { InstrumentName instrumentName = (InstrumentName)o; InstrumentDetails details; lock (m_InstrumentLock) { if (!m_InstrumentDetails.TryGetValue(instrumentName, out details)) { // Could not find desired instrument in our list of details. Try to request it. } } } else if (dataType == typeof(InstrumentKey)) { InstrumentKey instrKey = (InstrumentKey)o; lock (m_InstrumentLock) { bool isFound = false; foreach (InstrumentDetails detail in m_InstrumentDetails.Values) { if (detail.Key == instrKey) { isFound = true; break; } } if (!isFound) { m_PriceListener.SubscribeTo(instrKey); } } } else { Log.NewEntry(LogLevel.Warning, "ProcessHubRequestInstruments: Failed to recognize type of Data {0} in {1}.", dataType.Name, request.ToString()); } } //next data } //ProcessHubRequestInstruments()
}//HubEventHandler() // // // // // ************************************************************************* // **** Process Market Hub Requests() **** // ************************************************************************* /// <summary> /// This processes requests from the user. /// This is called by the hub thread. /// </summary> private void ProcessHubRequestProducts(Misty.Lib.MarketHubs.MarketHubRequest request) { Market market = null; IDictionary <MarketKey, Market> marketList = null; List <string> marketNameList = new List <string>(); // Collect all markets we are interested in. foreach (object o in request.Data) { string marketName = null; if (o is Misty.Lib.Products.Product) { marketName = ((Misty.Lib.Products.Product)o).ServerName; // user gave us product objects. } else if (o is string) { marketName = (string)o; // user gave us strings (which must be server names) } if (!string.IsNullOrEmpty(marketName) && !marketNameList.Contains(marketName)) { marketNameList.Add(marketName); } } marketList = m_TTService.session.MarketCatalog.Markets; // markets we know foreach (string marketName in marketNameList) // search for match of name to given by user. { market = null; foreach (Market mkt in marketList.Values) // search for mkt with correct name. { if (mkt.Name.Equals(marketName, StringComparison.CurrentCultureIgnoreCase)) { market = mkt; break; } } // if (market != null) { // We found a recognized market. ProductCatalogSubscription productCatalog = null; if (m_ProductCatalogSubscriptionList.TryGetValue(market, out productCatalog)) { // We have already subscribed to these products, so fire our current list of known products. // As more arrive we will fire another event. List <Misty.Lib.Products.Product> productList = new List <Misty.Lib.Products.Product>(); lock (m_ProductMapLock) { foreach (Misty.Lib.Products.Product prod in m_ProductMap.Keys) // search thru product list created during TT callbacks. { if (prod.ServerName.Equals(market.Name)) { productList.Add(prod); } } } OnMarketFoundResource(productList); // trigger event for subscribers } else { // Create new product catalog subscription for this market. productCatalog = market.CreateProductCatalogSubscription(m_TTService.m_Dispatcher); productCatalog.ProductsUpdated += new EventHandler <ProductCatalogUpdatedEventArgs>(ProductCatalog_Updated); productCatalog.Start(); m_ProductCatalogSubscriptionList.Add(market, productCatalog); Log.NewEntry(LogLevel.Minor, "ProcessMarketHubRequests: Created new ProductCatalog subscription service for {0}. Have {1} in total.", market.Name, m_ProductCatalogSubscriptionList.Count); } } else { Log.NewEntry(LogLevel.Error, "ProcessMarketHubRequests: Failed to find market {0}.", marketName); } } }// ProcessHubRequestProducts().