Add exception for webhook + add gracefull time before market decrease
This commit is contained in:
@@ -28,6 +28,7 @@ public class TradingBotBase : ITradingBot
|
||||
public readonly ILogger<TradingBotBase> Logger;
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
private const int NEW_POSITION_GRACE_SECONDS = 45; // grace window before evaluating missing orders
|
||||
private const int CLOSE_POSITION_GRACE_MS = 20000; // grace window before closing position to allow broker processing (20 seconds)
|
||||
|
||||
public TradingBotConfig Config { get; set; }
|
||||
public Account Account { get; set; }
|
||||
@@ -1324,6 +1325,13 @@ public class TradingBotBase : ITradingBot
|
||||
isForBacktest: Config.IsForBacktest);
|
||||
try
|
||||
{
|
||||
// Grace period: give the broker time to process any ongoing close operations
|
||||
// Using ConfigureAwait(false) to ensure non-blocking operation
|
||||
if (!Config.IsForBacktest)
|
||||
{
|
||||
await Task.Delay(CLOSE_POSITION_GRACE_MS).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
Position closedPosition = null;
|
||||
await ServiceScopeHelpers.WithScopedServices<IExchangeService, IAccountService, ITradingService>(
|
||||
_scopeFactory, async (exchangeService, accountService, tradingService) =>
|
||||
|
||||
Reference in New Issue
Block a user