/// <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); //initialize ExchangeCache _exchangeCache.Initialize(savedExchanges); await _log.WriteInfoAsync(nameof(StartupManager), nameof(StartAsync), $"ExchangeCache initialized with data: {string.Join("; ", savedExchanges)}.", DateTime.UtcNow); }
/// <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); }
public async Task StartAsync() { // TODO: Implement your startup logic here. Good idea is to log every step var exchangeSettings = _fakeExchangeConnectorSettings.ExchangesConfig.Select(ex => new Exchange(ex.Name) { Instruments = ex.Instruments?.Select(x => new Instrument(ex.Name, x)).ToList() ?? new List <Instrument>(), Accounts = ex.Accounts ?? new AccountBalance[0], Positions = ex.Positions?.Select(x => new Position { Symbol = x.Symbol, PositionVolume = x.PositionVolume }).ToList() ?? new List <Position>(), StreamingSupport = new StreamingSupport(ex.StreamingSupport.OrderBooks, ex.StreamingSupport.Orders), AcceptOrder = ex.AcceptOrder, PushEventToRabbit = ex.PushEventToRabbit }); _exchangeCache.Initialize(exchangeSettings); await Task.CompletedTask; }