コード例 #1
0
        public async Task LoadAsync()
        {
            var candleRepo = await _repoService.GetCandleRepositoryAsync(_exchangeName, _instrument, _period);

            if (candleRepo == null)
            {
                _logger.Log(LogLevel.Error, $"{_exchangeName} {_instrument} {_period} repository not found");
                return;
            }

            var dbCandles = await candleRepo.GetLastEntriesAsync();

            _candles = dbCandles.Select(Mapper.Map <CandleDto>).Select(x =>
            {
                x.Instrument   = _instrument;
                x.ExchangeName = _exchangeName;
                x.Period       = _period;

                return(x);
            }).ToList();

            if (!_candles.Any())
            {
                _logger.Log(LogLevel.Warn, $"{_exchangeName} {_instrument} {_period} could not load any candles");
            }
            else
            {
                _logger.Log(LogLevel.Debug, $"{_exchangeName} {_instrument} {_period} candle load complete");
            }

            await CatchupAsync(await candleRepo.GetLastEntryAsync());
        }
コード例 #2
0
ファイル: CandleService.cs プロジェクト: nazjunaid/bognabot
        private async Task Catchup()
        {
            var instruments = Enum.GetValues(typeof(Instrument)).Cast <Instrument>();
            var periods     = Enum.GetValues(typeof(TimePeriod)).Cast <TimePeriod>();

            foreach (var instrument in instruments)
            {
                foreach (var exchange in _exchanges)
                {
                    var supportedPeriods = exchange.ExchangeConfig.SupportedTimePeriods;
                    var maxPoints        = exchange.ExchangeConfig.UserConfig.MaxDataPoints;

                    foreach (var period in supportedPeriods)
                    {
                        var candleRepo = await _repoService.GetCandleRepositoryAsync(exchange.ExchangeConfig.ExchangeName, instrument, period.Key);

                        var lastEntry = await candleRepo.GetLastEntryAsync();

                        var now = exchange.Now;

                        var dataPoints = lastEntry != null
                            ? GetDataPointsFromTimeSpan(period.Key, now - lastEntry.TimestampOffset)
                            : maxPoints;

                        if (dataPoints <= 0)
                        {
                            continue;
                        }

                        if (dataPoints > maxPoints)
                        {
                            dataPoints = maxPoints;
                        }

                        var lastEntryLogText = (lastEntry != null ? $"was last seen at {lastEntry.TimestampOffset}" : "has no pevious records");
                        _logger.Log(LogLevel.Info, $"{exchange.ExchangeConfig.ExchangeName} {instrument} {period.Key} {lastEntryLogText}");

                        var syncStatusText = (dataPoints > 0 ? $"{dataPoints} data points behind" : "up to date");
                        _logger.Log(LogLevel.Info, $"{exchange.ExchangeConfig.ExchangeName} {instrument} {period.Key} is {syncStatusText}");

                        await InsertCandles(await exchange.GetCandlesAsync(instrument, period.Key, GetTimeOffsetFromDataPoints(period.Key, now, dataPoints), exchange.Now));
                    }
                }
            }
        }
コード例 #3
0
ファイル: SignalsService.cs プロジェクト: nazjunaid/bognabot
        public async Task ProcessSignals(IExchangeService exchangeService, Instrument instrument)
        {
            var periods = Enum.GetValues(typeof(TimePeriod)).Cast <TimePeriod>();

            foreach (var timePeriod in periods)
            {
                if (!exchangeService.ExchangeConfig.SupportedTimePeriods.ContainsKey(timePeriod))
                {
                    continue;
                }

                var candleRepo =
                    await _repositoryService.GetCandleRepositoryAsync(exchangeService.ExchangeConfig.ExchangeName,
                                                                      instrument, timePeriod);

                if (candleRepo == null)
                {
                    continue;
                }

                var lastCandles = new List <Candle>()
                {
                    Mapper.Map <Candle>(_candleService.GetLatestCandle(timePeriod,
                                                                       exchangeService.ExchangeConfig.ExchangeName))
                };

                lastCandles.AddRange(await candleRepo.GetLastEntriesAsync());

                if (!lastCandles.Any())
                {
                    continue;
                }

                var candles = lastCandles.ToArray();

                foreach (var signal in _signals.Values.Where(x => x.SupportedTimePeriods.Any(y => y == timePeriod)))
                {
                    var ss = await signal.ProcessSignal(timePeriod, candles);

                    _logger.Log(LogLevel.Info, $"{exchangeService.ExchangeConfig.ExchangeName} {instrument} {timePeriod} - {signal.GetType().Name} = {ss}");
                }
            }
        }