public void Attach(EventBus bus) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.name = "attached"; eventQueue.Enqueue(new OnQueueOpened()); bus.dataPipe.Add(eventQueue); this.attached[this.attached_count++] = eventQueue; }
protected override void OnConnected() { if (this.series.Count != 0) { foreach (DataSeries current in this.series) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.name = current.name; eventQueue.Enqueue(new OnQueueOpened()); this.framework.eventBus.dataPipe.Add(eventQueue); if (this.seriesObjects.Count == 0) { eventQueue.Enqueue(new OnSimulatorStart()); } this.seriesObjects.Add(new DataSeriesObject(current, this.dateTime1, this.dateTime2, eventQueue)); } } }
public void Attach(EventBus bus) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.name = "attached"; eventQueue.Enqueue(new OnQueueOpened()); bus.dataPipe.Add(eventQueue); this.attached[this.attached_count++] = eventQueue; }
void ThreadRun() { Console.WriteLine(string.Join(" ", DateTime.Now, _thread.Name, @"started")); if (!IsConnected) { Connect(); } EventQueue queue = new EventQueue(1, 0, 2, 10) { IsSynched = true }; queue.Enqueue(new OnQueueOpened(queue)); queue.Enqueue(new OnSimulatorStart(DateTime1, DateTime2, 0L)); queue.Enqueue(new OnQueueClosed(queue)); framework.EventBus.DataPipe.Add(queue); _isExiting = false; while (!_isExiting) { var currentNode = _dataSeries.First; SmartQuant.LinkedListNode<DataSeriesObject> prevNode = null; while (currentNode != null) { var serie = currentNode.Data; if (!serie.endOfSeries) { serie.Enqueue(); prevNode = currentNode; } else { if (prevNode == null) { _dataSeries.First = currentNode.Next; } else { prevNode.Next = currentNode.Next; } _dataSeries.Count--; serie.eventQueue.Enqueue(new OnQueueClosed(serie.eventQueue)); } currentNode = currentNode.Next; } } _isExiting = false; _isRunning = false; Console.WriteLine(string.Join(" ", DateTime.Now, _thread.Name, @"stopped")); }
protected override void OnConnected() { if (this.series.Count != 0) { foreach (DataSeries current in this.series) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.name = current.name; eventQueue.Enqueue(new OnQueueOpened()); this.framework.eventBus.dataPipe.Add(eventQueue); if (this.seriesObjects.Count == 0) { eventQueue.Enqueue(new OnSimulatorStart()); } this.seriesObjects.Add(new DataSeriesObject(current, this.dateTime1, this.dateTime2, eventQueue)); } } }
public Event Read() { if (this.synch) { DateTime t = DateTime.MaxValue; LinkedListNode <IEventQueue> linkedListNode = this.queues.First; LinkedListNode <IEventQueue> linkedListNode2 = null; LinkedListNode <IEventQueue> linkedListNode3 = null; while (linkedListNode != null) { Event @event = linkedListNode.Data.Peek(); if (@event.TypeId == 206) { if (linkedListNode2 == null) { this.queues.First = linkedListNode.Next; } else { linkedListNode2.Next = linkedListNode.Next; } this.queues.Count--; if (this.queues.Count == 0 && this.framework.Mode == FrameworkMode.Simulation && linkedListNode.Data.Name != "Simulator stop queue") { EventQueue eventQueue = new EventQueue(1, 0, 2, 10); eventQueue.name = "Simulator stop queue"; eventQueue.Enqueue(new OnQueueOpened()); eventQueue.Enqueue(new OnSimulatorStop()); eventQueue.Enqueue(new OnQueueClosed()); this.Add(eventQueue); } linkedListNode3 = linkedListNode; break; } DateTime dateTime = @event.dateTime; if (dateTime <= t) { linkedListNode3 = linkedListNode; t = dateTime; } linkedListNode2 = linkedListNode; linkedListNode = linkedListNode.Next; } return(linkedListNode3.Data.Read()); } LinkedListNode <IEventQueue> linkedListNode4 = this.queues.First; LinkedListNode <IEventQueue> linkedListNode5 = null; while (linkedListNode4 != null) { if (!linkedListNode4.Data.IsEmpty()) { Event event2 = linkedListNode4.Data.Read(); if (event2.TypeId == 206) { if (linkedListNode5 == null) { this.queues.First = linkedListNode4.Next; } else { linkedListNode5.Next = linkedListNode4.Next; } this.queues.Count--; } return(event2); } linkedListNode5 = linkedListNode4; linkedListNode4 = linkedListNode4.Next; } return(null); }
public Event Read() { if (this.synch) { DateTime t = DateTime.MaxValue; LinkedListNode<IEventQueue> linkedListNode = this.queues.First; LinkedListNode<IEventQueue> linkedListNode2 = null; LinkedListNode<IEventQueue> linkedListNode3 = null; while (linkedListNode != null) { Event @event = linkedListNode.Data.Peek(); if (@event.TypeId == 206) { if (linkedListNode2 == null) { this.queues.First = linkedListNode.Next; } else { linkedListNode2.Next = linkedListNode.Next; } this.queues.Count--; if (this.queues.Count == 0 && this.framework.Mode == FrameworkMode.Simulation && linkedListNode.Data.Name != "Simulator stop queue") { EventQueue eventQueue = new EventQueue(1, 0, 2, 10); eventQueue.name = "Simulator stop queue"; eventQueue.Enqueue(new OnQueueOpened()); eventQueue.Enqueue(new OnSimulatorStop()); eventQueue.Enqueue(new OnQueueClosed()); this.Add(eventQueue); } linkedListNode3 = linkedListNode; break; } DateTime dateTime = @event.dateTime; if (dateTime <= t) { linkedListNode3 = linkedListNode; t = dateTime; } linkedListNode2 = linkedListNode; linkedListNode = linkedListNode.Next; } return linkedListNode3.Data.Read(); } LinkedListNode<IEventQueue> linkedListNode4 = this.queues.First; LinkedListNode<IEventQueue> linkedListNode5 = null; while (linkedListNode4 != null) { if (!linkedListNode4.Data.IsEmpty()) { Event event2 = linkedListNode4.Data.Read(); if (event2.TypeId == 206) { if (linkedListNode5 == null) { this.queues.First = linkedListNode4.Next; } else { linkedListNode5.Next = linkedListNode4.Next; } this.queues.Count--; } return event2; } linkedListNode5 = linkedListNode4; linkedListNode4 = linkedListNode4.Next; } return null; }
private void Subscribe_(Instrument instrument, DateTime dateTime1, DateTime dateTime2) { if (this.series.Count != 0) { return; } Console.WriteLine(DateTime.Now + " DataSimulator::Subscribe " + instrument.symbol); DataSeries dataSeries = this.framework.DataManager.GetSeries(instrument, 4); if (dataSeries != null) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.name = instrument + " trade"; eventQueue.Enqueue(new OnQueueOpened()); this.framework.eventBus.dataPipe.Add(eventQueue); if (this.seriesObjects.Count == 0) { eventQueue.Enqueue(new OnSimulatorStart()); } this.seriesObjects.Add(new DataSeriesObject(dataSeries, dateTime1, dateTime2, eventQueue)); } dataSeries = this.framework.DataManager.GetSeries(instrument, 2); if (dataSeries != null) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.Enqueue(new OnQueueOpened()); eventQueue.name = instrument + " bid"; this.framework.eventBus.dataPipe.Add(eventQueue); this.seriesObjects.Add(new DataSeriesObject(dataSeries, dateTime1, dateTime2, eventQueue)); } dataSeries = this.framework.DataManager.GetSeries(instrument, 3); if (dataSeries != null) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.Enqueue(new OnQueueOpened()); eventQueue.name = instrument + " ask"; this.framework.eventBus.dataPipe.Add(eventQueue); this.seriesObjects.Add(new DataSeriesObject(dataSeries, dateTime1, dateTime2, eventQueue)); } dataSeries = this.framework.DataManager.GetSeries(instrument, 5); if (dataSeries != null) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.Enqueue(new OnQueueOpened()); eventQueue.name = instrument + " quote"; this.framework.eventBus.dataPipe.Add(eventQueue); this.seriesObjects.Add(new DataSeriesObject(dataSeries, dateTime1, dateTime2, eventQueue)); } dataSeries = this.framework.DataManager.GetSeries(instrument, 6); if (dataSeries != null) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.Enqueue(new OnQueueOpened()); eventQueue.name = instrument + " bar"; this.framework.eventBus.dataPipe.Add(eventQueue); this.seriesObjects.Add(new DataSeriesObject(dataSeries, dateTime1, dateTime2, eventQueue)); } dataSeries = this.framework.DataManager.GetSeries(instrument, 7); if (dataSeries != null) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.Enqueue(new OnQueueOpened()); eventQueue.name = instrument + " level2"; this.framework.eventBus.dataPipe.Add(eventQueue); this.seriesObjects.Add(new DataSeriesObject(dataSeries, dateTime1, dateTime2, eventQueue)); } dataSeries = this.framework.DataManager.GetSeries(instrument, 22); if (dataSeries != null) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.Enqueue(new OnQueueOpened()); eventQueue.name = instrument + " fundamental"; this.framework.eventBus.dataPipe.Add(eventQueue); this.seriesObjects.Add(new DataSeriesObject(dataSeries, dateTime1, dateTime2, eventQueue)); } dataSeries = this.framework.DataManager.GetSeries(instrument, 23); if (dataSeries != null) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.Enqueue(new OnQueueOpened()); eventQueue.name = instrument + " news"; this.framework.eventBus.dataPipe.Add(eventQueue); this.seriesObjects.Add(new DataSeriesObject(dataSeries, dateTime1, dateTime2, eventQueue)); } }
private void Subscribe_(Instrument instrument, DateTime dateTime1, DateTime dateTime2) { if (this.series.Count != 0) { return; } Console.WriteLine(DateTime.Now + " DataSimulator::Subscribe " + instrument.symbol); DataSeries dataSeries = this.framework.DataManager.GetSeries(instrument, 4); if (dataSeries != null) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.name = instrument + " trade"; eventQueue.Enqueue(new OnQueueOpened()); this.framework.eventBus.dataPipe.Add(eventQueue); if (this.seriesObjects.Count == 0) { eventQueue.Enqueue(new OnSimulatorStart()); } this.seriesObjects.Add(new DataSeriesObject(dataSeries, dateTime1, dateTime2, eventQueue)); } dataSeries = this.framework.DataManager.GetSeries(instrument, 2); if (dataSeries != null) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.Enqueue(new OnQueueOpened()); eventQueue.name = instrument + " bid"; this.framework.eventBus.dataPipe.Add(eventQueue); this.seriesObjects.Add(new DataSeriesObject(dataSeries, dateTime1, dateTime2, eventQueue)); } dataSeries = this.framework.DataManager.GetSeries(instrument, 3); if (dataSeries != null) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.Enqueue(new OnQueueOpened()); eventQueue.name = instrument + " ask"; this.framework.eventBus.dataPipe.Add(eventQueue); this.seriesObjects.Add(new DataSeriesObject(dataSeries, dateTime1, dateTime2, eventQueue)); } dataSeries = this.framework.DataManager.GetSeries(instrument, 5); if (dataSeries != null) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.Enqueue(new OnQueueOpened()); eventQueue.name = instrument + " quote"; this.framework.eventBus.dataPipe.Add(eventQueue); this.seriesObjects.Add(new DataSeriesObject(dataSeries, dateTime1, dateTime2, eventQueue)); } dataSeries = this.framework.DataManager.GetSeries(instrument, 6); if (dataSeries != null) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.Enqueue(new OnQueueOpened()); eventQueue.name = instrument + " bar"; this.framework.eventBus.dataPipe.Add(eventQueue); this.seriesObjects.Add(new DataSeriesObject(dataSeries, dateTime1, dateTime2, eventQueue)); } dataSeries = this.framework.DataManager.GetSeries(instrument, 7); if (dataSeries != null) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.Enqueue(new OnQueueOpened()); eventQueue.name = instrument + " level2"; this.framework.eventBus.dataPipe.Add(eventQueue); this.seriesObjects.Add(new DataSeriesObject(dataSeries, dateTime1, dateTime2, eventQueue)); } dataSeries = this.framework.DataManager.GetSeries(instrument, 22); if (dataSeries != null) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.Enqueue(new OnQueueOpened()); eventQueue.name = instrument + " fundamental"; this.framework.eventBus.dataPipe.Add(eventQueue); this.seriesObjects.Add(new DataSeriesObject(dataSeries, dateTime1, dateTime2, eventQueue)); } dataSeries = this.framework.DataManager.GetSeries(instrument, 23); if (dataSeries != null) { EventQueue eventQueue = new EventQueue(1, 0, 2, 25000); eventQueue.Enqueue(new OnQueueOpened()); eventQueue.name = instrument + " news"; this.framework.eventBus.dataPipe.Add(eventQueue); this.seriesObjects.Add(new DataSeriesObject(dataSeries, dateTime1, dateTime2, eventQueue)); } }
//void Subscribe(Instrument instrument, DateTime dateTime1, DateTime dateTime2) //{ // Console.WriteLine("{0} {1}::Subscribe {2}", DateTime.Now, this.Name, instrument.Symbol); // var info = new SubscribeInfo(); // info.DatePath = Path.Combine(DataPath, instrument.Symbol); // info.DateTime1 = dateTime1; // info.DateTime2 = dateTime2; // info.InstrumentId = instrument.Id; // info.SubscribeBidAsk = SubscribeBid && SubscribeAsk; // info.SubscribeTrade = SubscribeTrade; // var queue = new EventQueue(1, 0, 2, 0x61a8) { // IsSynched = true // }; // queue.Enqueue(new OnQueueOpened(queue)); // framework.EventBus.DataPipe.Add(queue); // _dataSeries.Add(new DataSeriesObject(info, queue)); //} void Subscribe(Instrument instrument, DateTime dateTime1, DateTime dateTime2) { Console.WriteLine("{0} {1}::Subscribe {2}", DateTime.Now, this.Name, instrument.Symbol); // 在这里一开始就加载完,需要一点时间,后期考虑将数据与回测结合起来使用 ProtobufDataZeroReader reader = new ProtobufDataZeroReader(); reader.DataPath_Instrument = DataPath_Instrument; reader.DataPath_Realtime = DataPath_Realtime; reader.SubscribeExternData = SubscribeExternData; reader.SubscribeAsk = SubscribeAsk; reader.SubscribeBid = SubscribeBid; reader.GetDataSeries(instrument, dateTime1, dateTime2); IDataSeries Trades = null; IDataSeries Bids = null; IDataSeries Asks = null; if(SubscribeTrade || SubscribeBid || SubscribeAsk) { reader.OutputSeries(out Trades, out Bids, out Asks); } if (SubscribeTrade && Trades != null && Trades.Count > 0) { var queue = new EventQueue(1, 0, 2, 0x61a8) { IsSynched = true }; queue.Enqueue(new OnQueueOpened(queue)); framework.EventBus.DataPipe.Add(queue); _dataSeries.Add(new DataSeriesObject(Trades, dateTime1, dateTime2, queue, this.Processor)); } if (SubscribeBid && Bids != null && Bids.Count > 0) { var queue = new EventQueue(1, 0, 2, 0x61a8) { IsSynched = true }; queue.Enqueue(new OnQueueOpened(queue)); framework.EventBus.DataPipe.Add(queue); _dataSeries.Add(new DataSeriesObject(Bids, dateTime1, dateTime2, queue, this.Processor)); } if (SubscribeAsk && Asks != null && Asks.Count > 0) { var queue = new EventQueue(1, 0, 2, 0x61a8) { IsSynched = true }; queue.Enqueue(new OnQueueOpened(queue)); framework.EventBus.DataPipe.Add(queue); _dataSeries.Add(new DataSeriesObject(Asks, dateTime1, dateTime2, queue, this.Processor)); } }