using KLHZ.Trader.Core.Exchange.Interfaces; using Microsoft.Extensions.DependencyInjection; using System.Collections.Concurrent; namespace KLHZ.Trader.Core.Exchange.Services { public class PortfolioWrapper { private readonly IServiceProvider _services; public readonly ConcurrentDictionary Accounts = new(); public PortfolioWrapper(IServiceProvider services) { _services = services; } public async Task AddAccount(string accountId, string? accountName = null) { for (int i = 0; i < 10; i++) { var acc = _services.GetKeyedService(i); if (acc != null) { if (acc.Initialized) { continue; } else { await acc.Init(accountId, accountName); Accounts[accountId] = acc; return; } } } throw new ArgumentOutOfRangeException("Уже инициализировано максимальное количество счетов."); } } }