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.
This commit is contained in:
2025-11-19 23:39:38 +07:00
parent fb570b9f7e
commit 97103fbfe8

View File

@@ -514,8 +514,19 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
try try
{ {
var ownedKeys = await _kaigenService.GetOwnedKeysAsync(_state.State.User); var ownedKeys = await _kaigenService.GetOwnedKeysAsync(_state.State.User);
var masterStrategy = await ServiceScopeHelpers.WithScopedService<IBotService, Bot>(
_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 => 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); key.Owned >= 1);
if (!hasMasterStrategyKey) if (!hasMasterStrategyKey)