From 6c338b1f4f1408914739e5ad5136ce1ec1a933fe Mon Sep 17 00:00:00 2001 From: vlad zverzhkhovskiy Date: Wed, 17 Sep 2025 17:05:32 +0300 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=20=D1=81=D0=BA=D0=BE?= =?UTF-8?q?=D1=80=D0=BE=D1=81=D1=82=D0=B8=20=D1=81=D1=82=D0=B0=D1=80=D1=82?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KLHZ.Trader.Core/Exchange/Services/TraderDataProvider.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/KLHZ.Trader.Core/Exchange/Services/TraderDataProvider.cs b/KLHZ.Trader.Core/Exchange/Services/TraderDataProvider.cs index 53858ab..06a149b 100644 --- a/KLHZ.Trader.Core/Exchange/Services/TraderDataProvider.cs +++ b/KLHZ.Trader.Core/Exchange/Services/TraderDataProvider.cs @@ -43,6 +43,7 @@ namespace KLHZ.Trader.Core.Exchange.Services internal readonly ConcurrentDictionary Accounts = new(); private readonly bool _isDataRecievingAllowed = false; private readonly Channel _forSave = Channel.CreateUnbounded(); + private readonly SemaphoreSlim _syncSemaphore = new SemaphoreSlim(1, 1); private readonly SemaphoreSlim _initSemaphore = new SemaphoreSlim(1, 1); public TraderDataProvider(InvestApiClient investApiClient, IOptions options, IDbContextFactory dbContextFactory, ILogger logger) @@ -170,7 +171,8 @@ namespace KLHZ.Trader.Core.Exchange.Services { try { - await _initSemaphore.WaitAsync(TimeSpan.FromSeconds(3)); + var cts = new CancellationTokenSource(TimeSpan.FromSeconds(3)); + await _initSemaphore.WaitAsync(cts.Token); var shares = await _investApiClient.Instruments.SharesAsync(); foreach (var share in shares.Instruments) { @@ -264,7 +266,7 @@ namespace KLHZ.Trader.Core.Exchange.Services try { - await _initSemaphore.WaitAsync(TimeSpan.FromSeconds(5)); + await _syncSemaphore.WaitAsync(); var portfolio = await _investApiClient.Operations.GetPortfolioAsync(new PortfolioRequest() { AccountId = account.AccountId, @@ -354,7 +356,7 @@ namespace KLHZ.Trader.Core.Exchange.Services _logger.LogError(ex, "Ошибка при синхранизации портфеля счёта {accountId}", account.AccountId); } - _initSemaphore.Release(); + _syncSemaphore.Release(); } internal async Task UpdateFuturesPrice(INewPrice newPrice, decimal newPriceValue)