Fix .First Position update + add more details when position rejected
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -51,20 +51,6 @@ namespace Managing.Infrastructure.Exchanges
|
||||
reduceOnly ? TradeStatus.PendingOpen : TradeStatus.Filled);
|
||||
}
|
||||
|
||||
// Check gas fees for EVM exchanges before opening position
|
||||
if (IsEvmExchange(account))
|
||||
{
|
||||
var gasFeeUsd = await GetFee(account);
|
||||
if (gasFeeUsd > 0.5m)
|
||||
{
|
||||
_logger.LogWarning(
|
||||
$"Gas fee too high for position opening: {gasFeeUsd:F2} USD (threshold: 0.5 USD). Cancelling position opening.");
|
||||
|
||||
// Return a cancelled trade
|
||||
return BuildEmptyTrade(ticker, price, quantity, direction, leverage, tradeType, currentDate.Value,
|
||||
TradeStatus.Cancelled);
|
||||
}
|
||||
}
|
||||
|
||||
var processor = GetProcessor(account);
|
||||
return await processor.OpenTrade(account, ticker, direction, price, quantity, leverage, tradeType,
|
||||
|
||||
@@ -688,6 +688,7 @@ public class EvmManager : IEvmManager
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SentrySdk.CaptureException(ex);
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user