Fix position status when checkbroker say no

This commit is contained in:
2025-10-06 21:35:48 +07:00
parent 746308bc4f
commit 51fbef6072

View File

@@ -1086,11 +1086,26 @@ public class TradingBotBase : ITradingBot
var reason = $"Cannot open position. There is already a position open for {Config.Ticker} on the broker."; var reason = $"Cannot open position. There is already a position open for {Config.Ticker} on the broker.";
if (previousPosition != null && orders.Count >= 2) if (previousPosition != null)
{
if (orders.Count >= 2)
{ {
await SetPositionStatus(previousPosition.SignalIdentifier, PositionStatus.Filled); await SetPositionStatus(previousPosition.SignalIdentifier, PositionStatus.Filled);
} }
else else
{
// Broker already has an open position, cancel the internally created (DB) position
await SetPositionStatus(previousPosition.SignalIdentifier, PositionStatus.Canceled);
if (!Config.IsForBacktest)
{
await UpdatePositionDatabase(previousPosition);
}
reason +=
" Position open on broker; internal position has been marked as Canceled.";
}
}
else
{ {
reason += reason +=
" Position open on broker but not enough orders or no previous position internally saved by the bot"; " Position open on broker but not enough orders or no previous position internally saved by the bot";