Fix cooldown

This commit is contained in:
2025-10-10 16:45:11 +07:00
parent 652c01b8bb
commit c618bca108

View File

@@ -494,7 +494,7 @@ public class TradingBotBase : ITradingBot
}
}
if (internalPosition.Status == PositionStatus.New)
if (internalPosition.Status == PositionStatus.New)
{
// Grace period: give the broker time to register open orders before we evaluate
var now = Config.IsForBacktest ? (LastCandle?.Date ?? DateTime.UtcNow) : DateTime.UtcNow;
@@ -502,7 +502,8 @@ public class TradingBotBase : ITradingBot
if (secondsSinceOpenRequest < NEW_POSITION_GRACE_SECONDS)
{
var remaining = NEW_POSITION_GRACE_SECONDS - secondsSinceOpenRequest;
await LogInformation($"⏳ Waiting for broker confirmation\nElapsed: `{secondsSinceOpenRequest:F0}s`\nGrace left: `{remaining:F0}s`");
await LogInformation(
$"⏳ Waiting for broker confirmation\nElapsed: `{secondsSinceOpenRequest:F0}s`\nGrace left: `{remaining:F0}s`");
return; // skip early checks until grace period elapses
}
@@ -1377,8 +1378,9 @@ public class TradingBotBase : ITradingBot
// Skip the candle-based PnL calculation since we have actual GMX data
goto SkipCandleBasedCalculation;
}else{
}
else
{
}
}
@@ -1762,21 +1764,24 @@ public class TradingBotBase : ITradingBot
{
var position = Positions.Values.First(p => p.SignalIdentifier == signalIdentifier);
if (positionStatus.Equals(PositionStatus.Canceled)){
var stackTrace = new StackTrace(true);
var callingMethod = stackTrace.GetFrame(1)?.GetMethod();
var callingMethodName = callingMethod?.DeclaringType?.Name + "." + callingMethod?.Name;
if (positionStatus.Equals(PositionStatus.Canceled))
{
var stackTrace = new StackTrace(true);
var callingMethod = stackTrace.GetFrame(1)?.GetMethod();
var callingMethodName = callingMethod?.DeclaringType?.Name + "." + callingMethod?.Name;
var exception = new InvalidOperationException($"Position {signalIdentifier} is already canceled for User {Account.User.Name}");
exception.Data["SignalIdentifier"] = signalIdentifier;
exception.Data["PositionId"] = position.Identifier;
exception.Data["CurrentStatus"] = position.Status.ToString();
exception.Data["RequestedStatus"] = positionStatus.ToString();
exception.Data["AccountName"] = Account.Name;
exception.Data["BotName"] = Config.Name;
exception.Data["CallingMethod"] = callingMethodName;
exception.Data["CallStack"] = Environment.StackTrace;
SentrySdk.CaptureException(exception);
var exception =
new InvalidOperationException(
$"Position {signalIdentifier} is already canceled for User {Account.User.Name}");
exception.Data["SignalIdentifier"] = signalIdentifier;
exception.Data["PositionId"] = position.Identifier;
exception.Data["CurrentStatus"] = position.Status.ToString();
exception.Data["RequestedStatus"] = positionStatus.ToString();
exception.Data["AccountName"] = Account.Name;
exception.Data["BotName"] = Config.Name;
exception.Data["CallingMethod"] = callingMethodName;
exception.Data["CallStack"] = Environment.StackTrace;
SentrySdk.CaptureException(exception);
}
if (!position.Status.Equals(positionStatus))
@@ -2360,7 +2365,7 @@ public class TradingBotBase : ITradingBot
// Calculate cooldown end time based on last position closing time
var baseIntervalSeconds = CandleHelpers.GetBaseIntervalInSeconds(Config.Timeframe);
var cooldownEndTime = LastPositionClosingTime.Value.AddSeconds(baseIntervalSeconds * Config.CooldownPeriod);
var isInCooldown = LastCandle.Date < cooldownEndTime;
var isInCooldown = (Config.IsForBacktest ? LastCandle.Date : DateTime.UtcNow) < cooldownEndTime;
if (isInCooldown)
{