public bool?SetAcceptOrder(string exchangeName, bool acceptOrder) { var exchange = _exchangeCache.Get(exchangeName); if (exchange == null) { return(null); } exchange.AcceptOrder = acceptOrder; _exchangeCache.Set(exchange); return(acceptOrder); }
public async Task Poll(string exchangeName, TimeSpan timeout) { var tokenSource = new CancellationTokenSource(timeout); List <Position> positions = null; //retrieve positions try { positions = (await _exchangeConnectorService.GetOpenedPositionAsync(exchangeName, tokenSource.Token)) .Select(Position.Create).ToList(); } catch (Exception ex) { await _log.WriteErrorAsync(nameof(ExchangePollingService), nameof(Poll), ex, DateTime.UtcNow); //TODO consider slack notification here return; } var exchange = _exchangeCache.GetOrCreate(exchangeName); //perform checking var checkResults = CheckPositions(exchange, positions); //create diff order for Risk System var executedTrades = checkResults .Select(x => CreateExecutionReport(exchangeName, x.Item1, x.Item2)) //do nothing if there's no quotes on any instrument, and wait for actual quotes. .Where(x => x != null) .ToList(); if (executedTrades.Count == 0) { return; } //publish trades for Risk System foreach (var executedTrade in executedTrades) { await _executionReportPublisher.Publish(executedTrade); } await _log.WriteInfoAsync(nameof(ExchangePollingService), nameof(Poll), $"Execution report have been published for {exchangeName}: {string.Join(", ", executedTrades.Select(x => x.Instrument.Name))}", DateTime.UtcNow); //update positions and push published changes to cache exchange.UpdatePositions(positions.Where(x => executedTrades.Select(tr => tr.Instrument.Name).Any(instrument => instrument == x.Symbol))); _exchangeCache.Set(exchange); }