Update SDK (#35)

* Update SDK for swap

* Fix web3proxy build

* Update types

* Fix swap

* Send token test and BASE transfer

* fix cache and hook

* Fix send

* Update health check with uiFeereceiver

* Fix sdk

* Fix get positions

* Fix timeoutloop

* Fix open position

* Fix closes positions

* Review
This commit is contained in:
Oda
2025-09-17 14:28:56 +07:00
committed by GitHub
parent 271dd70ad7
commit cee3902a4d
91 changed files with 21375 additions and 2831 deletions

View File

@@ -133,7 +133,8 @@ public class TradingBotBase : ITradingBot
{
// Add a small delay to ensure grain is fully activated
await Task.Delay(100);
LastCandle = await grain.GetLastCandle();
var lastCandles = await grain.GetLastCandle(1);
LastCandle = lastCandles.FirstOrDefault();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("invalid activation"))
{
@@ -143,7 +144,8 @@ public class TradingBotBase : ITradingBot
await Task.Delay(1000);
try
{
LastCandle = await grain.GetLastCandle();
var lastCandles = await grain.GetLastCandle(1);
LastCandle = lastCandles.FirstOrDefault();
}
catch (Exception retryEx)
{
@@ -1059,13 +1061,30 @@ public class TradingBotBase : ITradingBot
if (currentCandle != null)
{
List<Candle> recentCandles = null;
await ServiceScopeHelpers.WithScopedService<IExchangeService>(_scopeFactory, async exchangeService =>
if (Config.IsForBacktest)
{
recentCandles = Config.IsForBacktest
? (LastCandle != null ? new List<Candle>() { LastCandle } : new List<Candle>())
: (await exchangeService.GetCandlesInflux(TradingExchanges.Evm, Config.Ticker,
DateTime.UtcNow.AddHours(-4), Config.Timeframe)).ToList();
});
recentCandles = LastCandle != null ? new List<Candle>() { LastCandle } : new List<Candle>();
}
else
{
// Use CandleStoreGrain to get recent candles instead of calling exchange service directly
await ServiceScopeHelpers.WithScopedService<IGrainFactory>(_scopeFactory, async grainFactory =>
{
var grainKey = CandleHelpers.GetCandleStoreGrainKey(Account.Exchange, Config.Ticker, Config.Timeframe);
var grain = grainFactory.GetGrain<ICandleStoreGrain>(grainKey);
try
{
recentCandles = await grain.GetLastCandle(5);
}
catch (Exception ex)
{
Logger.LogError(ex, "Error retrieving recent candles from CandleStoreGrain for {GrainKey}", grainKey);
recentCandles = new List<Candle>();
}
});
}
// Check if we have any candles before proceeding
if (recentCandles == null || !recentCandles.Any())
@@ -1216,7 +1235,8 @@ public class TradingBotBase : ITradingBot
if (!Config.IsForBacktest)
{
await ServiceScopeHelpers.WithScopedService<IMessengerService>(_scopeFactory,
async messengerService => { await messengerService.SendClosingPosition(position); });
messengerService => { messengerService.SendClosingPosition(position);
return Task.CompletedTask; });
}
await CancelAllOrders();