Пример #1
0
        private void MarketProcessorThreadStatusChanged(object sender, MarketProcessorThreadStatusChangedEventArgs e)
        {
            if (e.status == MarketProcessorThreadStatus.CLOSED)
            {
                if (LigniteEngineThreads.ContainsKey(e.senderID))
                {
                    var senderId = e.senderID;
                    var thread   = LigniteEngineThreads[senderId];

                    var beforeremove = LigniteEngineThreads.Count;
                    LigniteEngineThreads.Remove(senderId);

                    if (beforeremove <= LigniteEngineThreads.Count)
                    {
                        SendMessage("Thread " + senderId + " not removed from LigniteEngineThreads!");
                    }

                    if (thread.ThreadState == ThreadState.Running)
                    {
                        Thread.Sleep(5);
                        SendMessage("Thread " + senderId + " not terminated!");
                    }
                }
            }

            if (OnMarketProcessorThreadStatusChanged != null)
            {
                OnMarketProcessorThreadStatusChanged(null, e);
            }
        }
Пример #2
0
        private void StartMarketProcessorThread(int exchangeId, int marketId, StrategyLoadPatern strategy)
        {
            // Create the ID to use for this item
            var processId = String.Format("MARKET_PROCESSOR:{0}:{1}", exchangeId, marketId);

            if (LigniteEngineThreads.ContainsKey(processId))
            {
                return;
            }

            var market = new Market {
                exchangeId = exchangeId, marketId = marketId
            };

            // Make sure the requested strategy is complete, if not replace empty elements with the default config
            var defaultPatern = settings.GetDefaultStrategyLoadPatern();

            if (strategy.OnMarketLoadActions == null)
            {
                strategy.OnMarketLoadActions = defaultPatern.OnMarketLoadActions;
            }

            if (strategy.DataLoadPaterns.Default == null)
            {
                strategy.DataLoadPaterns.Default = defaultPatern.DataLoadPaterns.Default;
            }

            if (strategy.DataLoadPaterns.HasBets == null)
            {
                strategy.DataLoadPaterns.HasBets = defaultPatern.DataLoadPaterns.HasBets;
            }

            if (strategy.DataLoadPaterns.HasUnmatchedBets == null)
            {
                strategy.DataLoadPaterns.HasUnmatchedBets = defaultPatern.DataLoadPaterns.HasUnmatchedBets;
            }

            if (strategy.DataLoadPaterns.Inactive == null)
            {
                strategy.DataLoadPaterns.Inactive = defaultPatern.DataLoadPaterns.Inactive;
            }

            if (strategy.DataLoadPaterns.InPlay == null)
            {
                strategy.DataLoadPaterns.InPlay = defaultPatern.DataLoadPaterns.InPlay;
            }

            if (strategy.DataLoadPaterns.Suspended == null)
            {
                strategy.DataLoadPaterns.Suspended = defaultPatern.DataLoadPaterns.Suspended;
            }

            // Declare the MarketLoader class to be threaded
            var marketProcessor = new MarketProcessor(processId, market, strategy);

            // Create the thread and start it
            var marketProcessorThread = new Thread(marketProcessor.Start);

            marketProcessorThread.Start();

            // Now lets store the thread so that we can access it later
            LigniteEngineThreads.Add(processId, marketProcessorThread);

            // Notify the user
            SendMessage(String.Format("New market submitted for processing. ID = {0}", processId));
        }