Fix fetch and restart bot
This commit is contained in:
@@ -248,13 +248,21 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
|
||||
public async Task StopAsync()
|
||||
{
|
||||
// Check if bot has open positions in database before allowing stop
|
||||
var hasOpenPositions = await HasOpenPositionsInDatabaseAsync();
|
||||
if (hasOpenPositions)
|
||||
await StopAsyncInternal(false);
|
||||
}
|
||||
|
||||
private async Task StopAsyncInternal(bool isRestarting)
|
||||
{
|
||||
// Only check for open positions if this is not part of a restart operation
|
||||
if (!isRestarting)
|
||||
{
|
||||
_logger.LogWarning("Cannot stop LiveTradingBotGrain {GrainId} - bot has open positions in database",
|
||||
this.GetPrimaryKey());
|
||||
throw new InvalidOperationException("Cannot stop bot while it has open positions. Please close all positions first.");
|
||||
var hasOpenPositions = await HasOpenPositionsInDatabaseAsync();
|
||||
if (hasOpenPositions)
|
||||
{
|
||||
_logger.LogWarning("Cannot stop LiveTradingBotGrain {GrainId} - bot has open positions in database",
|
||||
this.GetPrimaryKey());
|
||||
throw new InvalidOperationException("Cannot stop bot while it has open positions. Please close all positions first.");
|
||||
}
|
||||
}
|
||||
|
||||
// The check is now against the registry status
|
||||
@@ -578,18 +586,10 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
{
|
||||
_logger.LogInformation("Restarting LiveTradingBotGrain {GrainId}", this.GetPrimaryKey());
|
||||
|
||||
// Check if bot has open positions in database before allowing restart
|
||||
var hasOpenPositions = await HasOpenPositionsInDatabaseAsync();
|
||||
if (hasOpenPositions)
|
||||
{
|
||||
_logger.LogWarning("Cannot restart LiveTradingBotGrain {GrainId} - bot has open positions in database",
|
||||
this.GetPrimaryKey());
|
||||
throw new InvalidOperationException("Cannot restart bot while it has open positions. Please close all positions first.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await StopAsync();
|
||||
// Use internal stop method that bypasses open position check for restart
|
||||
await StopAsyncInternal(true);
|
||||
|
||||
// Add a small delay to ensure stop operations complete
|
||||
await Task.Delay(100);
|
||||
|
||||
@@ -402,7 +402,7 @@ public class PostgreSqlTradingRepository : ITradingRepository
|
||||
entity.ProfitAndLoss = position.ProfitAndLoss?.Realized ?? 0;
|
||||
entity.NetPnL = position.ProfitAndLoss?.Net ?? 0;
|
||||
entity.UiFees = position.UiFees;
|
||||
entity.OriginDirection = position.OriginDirection;
|
||||
// entity.OriginDirection = position.OriginDirection;
|
||||
entity.GasFees = position.GasFees;
|
||||
entity.Status = position.Status;
|
||||
entity.MoneyManagementJson = position.MoneyManagement != null
|
||||
|
||||
@@ -349,7 +349,7 @@ 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);
|
||||
@@ -442,13 +442,15 @@ 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>();
|
||||
}
|
||||
|
||||
@@ -456,7 +458,8 @@ public class EvmManager : IEvmManager
|
||||
|
||||
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>();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user