fix: correct PnL math and add health probe

This commit is contained in:
mindesbunister
2025-11-05 07:58:27 +01:00
parent 02193b7dce
commit cbb6592153
4 changed files with 33 additions and 18 deletions

View File

@@ -519,15 +519,15 @@ export async function closePosition(
// Calculate realized P&L with leverage (default 10x in dry run)
const profitPercent = ((oraclePrice - position.entryPrice) / position.entryPrice) * 100 * (position.side === 'long' ? 1 : -1)
const leverage = 10 // Use 10x for dry run
const accountPnLPercent = profitPercent * leverage
const closedNotional = sizeToClose * oraclePrice
const realizedPnL = (closedNotional * accountPnLPercent) / 100
const realizedPnL = (closedNotional * profitPercent) / 100
const accountPnLPercent = profitPercent * 10 // display using default leverage
const mockTxSig = `DRY_RUN_CLOSE_${Date.now()}_${Math.random().toString(36).substring(7)}`
console.log(`💰 Simulated close:`)
console.log(` Close price: $${oraclePrice.toFixed(4)}`)
console.log(` Profit %: ${profitPercent.toFixed(3)}% → Account P&L (10x): ${accountPnLPercent.toFixed(2)}%`)
console.log(` Realized P&L: $${realizedPnL.toFixed(2)}`)
return {
@@ -584,11 +584,10 @@ export async function closePosition(
console.log('⚠️ Could not determine leverage from account, using 10x default')
}
const accountPnLPercent = profitPercent * leverage
// Calculate closed notional value (USD)
const closedNotional = sizeToClose * oraclePrice
const realizedPnL = (closedNotional * accountPnLPercent) / 100
const realizedPnL = (closedNotional * profitPercent) / 100
const accountPnLPercent = profitPercent * leverage
console.log(`💰 Close details:`)
console.log(` Close price: $${oraclePrice.toFixed(4)}`)