Update SpotBot PNL calculation and enhance documentation guidelines
- Added logic to calculate broker PNL when it is zero or invalid, using actual prices for more accurate profit and loss reporting. - Improved logging to provide detailed information when PNL is calculated, enhancing visibility into trading performance. - Updated documentation guidelines to discourage unnecessary .md files unless explicitly requested by users.
This commit is contained in:
@@ -984,6 +984,23 @@ public class SpotBot : TradingBotBase
|
||||
var totalBotFees = position.GasFees + position.UiFees;
|
||||
var brokerRealizedPnl = brokerPosition.ProfitAndLoss.Realized;
|
||||
|
||||
// If broker PNL is 0 or invalid, calculate it ourselves using actual prices
|
||||
if (brokerRealizedPnl == 0 && brokerPosition.Open != null)
|
||||
{
|
||||
var entryPrice = position.Open.Price;
|
||||
var exitPrice = brokerPosition.Open.Price;
|
||||
var quantity = position.Open.Quantity;
|
||||
|
||||
// Calculate PNL: (exitPrice - entryPrice) * quantity for LONG
|
||||
brokerRealizedPnl = TradingBox.CalculatePnL(entryPrice, exitPrice, quantity, 1, position.OriginDirection);
|
||||
|
||||
await LogDebugAsync(
|
||||
$"⚠️ Broker PNL was 0, calculated from prices\n" +
|
||||
$"Entry Price: `${entryPrice:F2}` | Exit Price: `${exitPrice:F2}`\n" +
|
||||
$"Quantity: `{quantity:F8}`\n" +
|
||||
$"Calculated PNL: `${brokerRealizedPnl:F2}`");
|
||||
}
|
||||
|
||||
position.ProfitAndLoss = new ProfitAndLoss
|
||||
{
|
||||
Realized = brokerRealizedPnl,
|
||||
|
||||
Reference in New Issue
Block a user