Refactor SpotBot and ExchangeService for balance retrieval

- Updated SpotBot to fetch token balance directly using the new GetBalance method in IExchangeService.
- Modified IExchangeService to include a method for retrieving balance by ticker.
- Enhanced ExchangeService to implement the new balance retrieval logic for both EVM and non-EVM exchanges.
- Updated TokenService to streamline contract address and decimal retrieval for various tokens.
- Adjusted TradesModal to reflect changes in position status handling.
This commit is contained in:
2025-12-08 23:37:10 +07:00
parent a2ed4edd32
commit 931af3d3af
9 changed files with 232 additions and 54 deletions

View File

@@ -1,5 +1,6 @@
using Managing.Application.Abstractions.Repositories;
using Managing.Application.Abstractions.Repositories;
using Managing.Application.Abstractions.Services;
using Managing.Common;
using Managing.Domain.Accounts;
using Managing.Domain.Candles;
using Managing.Domain.Statistics;
@@ -16,13 +17,18 @@ namespace Managing.Infrastructure.Exchanges
private readonly ILogger<ExchangeService> _logger;
private readonly ICandleRepository _candleRepository;
private readonly IEnumerable<IExchangeProcessor> _exchangeProcessor;
private readonly IEvmManager _evmManager;
public ExchangeService(ILogger<ExchangeService> logger, ICandleRepository candleRepository,
IEnumerable<IExchangeProcessor> processor)
public ExchangeService(
ILogger<ExchangeService> logger,
ICandleRepository candleRepository,
IEnumerable<IExchangeProcessor> processor,
IEvmManager evmManager)
{
_logger = logger;
_candleRepository = candleRepository;
_exchangeProcessor = processor;
_evmManager = evmManager;
}
#region Trades
@@ -253,6 +259,35 @@ namespace Managing.Infrastructure.Exchanges
return await processor.GetBalance(account);
}
public async Task<Balance?> GetBalance(Account account, Ticker ticker)
{
if (!IsEvmExchange(account))
{
var processor = GetProcessor(account);
var balances = await processor.GetBalances(account);
return balances.FirstOrDefault(balance =>
string.Equals(balance.TokenName, ticker.ToString(), StringComparison.InvariantCultureIgnoreCase));
}
var evmBalance = await _evmManager.GetTokenBalance(Constants.Chains.Arbitrum, ticker, account.Key);
if (evmBalance == null)
{
return null;
}
return new Balance
{
TokenName = evmBalance.TokenName,
Price = evmBalance.Price,
Value = evmBalance.Value,
Amount = evmBalance.Balance,
TokenAdress = evmBalance.TokenAddress,
Chain = evmBalance.Chain
};
}
public async Task<decimal> GetFee(Account account, bool isForPaperTrading = false)
{
var processor = GetProcessor(account);