Fix cooldown
This commit is contained in:
@@ -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
|
// Grace period: give the broker time to register open orders before we evaluate
|
||||||
var now = Config.IsForBacktest ? (LastCandle?.Date ?? DateTime.UtcNow) : DateTime.UtcNow;
|
var now = Config.IsForBacktest ? (LastCandle?.Date ?? DateTime.UtcNow) : DateTime.UtcNow;
|
||||||
@@ -502,7 +502,8 @@ public class TradingBotBase : ITradingBot
|
|||||||
if (secondsSinceOpenRequest < NEW_POSITION_GRACE_SECONDS)
|
if (secondsSinceOpenRequest < NEW_POSITION_GRACE_SECONDS)
|
||||||
{
|
{
|
||||||
var remaining = NEW_POSITION_GRACE_SECONDS - secondsSinceOpenRequest;
|
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
|
return; // skip early checks until grace period elapses
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -644,7 +645,7 @@ public class TradingBotBase : ITradingBot
|
|||||||
await LogWarning(
|
await LogWarning(
|
||||||
$"❌ Position Confirmed Never Filled\nNo position in exchange history\nMarking as canceled without PnL processing");
|
$"❌ Position Confirmed Never Filled\nNo position in exchange history\nMarking as canceled without PnL processing");
|
||||||
}
|
}
|
||||||
|
|
||||||
SetSignalStatus(signal.Identifier, SignalStatus.Expired);
|
SetSignalStatus(signal.Identifier, SignalStatus.Expired);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1377,8 +1378,9 @@ public class TradingBotBase : ITradingBot
|
|||||||
|
|
||||||
// Skip the candle-based PnL calculation since we have actual GMX data
|
// Skip the candle-based PnL calculation since we have actual GMX data
|
||||||
goto SkipCandleBasedCalculation;
|
goto SkipCandleBasedCalculation;
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1762,21 +1764,24 @@ public class TradingBotBase : ITradingBot
|
|||||||
{
|
{
|
||||||
var position = Positions.Values.First(p => p.SignalIdentifier == signalIdentifier);
|
var position = Positions.Values.First(p => p.SignalIdentifier == signalIdentifier);
|
||||||
|
|
||||||
if (positionStatus.Equals(PositionStatus.Canceled)){
|
if (positionStatus.Equals(PositionStatus.Canceled))
|
||||||
var stackTrace = new StackTrace(true);
|
{
|
||||||
var callingMethod = stackTrace.GetFrame(1)?.GetMethod();
|
var stackTrace = new StackTrace(true);
|
||||||
var callingMethodName = callingMethod?.DeclaringType?.Name + "." + callingMethod?.Name;
|
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;
|
var exception =
|
||||||
exception.Data["PositionId"] = position.Identifier;
|
new InvalidOperationException(
|
||||||
exception.Data["CurrentStatus"] = position.Status.ToString();
|
$"Position {signalIdentifier} is already canceled for User {Account.User.Name}");
|
||||||
exception.Data["RequestedStatus"] = positionStatus.ToString();
|
exception.Data["SignalIdentifier"] = signalIdentifier;
|
||||||
exception.Data["AccountName"] = Account.Name;
|
exception.Data["PositionId"] = position.Identifier;
|
||||||
exception.Data["BotName"] = Config.Name;
|
exception.Data["CurrentStatus"] = position.Status.ToString();
|
||||||
exception.Data["CallingMethod"] = callingMethodName;
|
exception.Data["RequestedStatus"] = positionStatus.ToString();
|
||||||
exception.Data["CallStack"] = Environment.StackTrace;
|
exception.Data["AccountName"] = Account.Name;
|
||||||
SentrySdk.CaptureException(exception);
|
exception.Data["BotName"] = Config.Name;
|
||||||
|
exception.Data["CallingMethod"] = callingMethodName;
|
||||||
|
exception.Data["CallStack"] = Environment.StackTrace;
|
||||||
|
SentrySdk.CaptureException(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!position.Status.Equals(positionStatus))
|
if (!position.Status.Equals(positionStatus))
|
||||||
@@ -2360,7 +2365,7 @@ public class TradingBotBase : ITradingBot
|
|||||||
// Calculate cooldown end time based on last position closing time
|
// Calculate cooldown end time based on last position closing time
|
||||||
var baseIntervalSeconds = CandleHelpers.GetBaseIntervalInSeconds(Config.Timeframe);
|
var baseIntervalSeconds = CandleHelpers.GetBaseIntervalInSeconds(Config.Timeframe);
|
||||||
var cooldownEndTime = LastPositionClosingTime.Value.AddSeconds(baseIntervalSeconds * Config.CooldownPeriod);
|
var cooldownEndTime = LastPositionClosingTime.Value.AddSeconds(baseIntervalSeconds * Config.CooldownPeriod);
|
||||||
var isInCooldown = LastCandle.Date < cooldownEndTime;
|
var isInCooldown = (Config.IsForBacktest ? LastCandle.Date : DateTime.UtcNow) < cooldownEndTime;
|
||||||
|
|
||||||
if (isInCooldown)
|
if (isInCooldown)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user