示例#1
0
        private void OnTrade(Event e)
        {
            DataEventCount++;
            var trade = (Trade)e;

            SyncLocalClockWithDataObject(trade);
            SyncExchangeClockWithTick(trade, nameof(OnTrade));
            BarFactory.OnData(trade);
            this.framework.DataManager.OnTrade(trade);
            this.framework.InstrumentManager.GetById(trade.InstrumentId).Trade = trade;
            this.framework.ProviderManager.ExecutionSimulator.OnTrade(trade);
            this.framework.StrategyManager.OnTrade(trade);
        }
示例#2
0
        private void OnAsk(Event e)
        {
            DataEventCount++;
            var ask = (Ask)e;

            SyncLocalClockWithDataObject(ask);
            SyncExchangeClockWithTick(ask, nameof(OnAsk));
            BarFactory.OnData(ask);
            this.framework.DataManager.OnAsk(ask);
            this.framework.InstrumentManager.GetById(ask.InstrumentId).Ask = ask;
            this.framework.ProviderManager.ExecutionSimulator.OnAsk(ask);
            this.framework.StrategyManager.OnAsk(ask);
        }
示例#3
0
        private void OnBid(Event e)
        {
            DataEventCount++;
            var bid = (Bid)e;

            SyncLocalClockWithDataObject(bid);
            SyncExchangeClockWithTick(bid, nameof(OnBid));
            BarFactory.OnData(bid);
            this.framework.DataManager.OnBid(bid);
            this.framework.InstrumentManager.GetById(bid.InstrumentId).Bid = bid;
            this.framework.ProviderManager.ExecutionSimulator.OnBid(bid);
            this.framework.StrategyManager.OnBid(bid);
        }
示例#4
0
        public EventManager(Framework framework, EventBus bus)
        {
            this.framework  = framework;
            this.bus        = bus;
            BarFactory      = new BarFactory(this.framework);
            BarSliceFactory = new BarSliceFactory(this.framework);
            Dispatcher      = new EventDispatcher(this.framework);

            // Event Gates
            this.gates[EventType.Bid]                      = OnBid;
            this.gates[EventType.Ask]                      = OnAsk;
            this.gates[EventType.Trade]                    = OnTrade;
            this.gates[EventType.Quote]                    = OnQuote;
            this.gates[EventType.Bar]                      = OnBar;
            this.gates[EventType.Level2Snapshot]           = OnLevel2Snapshot;
            this.gates[EventType.Level2Update]             = OnLevel2Update;
            this.gates[EventType.ExecutionReport]          = OnExecutionReport;
            this.gates[EventType.Reminder]                 = OnReminder;
            this.gates[EventType.Fundamental]              = OnFundamental;
            this.gates[EventType.News]                     = OnNews;
            this.gates[EventType.Group]                    = OnGroup;
            this.gates[EventType.GroupEvent]               = OnGroupEvent;
            this.gates[EventType.Command]                  = OnCommand;
            this.gates[EventType.OnPositionOpened]         = OnPositionOpened;
            this.gates[EventType.OnPositionClosed]         = OnPositionClosed;
            this.gates[EventType.OnPositionChanged]        = OnPositionChanged;
            this.gates[EventType.OnFill]                   = OnFill;
            this.gates[EventType.OnTransaction]            = OnTransaction;
            this.gates[EventType.OnSendOrder]              = OnSendOrder;
            this.gates[EventType.OnPendingNewOrder]        = OnPendingNewOrder;
            this.gates[EventType.OnNewOrder]               = OnNewOrder;
            this.gates[EventType.OnOrderStatusChanged]     = OnOrderStatusChanged;
            this.gates[EventType.OnOrderPartiallyFilled]   = OnOrderPartiallyFilled;
            this.gates[EventType.OnOrderFilled]            = OnOrderFilled;
            this.gates[EventType.OnOrderReplaced]          = OnOrderReplaced;
            this.gates[EventType.OnOrderCancelled]         = OnOrderCancelled;
            this.gates[EventType.OnOrderRejected]          = OnOrderRejected;
            this.gates[EventType.OnOrderExpired]           = OnOrderExpired;
            this.gates[EventType.OnOrderCancelRejected]    = OnOrderCancelRejected;
            this.gates[EventType.OnOrderReplaceRejected]   = OnOrderReplaceRejected;
            this.gates[EventType.OnOrderDone]              = OnOrderDone;
            this.gates[EventType.OnPortfolioAdded]         = OnPortfolioAdded;
            this.gates[EventType.OnPortfolioRemoved]       = OnPortfolioRemoved;
            this.gates[EventType.OnPortfolioParentChanged] = OnPortfolioParentChanged;
            this.gates[EventType.HistoricalData]           = OnHistoricalData;
            this.gates[EventType.HistoricalDataEnd]        = OnHistoricalDataEnd;
            this.gates[EventType.BarSlice]                 = OnBarSlice;
            this.gates[EventType.OnStrategyEvent]          = OnStrategyEvent;
            this.gates[EventType.AccountData]              = OnAccountData;
            this.gates[EventType.OnPropertyChanged]        = OnPropertyChanged;
            this.gates[EventType.OnException]              = OnException;
            this.gates[EventType.AccountReport]            = OnAccountReport;
            this.gates[EventType.ProviderError]            = OnProviderError;
            this.gates[EventType.OnProviderConnected]      = OnProviderConnected;
            this.gates[EventType.OnProviderDisconnected]   = OnProviderDisconnected;
            this.gates[EventType.OnSimulatorStart]         = OnSimulatorStart;
            this.gates[EventType.OnSimulatorStop]          = OnSimulatorStop;
            this.gates[EventType.OnSimulatorProgress]      = OnSimulatorProgress;

            // Enable all events by defaults
            for (int i = 0; i < byte.MaxValue; i++)
            {
                Enabled[i] = true;
            }

            if (bus != null)
            {
                this.thread = new Thread(Run)
                {
                    Name         = "Event Manager Thread",
                    IsBackground = true
                };
                this.thread.Start();
            }
        }
示例#5
0
 public void Clear()
 {
     EventCount = DataEventCount = 0;
     BarFactory.Clear();
     BarSliceFactory.Clear();
 }
示例#6
0
        public EventManager(Framework framework, EventBus bus)
        {
            this.framework = framework;
            this.bus = bus;
            BarFactory = new BarFactory(this.framework);
            BarSliceFactory = new BarSliceFactory(this.framework);
            Dispatcher = new EventDispatcher(this.framework);

            // Event Gates
            this.gates[EventType.Bid] = OnBid;
            this.gates[EventType.Ask] = OnAsk;
            this.gates[EventType.Trade] = OnTrade;
            this.gates[EventType.Quote] = OnQuote;
            this.gates[EventType.Bar] = OnBar;
            this.gates[EventType.Level2Snapshot] = OnLevel2Snapshot;
            this.gates[EventType.Level2Update] = OnLevel2Update;            
            this.gates[EventType.ExecutionReport] = OnExecutionReport;
            this.gates[EventType.Reminder] = OnReminder;
            this.gates[EventType.Fundamental] = OnFundamental;
            this.gates[EventType.News] = OnNews;
            this.gates[EventType.Group] = OnGroup;
            this.gates[EventType.GroupEvent] = OnGroupEvent;
            this.gates[EventType.Command] = OnCommand;
            this.gates[EventType.OnPositionOpened] = OnPositionOpened;
            this.gates[EventType.OnPositionClosed] = OnPositionClosed;
            this.gates[EventType.OnPositionChanged] = OnPositionChanged;
            this.gates[EventType.OnFill] = OnFill;
            this.gates[EventType.OnTransaction] = OnTransaction;
            this.gates[EventType.OnSendOrder] = OnSendOrder;
            this.gates[EventType.OnPendingNewOrder] = OnPendingNewOrder;
            this.gates[EventType.OnNewOrder] = OnNewOrder;
            this.gates[EventType.OnOrderStatusChanged] = OnOrderStatusChanged;
            this.gates[EventType.OnOrderPartiallyFilled] = OnOrderPartiallyFilled;
            this.gates[EventType.OnOrderFilled] = OnOrderFilled;
            this.gates[EventType.OnOrderReplaced] = OnOrderReplaced;
            this.gates[EventType.OnOrderCancelled] = OnOrderCancelled;
            this.gates[EventType.OnOrderRejected] = OnOrderRejected;
            this.gates[EventType.OnOrderExpired] = OnOrderExpired;
            this.gates[EventType.OnOrderCancelRejected] = OnOrderCancelRejected;
            this.gates[EventType.OnOrderReplaceRejected] = OnOrderReplaceRejected;
            this.gates[EventType.OnOrderDone] = OnOrderDone;
            this.gates[EventType.OnPortfolioAdded] = OnPortfolioAdded;
            this.gates[EventType.OnPortfolioRemoved] = OnPortfolioRemoved;
            this.gates[EventType.OnPortfolioParentChanged] = OnPortfolioParentChanged;
            this.gates[EventType.HistoricalData] = OnHistoricalData;
            this.gates[EventType.HistoricalDataEnd] = OnHistoricalDataEnd;
            this.gates[EventType.BarSlice] = OnBarSlice;
            this.gates[EventType.OnStrategyEvent] = OnStrategyEvent;
            this.gates[EventType.AccountData] = OnAccountData;
            this.gates[EventType.OnPropertyChanged] = OnPropertyChanged;
            this.gates[EventType.OnException] = OnException;
            this.gates[EventType.AccountReport] = OnAccountReport;
            this.gates[EventType.ProviderError] = OnProviderError;
            this.gates[EventType.OnProviderConnected] = OnProviderConnected;
            this.gates[EventType.OnProviderDisconnected] = OnProviderDisconnected;
            this.gates[EventType.OnSimulatorStart] = OnSimulatorStart;
            this.gates[EventType.OnSimulatorStop] = OnSimulatorStop;
            this.gates[EventType.OnSimulatorProgress] = OnSimulatorProgress;

            // Enable all events by defaults
            for (int i = 0; i < byte.MaxValue; i++)
                Enabled[i] = true;

            if (bus != null)
            {
                this.thread = new Thread(Run)
                {
                    Name = "Event Manager Thread",
                    IsBackground = true
                };
                this.thread.Start();
            }
        }