From 554cac7d898e58a0e5e982baef0e238e7c76f21b Mon Sep 17 00:00:00 2001 From: cryptooda Date: Fri, 24 Oct 2025 02:41:40 +0700 Subject: [PATCH] Check direction of the position before updating the broker position --- src/Managing.Application/Bots/TradingBotBase.cs | 5 +++-- src/Managing.Application/Users/UserService.cs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Managing.Application/Bots/TradingBotBase.cs b/src/Managing.Application/Bots/TradingBotBase.cs index 0b1ff44f..9e4a6397 100644 --- a/src/Managing.Application/Bots/TradingBotBase.cs +++ b/src/Managing.Application/Bots/TradingBotBase.cs @@ -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; diff --git a/src/Managing.Application/Users/UserService.cs b/src/Managing.Application/Users/UserService.cs index 4230ad7e..ce14fade 100644 --- a/src/Managing.Application/Users/UserService.cs +++ b/src/Managing.Application/Users/UserService.cs @@ -56,9 +56,10 @@ public class UserService : IUserService if (!_authorizedAddresses.Any(a => string.Equals(a, recoveredAddress, StringComparison.OrdinalIgnoreCase))) { - throw new Exception($"Address {recoveredAddress} not authorized"); + throw new Exception($"Address {recoveredAddress} not authorized. Please wait for team approval."); } + if (recoveredAddress == null || !recoveredAddress.Equals(address)) { throw new Exception($"Address {recoveredAddress} not corresponding");