Refactor SpotBot position history logging
- Updated SpotBot to log detailed information when a closing position is found in the history, including position direction and dates. - Enhanced logging for scenarios where no closing position is found or when position history is unavailable, improving clarity on position status. - Removed outdated log messages to streamline the logging process.
This commit is contained in:
@@ -510,23 +510,40 @@ public class SpotBot : TradingBotBase
|
||||
|
||||
if (positionHistory != null && positionHistory.Count != 0)
|
||||
{
|
||||
var recentPosition = positionHistory
|
||||
// Find a SELL/SHORT position that occurred AFTER our open position was created
|
||||
// This indicates our LONG position was closed
|
||||
var closingPosition = positionHistory
|
||||
.Where(p => p.OriginDirection == TradeDirection.Short &&
|
||||
p.Date >= position.Date)
|
||||
.OrderByDescending(p => p.Date)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (recentPosition != null)
|
||||
if (closingPosition != null)
|
||||
{
|
||||
await LogDebugAsync(
|
||||
$"✅ Spot Position Found in History\n" +
|
||||
$"✅ Closing Position Found in History\n" +
|
||||
$"Position: `{position.Identifier}`\n" +
|
||||
$"Ticker: `{recentPosition.Ticker}`\n" +
|
||||
$"Date: `{recentPosition.Date}`");
|
||||
$"Ticker: `{closingPosition.Ticker}`\n" +
|
||||
$"Direction: `{closingPosition.OriginDirection}` (SHORT = Sold/Closed)\n" +
|
||||
$"Date: `{closingPosition.Date}`\n" +
|
||||
$"Our Position Open Date: `{position.Date}`");
|
||||
return (true, false);
|
||||
}
|
||||
}
|
||||
|
||||
await LogDebugAsync(
|
||||
$"❌ No Spot Position Found in Exchange History\nPosition: `{position.Identifier}`\nPosition may still be open or data is delayed");
|
||||
$"ℹ️ No Closing Position Found in History\n" +
|
||||
$"Position: `{position.Identifier}`\n" +
|
||||
$"Found {positionHistory.Count} history entries but none indicate position was closed\n" +
|
||||
$"Position is likely still open");
|
||||
}
|
||||
else
|
||||
{
|
||||
await LogDebugAsync(
|
||||
$"ℹ️ No Position History Available\n" +
|
||||
$"Position: `{position.Identifier}`\n" +
|
||||
$"Position is likely still open");
|
||||
}
|
||||
|
||||
return (false, false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user