Fix allocated amount when no bot
This commit is contained in:
@@ -3,6 +3,7 @@ using Managing.Application.Abstractions.Grains;
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Application.ManageBot.Commands;
|
||||
using Managing.Common;
|
||||
using Managing.Domain.Accounts;
|
||||
using MediatR;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
@@ -42,7 +43,7 @@ namespace Managing.Application.ManageBot
|
||||
$"Bot trading balance must be greater than {Constants.GMX.Config.MinimumPositionAmount}");
|
||||
}
|
||||
|
||||
var account = await _accountService.GetAccount(request.Config.AccountName, true, false);
|
||||
var account = await _accountService.GetAccount(request.Config.AccountName, true, true);
|
||||
|
||||
if (account == null)
|
||||
{
|
||||
@@ -59,16 +60,18 @@ namespace Managing.Application.ManageBot
|
||||
}
|
||||
}
|
||||
|
||||
Balance usdcBalance = null;
|
||||
// For other exchanges, keep the original USDC balance check
|
||||
if (account.Exchange != TradingExchanges.Evm && account.Exchange != TradingExchanges.GmxV2)
|
||||
{
|
||||
var usdcBalance = account.Balances.FirstOrDefault(b => b.TokenName == Ticker.USDC.ToString());
|
||||
usdcBalance = account.Balances.FirstOrDefault(b => b.TokenName == Ticker.USDC.ToString());
|
||||
|
||||
if (usdcBalance == null ||
|
||||
usdcBalance.Value < Constants.GMX.Config.MinimumPositionAmount ||
|
||||
usdcBalance.Value < request.Config.BotTradingBalance)
|
||||
{
|
||||
throw new Exception($"Account {request.Config.AccountName} has no USDC balance or not enough balance");
|
||||
throw new Exception(
|
||||
$"Account {request.Config.AccountName} has no USDC balance or not enough balance");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,14 +80,15 @@ namespace Managing.Application.ManageBot
|
||||
if (request.Config.BotTradingBalance > availableAllocation)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Insufficient available allocation on account '{account.Name}'. Requested: {request.Config.BotTradingBalance:F2} USDC, Available: {availableAllocation:F2} USDC.");
|
||||
$"Insufficient available allocation on account '{account.Name}'. Requested: {request.Config.BotTradingBalance:F2} USDC, " +
|
||||
$"Balance : {usdcBalance?.Value:F2 ?? 0} Available: {availableAllocation:F2} USDC.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var botGrain = _grainFactory.GetGrain<ILiveTradingBotGrain>(Guid.NewGuid());
|
||||
await botGrain.CreateAsync(request.Config, request.User);
|
||||
|
||||
|
||||
// Only start the bot if createOnly is false
|
||||
if (!request.CreateOnly)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user