public Task <int> GetFirstPriceHistoryFrameDate(int market, PriceHistoryPeriod period)
        {
            var firstId    = PriceHistoryExtensions.EncodeId(market, (int)period, 0);
            var firstFrame = frames
                             .OrderByDescending(f => f.Id)
                             .FirstOrDefault(f => f.Id >= firstId);

            if (firstFrame == null)
            {
                return(Task.FromResult(0));
            }

            return(Task.FromResult(PriceHistoryExtensions.DecodeId(firstFrame.Id).timestamp));
        }
        public async Task <int> GetFirstPriceHistoryFrameDate(int market, PriceHistoryPeriod period)
        {
            var firstId = PriceHistoryExtensions.EncodeId(market, (int)period, 0);

            var firstFrame = await priceHistoryCollection
                             .Find(Builders <PriceHistoryFrameModel> .Filter.Gte(f => f.Id, firstId))
                             .SortBy(e => e.Id)
                             .FirstOrDefaultAsync();

            if (firstFrame == null)
            {
                return(0);
            }

            return(PriceHistoryExtensions.DecodeId(firstFrame.Id).timestamp);
        }
Esempio n. 3
0
        public static PriceHistoryFrame FromModel(this PriceHistoryFrameModel frameModel)
        {
            if (frameModel is null)
            {
                throw new ArgumentNullException(nameof(frameModel));
            }

            var decodedId = PriceHistoryExtensions.DecodeId(frameModel.Id);

            return(new PriceHistoryFrame(DateTimeOffset.FromUnixTimeSeconds(decodedId.timestamp).UtcDateTime, (PriceHistoryPeriod)decodedId.period, decodedId.market, frameModel.Open)
            {
                Open = frameModel.Open,
                Close = frameModel.Close,
                High = frameModel.High,
                Low = frameModel.Low,
                BaseVolume = frameModel.BaseVolume,
                CounterVolume = frameModel.CounterVolume
            });
        }