Beispiel #1
0
        }//RequestStop()

        //
        //
        //
        //***********************************************
        // ****       RequestProductsToRecord()      ****
        //***********************************************
        //
        /// <summary>
        /// Threadsafe call to request products to recorded.
        ///
        /// Warning this need to be improved to take into account illiquid months!
        /// </summary>
        /// <param name="productRequest"></param>
        /// <returns></returns>
        public bool RequestProductsToRecord(ProductRequest productRequest)
        {
            DataHubRequest request = m_RequestFactory.Get();

            request.Request = RequestCode.RequestProductsToRecord;
            request.Data.Add(productRequest);
            return(this.HubEventEnqueue(request));
        }
Beispiel #2
0
        }//

        /// <summary>
        /// Overloaded version allows for data to be added.
        /// </summary>
        protected DataHubRequest GetRequest(RequestCode requestCode, object arg)
        {
            DataHubRequest request = m_RequestFactory.Get();

            request.Clear();
            if (arg != null)
            {
                request.Data.Add(arg);
            }
            request.Request = requestCode;
            return(request);
        }// GetRequest()
Beispiel #3
0
        //
        public bool RequestProductsToRecord(List <ProductRequest> productRequestList)
        {
            DataHubRequest request = m_RequestFactory.Get();

            request.Request = RequestCode.RequestProductsToRecord;
            foreach (ProductRequest productRequest in productRequestList)
            {
                request.Data.Add(productRequest);
                Log.NewEntry(LogLevel.Major, "Requesting New Product {0}", productRequest.Product.ProductName);
            }
            return(this.HubEventEnqueue(request));
        }
Beispiel #4
0
        //
        //
        #endregion//Constructors

        #region Hub Event Handler Overrides
        // *****************************************************************
        // ****                 Hub Event Handler                      ****
        // *****************************************************************
        //
        //
        //
        //
        // *******************************************************
        // ****                 HubEvent Handler              ****
        // *******************************************************
        protected override void HubEventHandler(EventArgs[] eventArgList)
        {
            foreach (EventArgs eventArg in eventArgList)
            {
                Type eArgType = eventArg.GetType();
                if (eArgType == typeof(DataHubRequest))
                {
                    DataHubRequest requestArg = (DataHubRequest)eventArg;
                    switch (requestArg.Request)
                    {
                    case RequestCode.ServiceStateChange:
                        // Process this!
                        break;

                    case RequestCode.Connect:
                        // Process this!
                        break;

                    case RequestCode.RequestProductsToRecord:
                        ProcessProductsToRecord(requestArg);
                        break;

                    default:
                        Log.NewEntry(LogLevel.Error, "HubEventHandler: DataHubRequest {0} not implemented", requestArg.ToString());
                        break;
                    }//switch(Request)
                    m_RequestFactory.Recycle(requestArg);
                }
                else if (eArgType == typeof(FoundServiceEventArg))
                {
                    ProcessFoundResources((FoundServiceEventArg)eventArg);
                }
                else if (eArgType == typeof(DatabaseWriterEventArgs))
                {
                    Log.NewEntry(LogLevel.Major, "Write Completed {0}", eArgType.ToString());
                }
                else if (eArgType == typeof(MarketStatusChangedEventArg))
                {
                    ProcessMarketStatusChangedEvent((MarketStatusChangedEventArg)eventArg);
                }
                else if (eArgType == typeof(DatabaseWriterHub.WriteStatusEventArgs))
                {
                    Log.NewEntry(LogLevel.Major, "Write Status {0}", eArgType.ToString());
                }
                else
                {   // unknown event.
                    Log.NewEntry(LogLevel.Error, "Unknown event type {0}", eArgType.ToString());
                }
            }
        }//end HubEvent
Beispiel #5
0
 //
 //
 // *********************************************************
 // ****            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