Fix fetch and restart bot

This commit is contained in:
2025-10-04 18:31:50 +07:00
parent 15eba0fc3c
commit 343b85dada
3 changed files with 30 additions and 27 deletions

View File

@@ -184,7 +184,7 @@ public class EvmManager : IEvmManager
public async Task<List<EvmBalance>> GetAllBalances(Chain chain, string publicAddress)
{
var cacheKey = $"balances_{chain.Name}_{publicAddress.ToLowerInvariant()}";
// Try to get from cache first
var cachedBalances = _cacheService.GetValue<List<EvmBalance>>(cacheKey);
if (cachedBalances != null)
@@ -194,7 +194,7 @@ public class EvmManager : IEvmManager
// If not in cache, fetch from blockchain
var balances = new List<EvmBalance>();
foreach (var ticker in TokenService.GetEligibleTickersForBalance())
{
try
@@ -349,14 +349,14 @@ public class EvmManager : IEvmManager
{
// Define the assets and chains we want to query
var assets = new[] { Ticker.USDC, Ticker.ETH };
var chains = new[] { "arbitrum", "ethereum" };
var chains = new[] { "arbitrum" };
// Get balances from Web3Proxy service
var balances = await _web3ProxyService.GetWalletBalanceAsync(publicAddress, assets, chains);
// Convert Balance objects to EvmBalance objects
var evmBalances = new List<EvmBalance>();
foreach (var balance in balances)
{
if (balance.Amount > 0)
@@ -395,7 +395,7 @@ public class EvmManager : IEvmManager
{
// Log the exception and fallback to original implementation if Web3Proxy fails
Console.WriteLine($"Web3Proxy balance retrieval failed: {ex.Message}");
var chainBalances = new List<EvmBalance>();
var chains = ChainService.GetChains();
@@ -442,24 +442,27 @@ public class EvmManager : IEvmManager
if (gmxPrices == null)
{
Console.WriteLine($"Warning: GMX API returned null for ticker {ticker}, timeframe {timeframe}, startDate {startDate:yyyy-MM-dd HH:mm:ss}");
Console.WriteLine(
$"Warning: GMX API returned null for ticker {ticker}, timeframe {timeframe}, startDate {startDate:yyyy-MM-dd HH:mm:ss}");
return new List<Candle>();
}
if (gmxPrices.Candles == null || !gmxPrices.Candles.Any())
{
Console.WriteLine($"Warning: GMX API returned empty candles array for ticker {ticker}, timeframe {timeframe}, startDate {startDate:yyyy-MM-dd HH:mm:ss}");
Console.WriteLine(
$"Warning: GMX API returned empty candles array for ticker {ticker}, timeframe {timeframe}, startDate {startDate:yyyy-MM-dd HH:mm:ss}");
return new List<Candle>();
}
var filteredCandles = gmxPrices.Candles.Where(p => p[0] >= startDate.AddMinutes(-1).ToUnixTimestamp()).ToList();
if (!filteredCandles.Any())
{
Console.WriteLine($"Warning: No candles found after filtering for ticker {ticker}, timeframe {timeframe}, startDate {startDate:yyyy-MM-dd HH:mm:ss}. Total candles before filtering: {gmxPrices.Candles.Count}");
Console.WriteLine(
$"Warning: No candles found after filtering for ticker {ticker}, timeframe {timeframe}, startDate {startDate:yyyy-MM-dd HH:mm:ss}. Total candles before filtering: {gmxPrices.Candles.Count}");
return new List<Candle>();
}
var candles = new List<Candle>();
var timeBetweenCandles = CandleHelpers.GetBaseIntervalInSeconds(timeframe);