// // /// <summary> /// Called by the executionListener thread to process an event on the queue. /// </summary> private void ProcessEvent() { if (m_isDisposing) { return; } EventArgs e; while (m_InQueue.TryDequeue(out e)) //remove from threadsafe queue { m_WorkQueue.Enqueue(e); // place on my current work stack } // // Process all events now // while (m_WorkQueue.Count > 0) { e = m_WorkQueue.Dequeue(); if (e is EngineEventArgs) { EngineEventArgs engEvent = (EngineEventArgs)e; if (engEvent.EngineID >= 0) { m_ExecContainer.EngineList[engEvent.EngineID].ProcessEvent(engEvent); if (engEvent.Status == EngineEventArgs.EventStatus.Confirm || engEvent.Status == EngineEventArgs.EventStatus.Failed) { m_EngineHub.OnEngineChanged(engEvent); } } if (engEvent.MsgType == EngineEventArgs.EventType.SyntheticOrder) { m_ExecContainer.IOrderEngine.ProcessEvent(e); } } else if (e is InstrumentChangeArgs) { // this is a market update. // 1. Fill Orders ( we should do this first) // 2. Update Internal Markets InstrumentChangeArgs instrChangeArgs = (InstrumentChangeArgs)e; m_MarketInstrumentIdChangedList.Clear(); // load ids for instruments we need to check. foreach (KeyValuePair <int, InstrumentChange> pair in instrChangeArgs.ChangedInstruments) { if (pair.Value.MarketDepthChanged[QTMath.BidSide].Contains(0) || pair.Value.MarketDepthChanged[QTMath.AskSide].Contains(0)) { m_MarketInstrumentIdChangedList.Add(pair.Value.InstrumentID); } } if (m_MarketInstrumentIdChangedList.Count > 0) { SimulateFills(m_MarketInstrumentIdChangedList); SimulateMarketUpdates(m_MarketInstrumentIdChangedList); } } else if (e is FoundServiceEventArg) { FoundServiceEventArg foundServiceEvent = (FoundServiceEventArg)e; if (foundServiceEvent.FoundInstruments != null && foundServiceEvent.FoundInstruments.Count != 0) { foreach (InstrumentName instrName in foundServiceEvent.FoundInstruments) { if (!m_ExecContainer.m_Markets.ContainsKey(instrName)) { UV.Lib.BookHubs.Market newMarket = UV.Lib.BookHubs.Market.Create(instrName); m_ExecContainer.m_Markets.Add(instrName, newMarket); } InstrumentDetails instrDetails; if (m_Market.TryGetInstrumentDetails(instrName, out instrDetails)) { ProcessInstrumentsFound(instrDetails); } } } } } }