Enhance TradingBot logic to handle multiple open orders: added checks for order count and elapsed time before canceling unfilled positions.
This commit is contained in:
BIN
src/.DS_Store
vendored
BIN
src/.DS_Store
vendored
Binary file not shown.
@@ -440,8 +440,44 @@ public class TradingBot : Bot, ITradingBot
|
||||
var orders = await ExchangeService.GetOpenOrders(Account, Config.Ticker);
|
||||
if (orders.Any())
|
||||
{
|
||||
await LogInformation(
|
||||
$"Cannot update Position. Position is still waiting for opening. There is {orders.Count()} open orders.");
|
||||
// If there are 3 or more orders and position is still not filled, check if enough time has passed
|
||||
if (orders.Count() >= 3)
|
||||
{
|
||||
var currentTime = Config.IsForBacktest ? OptimizedCandles.Last().Date : DateTime.UtcNow;
|
||||
var timeSinceRequest = currentTime - positionForSignal.Open.Date;
|
||||
var waitTimeMinutes = 10;
|
||||
|
||||
if (timeSinceRequest.TotalMinutes >= waitTimeMinutes)
|
||||
{
|
||||
await LogWarning(
|
||||
$"Too many open orders ({orders.Count()}) for unfilled position and {waitTimeMinutes} minutes have passed. Canceling all orders and marking position as canceled.");
|
||||
|
||||
try
|
||||
{
|
||||
await ExchangeService.CancelOrder(Account, Config.Ticker);
|
||||
await LogInformation($"Successfully canceled all orders for {Config.Ticker}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await LogWarning($"Failed to cancel orders: {ex.Message}");
|
||||
}
|
||||
|
||||
await SetPositionStatus(signal.Identifier, PositionStatus.Canceled);
|
||||
SetSignalStatus(signal.Identifier, SignalStatus.Expired);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
var remainingMinutes = waitTimeMinutes - timeSinceRequest.TotalMinutes;
|
||||
await LogInformation(
|
||||
$"Position has {orders.Count()} open orders but only {timeSinceRequest.TotalMinutes:F1} minutes have passed. Waiting {remainingMinutes:F1} more minutes before canceling.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await LogInformation(
|
||||
$"Cannot update Position. Position is still waiting for opening. There is {orders.Count()} open orders.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
BIN
src/Managing.Nswag/.DS_Store
vendored
BIN
src/Managing.Nswag/.DS_Store
vendored
Binary file not shown.
BIN
src/Managing.Web3Proxy/.DS_Store
vendored
BIN
src/Managing.Web3Proxy/.DS_Store
vendored
Binary file not shown.
Reference in New Issue
Block a user