}//TryCreateNewBook() // // // #endregion//Private Methods #region no Event Handlers // ***************************************************************** // **** Event Handlers **** // ***************************************************************** // // /// <summary> /// Called by the TTService object once the API has connected. /// </summary> /// <param name="sender"></param> /// <param name="eventArg"></param> private void TTService_ServiceStatusChanged(object sender, EventArgs eventArg) { TTServices.TTApiService.ServiceStatusChangeEventArgs ttServiceEvent = (TTServices.TTApiService.ServiceStatusChangeEventArgs)eventArg; if (ttServiceEvent.IsConnected) { if (m_OrderListener == null) // use this to recall whether we've already connected or not. { m_OrderListener = new OrderListener("OrderListener", this); m_OrderListener.Start(); } } }
} //HubEventHandler() // // // // ***************************************************** // **** Process Request() **** // ***************************************************** private void ProcessRequest(OrderHubRequest eventArg) { Log.NewEntry(LogLevel.Minor, "ProcessRequest: {0}", eventArg); switch (eventArg.Request) { case OrderHubRequest.RequestType.RequestConnect: // We automatically connect to the TT Api once we get the call back from it. break; case OrderHubRequest.RequestType.RequestCreateFillBook: if (eventArg.Data[0] is TT.InstrumentKey) { TT.InstrumentKey ttKey = (TT.InstrumentKey)eventArg.Data[0]; InstrumentName name; if (m_TTKey2Name.TryGetValue(ttKey, out name) && m_Books.ContainsKey(name)) { Log.NewEntry(LogLevel.Minor, "ProcessRequest: Already have book for {1}. Ignoring {0}.", eventArg, name); } else { OrderBookTT book; if (TryCreateNewBook(ttKey, out book)) { Log.NewEntry(LogLevel.Minor, "ProcessRequest: Create book succeeded {0}.", book); OrderBookEventArgs outgoingEventArg = new OrderBookEventArgs(this, book.m_InstrumentName, OrderBookEventArgs.EventTypes.CreatedBook); OnBookCreated(outgoingEventArg); // TODO: Load additional information needed for new book creation. // Push out waiting events. ConcurrentQueue <EventArgs> waitingTTOrders; while (m_TTEventsToProcess.TryRemove(ttKey, out waitingTTOrders)) // this should only execute once, but if new orders are added concurrently could execute more! { EventArgs eventArg1; while (waitingTTOrders.Count > 0) { if (waitingTTOrders.TryDequeue(out eventArg1)) { this.HubEventEnqueue(eventArg1); } else { break; } } } } else { Log.NewEntry(LogLevel.Minor, "ProcessRequest: Create book failed. Will try again."); m_WaitingRequests.Enqueue(eventArg); // Store this request } } } break; case OrderHubRequest.RequestType.RequestShutdown: if (m_OrderListener != null) { m_OrderListener.Dispose(); m_OrderListener = null; } base.Stop(); break; default: break; } // switch request } //ProcessRequest()