public async Task <IEnumerable <IFeedCandle> > GetCandlesAsync(PriceType priceType, TimeInterval interval, DateTime from, DateTime to) { if (priceType == PriceType.Unspecified) { throw new ArgumentException(nameof(priceType)); } string partitionKey = CandleTableEntity.GeneratePartitionKey(priceType); string rowKeyFrom = CandleTableEntity.GenerateRowKey(from, interval); string rowKeyTo = CandleTableEntity.GenerateRowKey(to, interval); TableQuery <CandleTableEntity> query = new TableQuery <CandleTableEntity>(); string pkeyFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey); var rowkeyCondFrom = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, rowKeyFrom); var rowkeyCondTo = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, rowKeyTo); var rowkeyFilter = TableQuery.CombineFilters(rowkeyCondFrom, TableOperators.And, rowkeyCondTo); query.FilterString = TableQuery.CombineFilters(pkeyFilter, TableOperators.And, rowkeyFilter); IEnumerable <CandleTableEntity> entities = await _tableStorage.WhereAsync(query); var result = from e in entities select e.Candles.Select(ci => ci.ToCandle(e.PriceType == PriceType.Bid, e.DateTime, interval)); return(result .SelectMany(c => c) .Where(c => c.DateTime >= from && c.DateTime < to)); }
public static string RowKey(this IFeedCandle candle, TimeInterval interval) { if (candle == null) { throw new ArgumentNullException(nameof(candle)); } return(CandleTableEntity.GenerateRowKey(candle.DateTime, candle.IsBuy, interval)); }
public async Task InsertOrMergeAsync(IFeedCandle candle, PriceType priceType, TimeInterval interval) { // Get candle table entity string partitionKey = CandleTableEntity.GeneratePartitionKey(priceType); string rowKey = CandleTableEntity.GenerateRowKey(candle.DateTime, interval); CandleTableEntity entity = await _tableStorage.GetDataAsync(partitionKey, rowKey); if (entity == null) { entity = new CandleTableEntity(partitionKey, rowKey); } // Merge candle entity.MergeCandle(candle, interval); // Update await _tableStorage.InsertOrMergeAsync(entity); }
public async Task <IFeedCandle> GetCandleAsync(string asset, TimeInterval interval, bool isBuy, DateTime dateTime) { if (string.IsNullOrEmpty(asset)) { throw new ArgumentNullException(nameof(asset)); } // 1. Get candle table entity string partitionKey = CandleTableEntity.GeneratePartitionKey(asset); string rowKey = CandleTableEntity.GenerateRowKey(dateTime, isBuy, interval); //CandleTableEntity entity = await _tableStorage.GetDataAsync(partitionKey, rowKey); //--------------- TableQuery <CandleTableEntity> query = new TableQuery <CandleTableEntity>(); string pkeyFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey); string rowkeyFilter = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, rowKey); query.FilterString = TableQuery.CombineFilters(pkeyFilter, TableOperators.And, rowkeyFilter); query.SelectColumns = CandleTableEntity.GetStoreFields(interval, dateTime); List <CandleTableEntity> entities = new List <CandleTableEntity>(1); await _tableStorage.ScanDataAsync(query, list => { entities.AddRange(list); return(Task.FromResult(0)); }); //----------- // 2. Find required candle in candle list by tick if (entities.Count > 0) { var cell = dateTime.GetIntervalCell(interval); var tick = dateTime.GetIntervalTick(interval); var candleItem = entities[0].Candles.FirstOrDefault(ci => ci.Tick == tick && ci.Cell == cell); return(candleItem.ToCandle(isBuy, entities[0].DateTime, interval)); } return(null); }
public async Task <IFeedCandle> GetCandleAsync(PriceType priceType, TimeInterval interval, DateTime dateTime) { if (priceType == PriceType.Unspecified) { throw new ArgumentException(nameof(priceType)); } // 1. Get candle table entity string partitionKey = CandleTableEntity.GeneratePartitionKey(priceType); string rowKey = CandleTableEntity.GenerateRowKey(dateTime, interval); CandleTableEntity entity = await _tableStorage.GetDataAsync(partitionKey, rowKey); // 2. Find required candle in candle list by tick if (entity != null) { var tick = dateTime.GetIntervalTick(interval); var candleItem = entity.Candles.FirstOrDefault(ci => ci.Tick == tick); return(candleItem.ToCandle(priceType == PriceType.Bid, entity.DateTime, interval)); } return(null); }
public async Task <IEnumerable <IFeedCandle> > GetCandlesAsync(string asset, TimeInterval interval, bool isBuy, DateTime from, DateTime to) { if (string.IsNullOrEmpty(asset)) { throw new ArgumentNullException(nameof(asset)); } string partitionKey = CandleTableEntity.GeneratePartitionKey(asset); string rowKeyFrom = CandleTableEntity.GenerateRowKey(from, isBuy, interval); string rowKeyTo = CandleTableEntity.GenerateRowKey(to, isBuy, interval); //IEnumerable<CandleTableEntity> candleEntities = await _tableStorage.WhereAsync(partitionKey, from, to, ToIntervalOption.ExcludeTo, null, includeTime: true); //--------------- TableQuery <CandleTableEntity> query = new TableQuery <CandleTableEntity>(); string pkeyFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey); string fromFilter = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, rowKeyFrom); string toFilter = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, rowKeyTo); query.FilterString = TableQuery.CombineFilters(pkeyFilter, TableOperators.And, TableQuery.CombineFilters(fromFilter, TableOperators.And, toFilter)); List <CandleTableEntity> entities = new List <CandleTableEntity>(1); await _tableStorage.ScanDataAsync(query, list => { entities.AddRange(list); return(Task.FromResult(0)); }); //----------- var result = from e in entities select e.Candles.Select(ci => ci.ToCandle(e.IsBuy, e.DateTime, interval)); return(result .SelectMany(c => c) .Where(c => c.DateTime >= from && c.DateTime < to)); }