private void ResetCurrentCandle(CandleDto latest) { CurrentCandle.Open = latest.Close; CurrentCandle.High = latest.Close; CurrentCandle.Low = latest.Close; CurrentCandle.Trades = 0; CurrentCandle.Volume = 0; CurrentCandle.Timestamp = ExchangeUtils.GetTimeOffsetFromDataPoints(latest.Period, CurrentCandle.Timestamp, -1); }
public ExchangeCandles(ILogger logger, RepositoryService repoService, IExchangeService exchange, IndicatorFactory indicatorFactory, TimePeriod period, Instrument instrument) { _logger = logger; _repoService = repoService; _exchange = exchange; _indicatorFactory = indicatorFactory; _period = period; _instrument = instrument; _exchangeName = _exchange.ExchangeConfig.ExchangeName; CurrentCandle = new CandleDto { ExchangeName = _exchangeName, Period = _period, Instrument = _instrument }; }
public async Task <ActionResult> PostCandle([FromBody] CandleDto candleDto, ApiVersion apiVersion, CancellationToken ct) { try { _logId = _batchLog.Start(); _batchLog.Update(_logId, $"POST PostCandle for {candleDto.Market} {candleDto.Granularity} {candleDto.TimeStamp} Candle"); var candle = _mapper.Map <Candle>(candleDto); var candleExists = await _unit.Candle.GetCandleExists(candle.Market, candle.Granularity, candle.TimeStamp, ct); if (candleExists) { var message = $"Duplicate Candle {candle.Market} {candle.Granularity} {candle.TimeStamp}"; _logger.LogWarning(_batchLog.Print(_logId, message)); return(UnprocessableEntity(message)); } await _unit.Candle.AddCandleAsync(candle, ct); _unit.SaveChanges(); _batchLog.Update(_logId, "Candle Added"); _logger.LogInformation(_batchLog.Print(_logId)); // re-direct will not work but i wont the 201 response + records added return(CreatedAtAction(nameof(GetCandles), new { id = candle.Id, version = apiVersion.ToString() }, candle)); } catch (OperationCanceledException) { _logger.LogWarning(_batchLog.Print(_logId, $"Operation Cancelled")); return(NotFound("Operation Cancelled")); } catch (Exception e) { _logger.LogError(_batchLog.Print(_logId, $"Error from {nameof(CandleController)}", e)); return(BadRequest(_batchLog.Print(_logId, $"Error from {nameof(CandleController)}", e))); } }