Пример #1
0
        //
        //
        /// <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);
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        //
        //
        private void MarketTTAPI_MarketFoundServiceResource(object sender, EventArgs e)
        {
            FoundServiceEventArg foundServiceEventArg = (FoundServiceEventArg)e;

            if (foundServiceEventArg.FoundInstruments != null)
            {
                foreach (InstrumentName instrumentFromTT in foundServiceEventArg.FoundInstruments)
                {
                    if (!m_InstrumentPendingWriting.Contains(instrumentFromTT))
                    {
                        InstrumentInfoItem BREInstrumentInfoItem;
                        if (m_InstrumentExistInDatabase.Contains(instrumentFromTT))
                        {
                            BREInstrumentInfoItem = m_BREInstrumentInfoItems[instrumentFromTT];
                        }
                        else
                        {
                            BREInstrumentInfoItem = m_BREInstrumentInfoItem;
                            InstrumentDetails instrumentDetails;
                            if (m_Market.TryGetInstrumentDetails(instrumentFromTT, out instrumentDetails))
                            {
                                BREInstrumentInfoItem.LastTradeDate = instrumentDetails.ExpirationDate;
                                BREInstrumentInfoItem.Type          = instrumentDetails.Type;
                                string expiryCode;
                                if (!BRE.Lib.Utilities.QTMath.TryParseMMMYYToMonthCode(instrumentDetails.InstrumentName.SeriesName, out expiryCode))
                                {
                                    m_Log.NewEntry(LogLevel.Error, "Failed to parse instrument series name for instrument {0}.", instrumentFromTT);
                                    continue;
                                }
                                BREInstrumentInfoItem.Expiry = expiryCode;
                            }
                            else
                            {
                                m_Log.NewEntry(LogLevel.Error, "Failed to get instrument details for instrument {0}.", instrumentFromTT);
                                continue;
                            }
                            m_BREInstrumentInfoItems.Add(instrumentFromTT, BREInstrumentInfoItem);
                        }
                        BREInstrumentInfoItem.InstrumentNameTT = instrumentFromTT.FullName;

                        string instrumentNameDatabase;
                        string hedgeOptions;
                        if (QTMath.TryConvertInstrumentNameToInstrumentNameDatabase(instrumentFromTT, m_Log, out instrumentNameDatabase))
                        {
                            BREInstrumentInfoItem.InstrumentNameDatabase = instrumentNameDatabase;
                        }
                        else
                        {
                            m_Log.NewEntry(LogLevel.Error, "Instrument name database generated failed for instrument {0}.", instrumentFromTT);
                            continue;
                        }

                        if (m_HedgeOptionsWriter.TryWriteHedgeOptionsForInstrument(instrumentFromTT, out hedgeOptions))
                        {
                            BREInstrumentInfoItem.HedgeOptions = hedgeOptions;
                        }
                        else
                        {
                            m_Log.NewEntry(LogLevel.Error, "Hedge options generated failed for instrument {0}.", instrumentFromTT);
                            continue;
                        }

                        m_InstrumentPendingWriting.Add(instrumentFromTT);
                    }
                }
            }
            m_UIDispatcher.Invoke(
                new Action(() =>
            {
                this.buttonWrite.Enabled = true;
            })
                );
        }