private async IAsyncEnumerable <ITradingInstrument> GetTradingInstruments(
            IReadOnlyList <Product> products,
            string tradingConditionId = null)
        {
            var clientProfiles = tradingConditionId == null
                ? await _clientProfilesRepository.GetAllAsync()
                : new[] { await _clientProfilesRepository.GetByIdAsync(tradingConditionId) };

            var assetTypes = products.Select(p => p.AssetType).Distinct().ToList();

            foreach (var clientProfile in clientProfiles)
            {
                var availableClientProfileSettingsList =
                    await _clientProfileSettingsRepository.GetAllAsync(clientProfile.Id, assetTypes, true);

                foreach (var product in products)
                {
                    var clientProfileSettings = availableClientProfileSettingsList.SingleOrDefault(x =>
                                                                                                   x.ClientProfileId == clientProfile.Id && x.AssetTypeId == product.AssetType);

                    if (clientProfileSettings == null)
                    {
                        continue;
                    }

                    var underlying = _underlyingsCache.GetByMdsCode(product.UnderlyingMdsCode);

                    yield return(TradingInstrument.CreateFromProduct(
                                     product,
                                     clientProfileSettings.ClientProfileId,
                                     clientProfileSettings.Margin,
                                     underlying?.Spread ?? _defaultTradingInstrumentSettings.Spread));
                }
            }
        }
Exemple #2
0
        public async Task <ITradingCondition> GetAsync(string clientProfileId)
        {
            var clientProfile = await _clientProfilesRepository.GetByIdAsync(clientProfileId);

            if (clientProfile == null)
            {
                return(null);
            }

            var settlementCurrency = await _settlementCurrencyService.GetSettlementCurrencyAsync();

            return(MapTradingCondition(clientProfile, settlementCurrency));
        }