public MarginTradingAccount GetAccountById(string accountId) { if (string.IsNullOrWhiteSpace(accountId)) { throw new ArgumentNullException(nameof(accountId)); } if (_draftSnapshotKeeper.Initialized()) { _log.WriteInfoAsync(nameof(AccountsProvider), nameof(GetAccountById), _draftSnapshotKeeper.TradingDay.ToJson(), "Draft snapshot keeper initialized and will be used as accounts provider"); var accounts = _draftSnapshotKeeper .GetAccountsAsync() .GetAwaiter() .GetResult(); return(accounts .SingleOrDefault(a => a.Id == accountId)); } return(_accountsCacheService.TryGet(accountId)); }
/// <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)); }