public Task <List <PriceHistoryFrameModel> > GetPriceHistory(int cursorTimeStamp, int toUnixTimeStamp, int asset, PriceHistoryPeriod period) { var cursorId = PriceHistoryExtensions.EncodeId(asset, (int)period, cursorTimeStamp); var toId = PriceHistoryExtensions.EncodeId(asset, (int)period, toUnixTimeStamp); var result = frames .Where(f => f.Id >= cursorId && f.Id < toId) .OrderByDescending(f => f.Id) .ToList(); return(Task.FromResult(result)); }
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 <List <PriceHistoryFrameModel> > GetPriceHistory(int cursorTimeStamp, int toUnixTimeStamp, int asset, PriceHistoryPeriod period) { var cursorId = PriceHistoryExtensions.EncodeId(asset, (int)period, cursorTimeStamp); var toId = PriceHistoryExtensions.EncodeId(asset, (int)period, toUnixTimeStamp); var query = priceHistoryCollection.Find( Builders <PriceHistoryFrameModel> .Filter.And( Builders <PriceHistoryFrameModel> .Filter.Gte(f => f.Id, cursorId), Builders <PriceHistoryFrameModel> .Filter.Lt(f => f.Id, toId) ) ).SortByDescending(x => x.Id); return(await query .ToListAsync()); }
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); }
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 }); }
public static PriceHistoryFrameModel ToFrameModel(this PriceHistoryFrame frame) { if (frame is null) { throw new ArgumentNullException(nameof(frame)); } var id = PriceHistoryExtensions.EncodeId(frame.Market, (int)frame.Period, (int)((DateTimeOffset)frame.StartTime).ToUnixTimeSeconds()); return(new PriceHistoryFrameModel { Id = id, Open = frame.Open, Close = frame.Close, Low = frame.Low, High = frame.High, BaseVolume = frame.BaseVolume, CounterVolume = frame.CounterVolume }); }