Fix .First Position update + add more details when position rejected

This commit is contained in:
2025-10-11 12:27:54 +07:00
parent 3b3e383781
commit 04df72a6bd
4 changed files with 13 additions and 19 deletions

View File

@@ -369,10 +369,8 @@ public class TradingBotBase : ITradingBot
// No existing position found, proceed to open a new one
var newlyCreatedPosition = await OpenPosition(signal);
if (newlyCreatedPosition != null)
{
Positions[newlyCreatedPosition.Identifier] = newlyCreatedPosition;
}
// Position is now added to Positions collection inside OpenPosition method
// No need to add it here again
}
}
@@ -996,6 +994,9 @@ public class TradingBotBase : ITradingBot
if (position != null)
{
// Add position to internal collection before any status updates
Positions[position.Identifier] = position;
if (position.Open.Status != TradeStatus.Cancelled && position.Status != PositionStatus.Rejected)
{
SetSignalStatus(signal.Identifier, SignalStatus.PositionOpen);
@@ -1011,6 +1012,7 @@ public class TradingBotBase : ITradingBot
}
else
{
SentrySdk.CaptureMessage("Position rejected", SentryLevel.Error);
await SetPositionStatus(signal.Identifier, PositionStatus.Rejected);
position.Status = PositionStatus.Rejected;
await UpdatePositionDatabase(position);
@@ -1768,7 +1770,7 @@ public class TradingBotBase : ITradingBot
{
var position = Positions.Values.First(p => p.SignalIdentifier == signalIdentifier);
if (positionStatus.Equals(PositionStatus.Canceled))
if (positionStatus.Equals(PositionStatus.Canceled | PositionStatus.Rejected))
{
var stackTrace = new StackTrace(true);
var callingMethod = stackTrace.GetFrame(1)?.GetMethod();

View File

@@ -125,6 +125,11 @@ namespace Managing.Application.Trading.Handlers
? position.Status
: PositionStatus.Rejected;
if (position.Status == PositionStatus.Rejected)
{
SentrySdk.CaptureException(new Exception($"Position {position.Identifier} for {request.SignalIdentifier} rejected"));
}
if (!request.IsForPaperTrading)
{
await tradingService.InsertPositionAsync(position);