public async Task Add(CurrencyPriceModel price) { var model = new MongoCurrencyPriceModel { Price = price }; await _collection.InsertOneAsync(model); _logger.LogTrace($"Price added: {price}"); }
public async Task Update(CurrencyPriceModel price) { var model = _collection.AsQueryable() .FirstOrDefault(m => (m.Price != null) && (m.Price.Figi == price.Figi)); if (model == null) { _logger.LogWarning($"Price not found: {price}"); return; } model.Price = price; await _collection.ReplaceOneAsync(m => m.Id == model.Id, model); _logger.LogTrace($"Price updated: {price}"); }
public async Task AddOrAppendCandles(CurrencyCode currency, AssetFIGI figi, CandleList candles) { var model = TryGetModel(figi); var candleModels = candles.Candles .Select(c => new CandleModel(new DateTimeOffset(c.Time), c.Open, c.Close, c.Low, c.High)) .ToList(); if (model != null) { _logger.LogTrace($"Add {candleModels.Count} candles to existing model '{currency}' with FIGI '{figi}'"); model.Candles.AddRange(candleModels); await _repository.Update(model); } else { _logger.LogTrace($"Creating new model '{currency}' with FIGI '{figi}'"); var newModel = new CurrencyPriceModel(currency, candles.Figi, candleModels); await _repository.Add(newModel); } }