internal DataSeriesObject(IDataSeries series, DateTime dateTime1, DateTime dateTime2, EventQueue queue, DataProcessor processor) { this.series = series; eventQueue = queue; if (processor == null) { this.processor = new DataProcessor(); } else { this.processor = processor; } if (!(dateTime1 == DateTime.MinValue) && (dateTime1 >= series.DateTime1)) { index1 = series.GetIndex(dateTime1, SearchOption.Next); } else { index1 = 0L; } if (!(dateTime2 == DateTime.MaxValue) && (dateTime2 <= series.DateTime2)) { index2 = series.GetIndex(dateTime2); } else { index2 = series.Count - 1L; } current = index1; progressDelta = (int)Math.Ceiling(Count() / 100.0); progressCount = progressDelta; progressPercent = 0; }
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)); } } }
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")); }
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 OnQueueOpened(EventQueue queue) { this.DateTime = DateTime.MinValue; this.queue = queue; }
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)); } }
protected virtual void OnConnected() { if (this is IDataProvider) { this.dataQueue = new EventQueue(1, 0, 2, 25000); this.dataQueue.Enqueue(new OnQueueOpened()); this.dataQueue.name = this.name + " data queue"; this.framework.eventBus.dataPipe.Add(this.dataQueue); } if (this is IExecutionProvider) { this.executionQueue = new EventQueue(2, 0, 2, 25000); this.executionQueue.Enqueue(new OnQueueOpened()); this.executionQueue.name = this.name + " execution queue"; this.framework.eventBus.executionPipe.Add(this.executionQueue); } }
private void OpenInstrumentQueue() { if (this.instrumentQueue == null) { this.instrumentQueue = new EventQueue(0, 0, 2, 1000); this.instrumentQueue.name = this.name + " instrument queue"; this.instrumentQueue.Enqueue(new OnQueueOpened()); this.framework.eventBus.servicePipe.Add(this.instrumentQueue); } }
private void OpenHistoricalDataQueue() { if (this.historicalQueue == null) { this.historicalQueue = new EventQueue(0, 0, 2, 1000); this.historicalQueue.name = this.name + " historical queue"; this.historicalQueue.Enqueue(new OnQueueOpened()); this.framework.eventBus.servicePipe.Add(this.historicalQueue); } }
private void CloseInstrumentQueue() { if (this.instrumentQueue != null) { this.instrumentQueue.Enqueue(new OnQueueClosed()); this.instrumentQueue = null; } }
private void CloseHistoricalDataQueue() { if (this.historicalQueue != null) { this.historicalQueue.Enqueue(new OnQueueClosed()); this.historicalQueue = null; } }
protected virtual void OnDisconnected() { if (this is IDataProvider) { this.dataQueue.Enqueue(new OnQueueClosed()); this.dataQueue = null; } if (this is IExecutionProvider) { this.executionQueue.Enqueue(new OnQueueClosed()); this.executionQueue = null; } }
//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)); } }
public DataSeriesObject_bak(SubscribeInfo info, EventQueue queue) { EventQueue = queue; _info = info; Init(); }