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:
@@ -85,14 +85,9 @@ public class SpotBot : TradingBotBase, ITradingBot
|
||||
// For spot trading, fetch token balance directly and update PnL based on current price
|
||||
try
|
||||
{
|
||||
var balances = await ServiceScopeHelpers.WithScopedService<IExchangeService, List<Balance>>(
|
||||
var tokenBalance = await ServiceScopeHelpers.WithScopedService<IExchangeService, Balance?>(
|
||||
_scopeFactory,
|
||||
async exchangeService => { return await exchangeService.GetBalances(Account); });
|
||||
|
||||
// Find the token balance for the ticker
|
||||
var tickerString = Config.Ticker.ToString();
|
||||
var tokenBalance = balances.FirstOrDefault(b =>
|
||||
b.TokenName?.Equals(tickerString, StringComparison.OrdinalIgnoreCase) == true);
|
||||
async exchangeService => await exchangeService.GetBalance(Account, Config.Ticker));
|
||||
|
||||
if (tokenBalance == null || tokenBalance.Amount <= 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user