public SortedDictionary <uint, MarketState> DuplicateTick(SortedDictionary <uint, MarketState> mostRecentState, DateTime timestamp)
        {
            // create a new time stamp if it doesn't exist (Only exist if there is a race condition)
            if (!_marketData.ContainsKey(timestamp))
            {
                _marketData.Add(timestamp, new SortedDictionary <uint, MarketState>());
            }

            var marketDataForTimeStamp = _marketData[timestamp];

            lock (marketDataForTimeStamp)
            {
                DateTime newTimeStamp = DateTime.MinValue;

                var prevState = mostRecentState[(uint)mostRecentState.Count - 1];
                var newState  = new MarketState(_securityObj, prevState, timestamp);
                SortedDictionary <uint, MarketState> timeBin = _marketData[timestamp];

                newState.BinCnt = (uint)marketDataForTimeStamp.Count;
                marketDataForTimeStamp.Add(newState.BinCnt, newState);

                if (LogEachTick)
                {
                    string output = newState.ToStringAllData();
                    if (newState.StateType == MktStateType.Trade)
                    {
                        output += " " + newState.ToStringAllTradesNoIndentity();
                    }
                    Console.WriteLine(output);
                }
            }

            return(_marketData[timestamp]);
        }
Esempio n. 2
0
        public void NewTick(TickData newData)
        {
            DateTime currTimeBinTimeStamp = getCurrentInterval(newData.TimeStamp);

            if (currTimeBinTimeStamp > DateTime.MinValue) // check to make sure the initialzation has happend
            {
                // get the current market state
                SortedDictionary <uint, MarketState> currTimeBin = _marketData[currTimeBinTimeStamp];
                MarketState currentState = currTimeBin.ElementAt(currTimeBin.Count - 1).Value; // last data point in time bin

                // disregard duplicates
                if (!DuplicateOfPrevDataPoint(newData, currentState))
                {
                    bool addedNewTimeStamp = false;
                    if (!_marketData.ContainsKey(newData.TimeStamp))
                    {
                        _marketData.Add(newData.TimeStamp, new SortedDictionary <uint, MarketState>());
                        _latestTimeBin    = newData.TimeStamp > _latestTimeBin ? newData.TimeStamp : _latestTimeBin;
                        addedNewTimeStamp = true;
                    }

                    var marketDataForTimeStamp = _marketData[newData.TimeStamp];
                    lock (marketDataForTimeStamp)
                    {
                        // create a new updated market state
                        var newState = new MarketState(_securityObj, currentState, newData);

                        newState.BinCnt = (uint)marketDataForTimeStamp.Count;
                        marketDataForTimeStamp.Add(newState.BinCnt, newState);

                        if (LogEachTick)
                        {
                            string output = newState.ToStringAllData();
                            if (newState.StateType == MktStateType.Trade)
                            {
                                output += " " + newState.ToStringAllTradesNoIndentity();
                            }
                            Console.WriteLine(output);
                        }
                    }

                    // let the market aggregator know there is a new timestamp to aggregate
                    if (addedNewTimeStamp)
                    {
                        _markets.AddTickData(this, _marketData[newData.TimeStamp], newData.TimeStamp);
                    }
                }
            }
        }
        public SortedDictionary<uint, MarketState> DuplicateTick(SortedDictionary<uint, MarketState> mostRecentState, DateTime timestamp)
        {
            // create a new time stamp if it doesn't exist (Only exist if there is a race condition)
            if (!_marketData.ContainsKey(timestamp))
                _marketData.Add(timestamp, new SortedDictionary<uint, MarketState>());

            var marketDataForTimeStamp = _marketData[timestamp];
            lock (marketDataForTimeStamp)
            {
                DateTime newTimeStamp = DateTime.MinValue;

                var prevState = mostRecentState[(uint)mostRecentState.Count - 1];
                var newState = new MarketState(_securityObj, prevState, timestamp);
                SortedDictionary<uint, MarketState> timeBin = _marketData[timestamp];

                newState.BinCnt = (uint)marketDataForTimeStamp.Count;
                marketDataForTimeStamp.Add(newState.BinCnt, newState);

                if (LogEachTick)
                {
                    string output = newState.ToStringAllData();
                    if (newState.StateType == MktStateType.Trade) output += " " + newState.ToStringAllTradesNoIndentity();
                    Console.WriteLine(output);
                }
            }

            return _marketData[timestamp];
        }
        public void NewTick(TickData newData)
        {
            DateTime currTimeBinTimeStamp = getCurrentInterval(newData.TimeStamp);

            if (currTimeBinTimeStamp > DateTime.MinValue) // check to make sure the initialzation has happend
            {
                // get the current market state
                SortedDictionary<uint, MarketState> currTimeBin = _marketData[currTimeBinTimeStamp];
                MarketState currentState = currTimeBin.ElementAt(currTimeBin.Count - 1).Value; // last data point in time bin

                // disregard duplicates
                if (!DuplicateOfPrevDataPoint(newData, currentState))
                {
                    bool addedNewTimeStamp = false;
                    if (!_marketData.ContainsKey(newData.TimeStamp))
                    {
                        _marketData.Add(newData.TimeStamp, new SortedDictionary<uint, MarketState>());
                        addedNewTimeStamp = true;
                    }

                    var marketDataForTimeStamp = _marketData[newData.TimeStamp];
                    lock (marketDataForTimeStamp)
                    {
                        // create a new updated market state
                        var newState = new MarketState(_securityObj, currentState, newData);

                        newState.BinCnt = (uint) marketDataForTimeStamp.Count;
                        marketDataForTimeStamp.Add(newState.BinCnt, newState);

                        if (LogEachTick)
                        {
                            string output = newState.ToStringAllData();
                            if (newState.StateType == MktStateType.Trade) output += " " + newState.ToStringAllTradesNoIndentity();
                            Console.WriteLine(output);
                        }

                    }

                    // let the market aggregator know there is a new timestamp to aggregate
                    if (addedNewTimeStamp)
                        _markets.AddTickData(this, _marketData[newData.TimeStamp], newData.TimeStamp);

                }
            }
        }