// // // ********************************************************* // **** ProcessProductsToRecord() **** // ********************************************************* /// <summary> /// Called by the hub thread to deal with requests for products to record. If more instruments are /// requested at a later time this should handle it correctly, however this functionality is largely untested. /// </summary> /// <param name="requestArg"></param> private void ProcessProductsToRecord(DataHubRequest requestArg) { foreach (object o in requestArg.Data) { ProductRequest prodRequest = (ProductRequest)o; if (!m_ProductRequestList.Contains(prodRequest)) { // we have never seen this exact request if (!m_ProductsRequested.Contains(prodRequest.Product)) { // we have also never requested this product! m_ProductsRequested.Add(prodRequest.Product); m_ProductRequestList.Add(prodRequest); // add it m_Market.RequestProducts(prodRequest.Product); // request it } else { // we have request this product previously but may need to request more contracts now. foreach (ProductRequest completedRequest in m_ProductRequestList) { if (completedRequest.Product == prodRequest.Product && prodRequest.nInstrumentsToRecord > completedRequest.nInstrumentsToRecord) {// this is the same product and we want more contracts (if less we ignore it) List <InstrumentName> instrumentsInProduct; List <InstrumentDetails> instrumentDetailsList; m_InstrumentsByProduct.TryGetValue(prodRequest.Product, out instrumentsInProduct); // find all the instruments if (m_Market.TryGetInstrumentDetails(instrumentsInProduct, out instrumentDetailsList)) // get all the details { // we have instrument details to look at instrumentDetailsList.Sort((x, y) => x.ExpirationDate.CompareTo(y.ExpirationDate)); // sort list by expirations int noOfInstruments = Math.Min(prodRequest.nInstrumentsToRecord, instrumentDetailsList.Count); // if we are trying to subscribe to more contracts than exist! for (int i = completedRequest.nInstrumentsToRecord - 1; i < noOfInstruments; i++) { // for every instrument past what we already have, subscribe m_Market.RequestInstrumentPriceSubscription(instrumentDetailsList[i].InstrumentName); // subscribe to instrument //m_Market.RequestInstrumentTimeAndSalesSubscription(instrumentDetailsList[i].InstrumentName); m_InstrumentsRequested.Add(instrumentDetailsList[i].InstrumentName); // add it to our list of subscriptions. } // end i } } } } } } } // ProcessProductsToRecord