/// <summary>
        /// Pushes the tick into this enumerator. This tick will be aggregated into a quote bar
        /// and emitted after the alotted time has passed
        /// </summary>
        /// <param name="data">The new data to be aggregated</param>
        public void ProcessData(BaseData data)
        {
            QuoteBar working;

            var tick     = data as Tick;
            var qty      = tick == null ? 0 : tick.Quantity;
            var bidPrice = tick == null ? data.Value : tick.BidPrice;
            var askPrice = tick == null ? data.Value : tick.AskPrice;
            var bidSize  = tick == null ? 0m : tick.BidSize;
            var askSize  = tick == null ? 0m : tick.AskSize;

            if (!_queue.TryPeek(out working))
            {
                // the consumer took the working bar, or time ticked over into next bar
                var utcNow           = _timeProvider.GetUtcNow();
                var currentLocalTime = utcNow.ConvertFromUtc(_timeZone);
                var barStartTime     = currentLocalTime.RoundDown(_barSize);
                working = new QuoteBar();
                working.Update(data.Value, bidPrice, askPrice, qty, bidSize, askSize);
                working.Period = _barSize;
                working.Time   = barStartTime;
                working.Symbol = data.Symbol;
                _queue.Enqueue(working);

                if (_liveMode)
                {
                    _realTimeScheduleEventService.ScheduleEvent(_barSize.Subtract(currentLocalTime - barStartTime), utcNow);
                }
            }
            else
            {
                // we're still within this bar size's time
                working.Update(data.Value, bidPrice, askPrice, qty, bidSize, askSize);
            }
        }
Example #2
0
        public void Accuracy()
        {
            var          scheduledEventService = new RealTimeScheduleEventService(RealTimeProvider.Instance);
            EventHandler handler = (_, __) =>
            {
                Log.Trace($"{DateTime.UtcNow:O}");

                var now           = DateTime.UtcNow;
                var nextEventTime = now.RoundDown(TimeSpan.FromSeconds(1)).Add(TimeSpan.FromSeconds(1) + TimeSpan.FromMilliseconds(101));
                scheduledEventService.ScheduleEvent(nextEventTime - now, now);
            };

            scheduledEventService.NewEvent += handler;
            handler(this, null);
            Thread.Sleep(5000);
            scheduledEventService.DisposeSafely();
        }
        /// <summary>
        /// Pushes the tick into this enumerator. This tick will be aggregated into a quote bar
        /// and emitted after the alotted time has passed
        /// </summary>
        /// <param name="data">The new data to be aggregated</param>
        public void ProcessData(BaseData data)
        {
            QuoteBar working;

            var tick     = data as Tick;
            var qty      = tick == null ? 0 : tick.Quantity;
            var bidPrice = tick == null ? data.Value : tick.BidPrice;
            var askPrice = tick == null ? data.Value : tick.AskPrice;
            var bidSize  = tick == null ? 0m : tick.BidSize;
            var askSize  = tick == null ? 0m : tick.AskSize;

            if (!_queue.TryPeek(out working))
            {
                // the consumer took the working bar, or time ticked over into next bar
                var utcNow           = _timeProvider.GetUtcNow();
                var currentLocalTime = utcNow.ConvertFromUtc(_timeZone);
                var barStartTime     = currentLocalTime.RoundDown(_barSize);
                working = new QuoteBar();

                // open ask and bid should match previous close ask and bid
                if (Current != null)
                {
                    // note that we will only fill forward previous close ask and bid when a new data point comes in and we generate a new working bar which is not a fill forward bar
                    var previous = Current as QuoteBar;
                    working.Update(0, previous.Bid?.Close ?? 0, previous.Ask?.Close ?? 0, 0, previous.LastBidSize, previous.LastAskSize);
                }

                working.Update(data.Value, bidPrice, askPrice, qty, bidSize, askSize);
                working.Period = _barSize;
                working.Time   = barStartTime;
                working.Symbol = data.Symbol;
                _queue.Enqueue(working);

                if (_liveMode)
                {
                    _realTimeScheduleEventService.ScheduleEvent(_barSize.Subtract(currentLocalTime - barStartTime), utcNow);
                }
            }
            else
            {
                // we're still within this bar size's time
                working.Update(data.Value, bidPrice, askPrice, qty, bidSize, askSize);
            }
        }
Example #4
0
        /// <summary>
        /// Pushes the tick into this enumerator. This tick will be aggregated into a OI bar
        /// and emitted after the alotted time has passed
        /// </summary>
        /// <param name="data">The new data to be aggregated</param>
        public void ProcessData(Tick data)
        {
            OpenInterest working;

            if (!_queue.TryPeek(out working))
            {
                // the consumer took the working bar, or time ticked over into next bar
                var utcNow           = _timeProvider.GetUtcNow();
                var currentLocalTime = utcNow.ConvertFromUtc(_timeZone);
                var barStartTime     = currentLocalTime.RoundDown(_barSize);
                working         = new OpenInterest(barStartTime, data.Symbol, data.Value);
                working.EndTime = barStartTime + _barSize;
                _queue.Enqueue(working);

                if (_liveMode)
                {
                    _realTimeScheduleEventService.ScheduleEvent(_barSize.Subtract(currentLocalTime - barStartTime), utcNow);
                }
            }
            else
            {
                working.Value = data.Value;
            }
        }