40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
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<string, IManagedAccount> 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<IManagedAccount>(i);
|
|
if (acc != null)
|
|
{
|
|
if (acc.Initialized)
|
|
{
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
await acc.Init(accountId, accountName);
|
|
Accounts[accountId] = acc;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
throw new ArgumentOutOfRangeException("Уже инициализировано максимальное количество счетов.");
|
|
}
|
|
}
|
|
}
|