Check direction of the position before updating the broker position

This commit is contained in:
2025-10-24 02:41:40 +07:00
parent 4489c57f55
commit 554cac7d89
2 changed files with 5 additions and 3 deletions

View File

@@ -402,7 +402,8 @@ public class TradingBotBase : ITradingBot
if (!Config.IsForBacktest)
{
var brokerPosition = brokerPositions.FirstOrDefault(p => p.Ticker == Config.Ticker);
var brokerPosition = brokerPositions.FirstOrDefault(p =>
p.Ticker == Config.Ticker && p.OriginDirection == positionForSignal.OriginDirection);
if (brokerPosition != null)
{
var previousPositionStatus = internalPosition.Status;
@@ -1164,7 +1165,7 @@ public class TradingBotBase : ITradingBot
}
await LogInformation(
$"🔧 Closing Trade\nTicker: `{Config.Ticker}`\nPrice: `${lastPrice}`\n📋 Type: `{tradeToClose.TradeType}`\n📊 Quantity: `{tradeToClose.Quantity:F5}`");
$"🔧 Closing {position.OriginDirection} Trade\nTicker: `{Config.Ticker}`\nPrice: `${lastPrice}`\n📋 Type: `{tradeToClose.TradeType}`\n📊 Quantity: `{tradeToClose.Quantity:F5}`");
decimal quantity = 0;