Fix restart bot without account
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using Managing.Application.Abstractions;
|
using Managing.Application.Abstractions;
|
||||||
using Managing.Application.Abstractions.Services;
|
using Managing.Application.Abstractions.Services;
|
||||||
using Managing.Application.ManageBot.Commands;
|
using Managing.Application.ManageBot.Commands;
|
||||||
|
using Managing.Domain.Accounts;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using static Managing.Common.Enums;
|
using static Managing.Common.Enums;
|
||||||
|
|
||||||
@@ -50,7 +51,22 @@ namespace Managing.Application.ManageBot
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get account to check GMX initialization status
|
// Get account to check GMX initialization status
|
||||||
var account = await _accountService.GetAccount(botConfig.AccountName, true, true);
|
Account account;
|
||||||
|
if (string.IsNullOrEmpty(botConfig.AccountName))
|
||||||
|
{
|
||||||
|
// Fallback: Get the first account for the user
|
||||||
|
var userAccounts = await _accountService.GetAccountsByUserAsync(bot.User, true, true);
|
||||||
|
var firstAccount = userAccounts.FirstOrDefault();
|
||||||
|
if (firstAccount == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"User '{bot.User.Name}' has no accounts configured.");
|
||||||
|
}
|
||||||
|
account = firstAccount;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
account = await _accountService.GetAccount(botConfig.AccountName, true, true);
|
||||||
|
}
|
||||||
if (account.Exchange == TradingExchanges.GmxV2 && !account.IsGmxInitialized)
|
if (account.Exchange == TradingExchanges.GmxV2 && !account.IsGmxInitialized)
|
||||||
{
|
{
|
||||||
var initResult = await _tradingService.InitPrivyWallet(account.Key, TradingExchanges.GmxV2);
|
var initResult = await _tradingService.InitPrivyWallet(account.Key, TradingExchanges.GmxV2);
|
||||||
|
|||||||
Reference in New Issue
Block a user