示例#1
0
        DateTime GetStartDate(AssetFIGI figi)
        {
            var price = _priceManager.TryGet(figi);

            if (price == null)
            {
                _logger.LogTrace($"Currency price for FIGI '{figi}' is unknown, lookup first add date");
                return(_priceManager.GetStartDate());
            }
            var lastRecordedDate = price.Candles[^ 1].Date;
示例#2
0
        public CurrencyPrice?TryGet(AssetFIGI figi)
        {
            var model = TryGetModel(figi);

            if (model == null)
            {
                return(null);
            }
            return(new CurrencyPrice(
                       model.Code, model.Figi,
                       model.Candles.Select(c => new Candle(c.Date, c.Open, c.Close, c.Low, c.High)).ToList()));
        }
示例#3
0
        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);
            }
        }
示例#4
0
 CurrencyPriceModel?TryGetModel(AssetFIGI figi) =>
 _repository.GetAll()
 .FirstOrDefault(m => m.Figi == figi);
示例#5
0
        public IReadOnlyCollection <(DateTime, DateTime)> TryCalculateRequiredIntervals(AssetFIGI figi)
        {
            var startDate = GetStartDate(figi);
            var endDate   = GetEndDate();

            _logger.LogTrace($"Interval for FIGI '{figi}' is {startDate}-{endDate}");
            var result = new List <(DateTime, DateTime)>();
            var diff   = (endDate - startDate);

            if (diff < TimeSpan.FromDays(1))
            {
                _logger.LogTrace("No processing required");
                return(result);
            }
            var date = startDate;

            while (date < endDate)
            {
                var interval = (endDate - date);
                var nextDate = (interval.TotalDays < 365) ? endDate : date.AddDays(365);
                result.Add((date, nextDate));
                date = nextDate.AddDays(1);
            }
            _logger.LogTrace(
                $"Interval splits into {result.Count} parts: {string.Join("; ", result.Select(r => r.ToString()))}");
            return(result);
        }