/// <inheritdoc /> public async Task <TradingEngineSnapshot> RunAsync(IEnumerable <ClosingFxRate> fxRates, IEnumerable <ClosingAssetPrice> cfdQuotes, string correlationId) { var fxRatesList = fxRates?.ToList(); var cfdQuotesList = cfdQuotes?.ToList(); if (fxRatesList == null || !fxRatesList.Any()) { throw new EmptyPriceUploadException(); } if (cfdQuotesList == null || !cfdQuotesList.Any()) { throw new EmptyPriceUploadException(); } var positions = _draftSnapshotKeeper.GetPositions(); var accounts = (await _draftSnapshotKeeper.GetAccountsAsync()).ToImmutableArray(); foreach (var closingFxRate in fxRatesList) { ApplyFxRate(positions, accounts, closingFxRate.ClosePrice, closingFxRate.AssetId); } var orders = _draftSnapshotKeeper.GetAllOrders(); foreach (var closingAssetPrice in cfdQuotesList) { ApplyCfdQuote(positions, orders, accounts, closingAssetPrice.ClosePrice, closingAssetPrice.AssetId); } var quotesTimestamp = _dateService.Now(); await _draftSnapshotKeeper.UpdateAsync( positions, orders, accounts, fxRatesList.Select(r => r.ToContract(quotesTimestamp)), cfdQuotesList.Select(q => q.ToContract(quotesTimestamp)) ); return(new TradingEngineSnapshot(_draftSnapshotKeeper.TradingDay, correlationId, _draftSnapshotKeeper.Timestamp, MapToFinalJson(orders, _draftSnapshotKeeper), MapToFinalJson(positions, _draftSnapshotKeeper), MapToFinalJson(accounts), MapToJson(_draftSnapshotKeeper.FxPrices), MapToJson(_draftSnapshotKeeper.CfdQuotes), SnapshotStatus.Final)); }
public ICollection <Position> GetPositionsByAccountIds(params string[] accountIds) { if (accountIds == null || !accountIds.Any() || accountIds.Any(string.IsNullOrWhiteSpace)) { throw new ArgumentNullException(nameof(accountIds)); } if (_draftSnapshotKeeper.Initialized()) { _log.WriteInfoAsync(nameof(PositionsProvider), nameof(GetPositionsByAccountIds), _draftSnapshotKeeper.TradingDay.ToJson(), "Draft snapshot keeper initialized and will be used as positions provider"); var positions = _draftSnapshotKeeper.GetPositions(); return(positions .Where(p => accountIds.Contains(p.AccountId)) .ToList()); } return(_ordersCache.Positions.GetPositionsByAccountIds(accountIds)); }