コード例 #1
0
        /// <summary>
        /// Startup logic implementation.
        /// </summary>
        /// <returns></returns>
        public async Task StartAsync()
        {
            //read last saved cache
            var savedExchanges = await _genericBlobRepository.ReadAsync <List <Exchange> >(Constants.BlobContainerName,
                                                                                           Constants.BlobExchangesCache);

            //retrieve current hedging positions
            IReadOnlyList <ExternalPositionModel> currentHedgingPositions = null;

            try
            {
                currentHedgingPositions = await _hedgingServiceClient.ExternalPositions.List();
            }
            catch (Exception ex)
            {
                await _log.WriteFatalErrorAsync(nameof(StartupManager), nameof(StartAsync), ex, DateTime.UtcNow);

                throw;
            }

            //initialize ExchangeCache
            var cachedData = _exchangeCache.Initialize(savedExchanges,
                                                       currentHedgingPositions?
                                                       .Where(x => _requiredExchanges.Any(exch => exch == x.Exchange))
                                                       .GroupBy(x => x.Exchange)
                                                       .ToDictionary(x => x.Key, x => x.Select(Position.Create).ToList())
                                                       ?? new Dictionary <string, List <Position> >());

            //save old blob data
            await _genericBlobRepository.Write(Constants.BlobContainerName,
                                               $"{Constants.BlobExchangesCache}_{DateTime.UtcNow:s}", savedExchanges);

            //write new blob data
            await _genericBlobRepository.Write(Constants.BlobContainerName, Constants.BlobExchangesCache, cachedData);

            await _log.WriteInfoAsync(nameof(StartupManager), nameof(StartAsync),
                                      $"ExchangeCache initialized with data: {string.Join("; ",cachedData)}.", DateTime.UtcNow);
        }
コード例 #2
0
        public override async Task Execute()
        {
            var data = _exchangeCache.GetAll();

            if (data == null || data.Count == 0)
            {
                return;
            }

            await _genericBlobRepository.Write(Constants.BlobContainerName, Constants.BlobExchangesCache, data);

            await _log.WriteInfoAsync(nameof(DataSavingHandler), nameof(Execute),
                                      $"Exchange cache saved to blob: {string.Join("; ", data)}.", DateTime.UtcNow);
        }