From 97103fbfe809d2aef40acc01f6db63786155a12e Mon Sep 17 00:00:00 2001 From: cryptooda Date: Wed, 19 Nov 2025 23:39:38 +0700 Subject: [PATCH] Add master strategy validation in LiveTradingBotGrain - Introduced a check to ensure the master strategy is retrieved successfully before proceeding with key validation. - Added logging for cases where the master strategy is not found, improving traceability in the bot's operation. --- .../Bots/Grains/LiveTradingBotGrain.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Managing.Application/Bots/Grains/LiveTradingBotGrain.cs b/src/Managing.Application/Bots/Grains/LiveTradingBotGrain.cs index a04b8d56..b88c4663 100644 --- a/src/Managing.Application/Bots/Grains/LiveTradingBotGrain.cs +++ b/src/Managing.Application/Bots/Grains/LiveTradingBotGrain.cs @@ -514,8 +514,19 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable try { var ownedKeys = await _kaigenService.GetOwnedKeysAsync(_state.State.User); + + var masterStrategy = await ServiceScopeHelpers.WithScopedService( + _scopeFactory, + async botService => await botService.GetBotByIdentifier(_state.State.Config.MasterBotIdentifier.Value)); + + if (masterStrategy == null) + { + _logger.LogWarning("Master strategy {MasterBotId} not found", _state.State.Config.MasterBotIdentifier.Value); + return; + } + var hasMasterStrategyKey = ownedKeys.Items.Any(key => - string.Equals(key.AgentName, _state.State.Config.MasterBotIdentifier.Value.ToString(), StringComparison.OrdinalIgnoreCase) && + string.Equals(key.AgentName, masterStrategy.User.AgentName, StringComparison.OrdinalIgnoreCase) && key.Owned >= 1); if (!hasMasterStrategyKey)