Enhance bot command handlers with GMX wallet initialization
- Updated RestartBotCommandHandler, StartBotCommandHandler, and StartCopyTradingCommandHandler to include ITradingService for GMX wallet initialization. - Added checks for GMX account initialization status and implemented wallet initialization logic where necessary. - Improved error handling for wallet initialization failures.
This commit is contained in:
@@ -14,13 +14,15 @@ namespace Managing.Application.ManageBot
|
||||
private readonly IAccountService _accountService;
|
||||
private readonly IGrainFactory _grainFactory;
|
||||
private readonly IBotService _botService;
|
||||
private readonly ITradingService _tradingService;
|
||||
|
||||
public StartBotCommandHandler(
|
||||
IAccountService accountService, IGrainFactory grainFactory, IBotService botService)
|
||||
IAccountService accountService, IGrainFactory grainFactory, IBotService botService, ITradingService tradingService)
|
||||
{
|
||||
_accountService = accountService;
|
||||
_grainFactory = grainFactory;
|
||||
_botService = botService;
|
||||
_tradingService = tradingService;
|
||||
}
|
||||
|
||||
public async Task<BotStatus> Handle(StartBotCommand request, CancellationToken cancellationToken)
|
||||
@@ -79,6 +81,16 @@ namespace Managing.Application.ManageBot
|
||||
}
|
||||
}
|
||||
|
||||
// Check GMX initialization status for GMX V2 accounts
|
||||
if (account.Exchange == TradingExchanges.GmxV2 && !account.IsGmxInitialized)
|
||||
{
|
||||
var initResult = await _tradingService.InitPrivyWallet(account.Key, TradingExchanges.GmxV2);
|
||||
if (!initResult.Success)
|
||||
{
|
||||
throw new InvalidOperationException($"Failed to initialize GMX wallet: {initResult.Error}");
|
||||
}
|
||||
}
|
||||
|
||||
Balance usdcBalance = null;
|
||||
// For other exchanges, keep the original USDC balance check
|
||||
if (account.Exchange != TradingExchanges.Evm && account.Exchange != TradingExchanges.GmxV2)
|
||||
|
||||
Reference in New Issue
Block a user