hedgequantx 2.6.44 → 2.6.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -379,17 +379,20 @@ const launchAlgo = async (service, account, contract, config) => {
|
|
|
379
379
|
// Only update for our account
|
|
380
380
|
if (pnlData.accountId !== rithmicAccountId) return;
|
|
381
381
|
|
|
382
|
-
//
|
|
383
|
-
|
|
382
|
+
// ACCOUNT_PNL_UPDATE (451) provides account-level totals
|
|
383
|
+
// closedPositionPnl = realized P&L from all closed trades today
|
|
384
384
|
const closedPnl = parseFloat(pnlData.closedPositionPnl || 0);
|
|
385
385
|
|
|
386
|
-
// Update
|
|
387
|
-
stats.
|
|
388
|
-
|
|
389
|
-
|
|
386
|
+
// Update closed P&L (realized) from account-level data
|
|
387
|
+
stats.closedPnl = closedPnl;
|
|
388
|
+
|
|
389
|
+
// Total P&L = openPnl (from positionUpdate) + closedPnl (from pnlUpdate)
|
|
390
|
+
// This matches R Trader's "Today's P&L" calculation
|
|
391
|
+
stats.pnl = (stats.openPnl || 0) + (stats.closedPnl || 0);
|
|
390
392
|
});
|
|
391
393
|
|
|
392
394
|
// Listen to position updates for real-time position tracking (like R Trader)
|
|
395
|
+
// INSTRUMENT_PNL_UPDATE (450) provides per-instrument P&L in real-time
|
|
393
396
|
service.on('positionUpdate', (pos) => {
|
|
394
397
|
if (!pos || pos.accountId !== rithmicAccountId) return;
|
|
395
398
|
if (pos.symbol !== symbolName && !pos.symbol?.includes(symbolName.replace(/[A-Z]\d+$/, ''))) return;
|
|
@@ -398,6 +401,17 @@ const launchAlgo = async (service, account, contract, config) => {
|
|
|
398
401
|
stats.position = pos.quantity || 0;
|
|
399
402
|
stats.entryPrice = pos.averagePrice || 0;
|
|
400
403
|
currentPosition = pos.quantity || 0;
|
|
404
|
+
|
|
405
|
+
// CRITICAL: Update Open P&L from instrument-level data (real-time, same as R Trader)
|
|
406
|
+
// pos.openPnl comes from INSTRUMENT_PNL_UPDATE (450) - this is the unrealized P&L
|
|
407
|
+
if (pos.openPnl !== undefined && pos.openPnl !== null) {
|
|
408
|
+
stats.openPnl = pos.openPnl;
|
|
409
|
+
}
|
|
410
|
+
// Update day P&L if available
|
|
411
|
+
if (pos.dayPnl !== undefined && pos.dayPnl !== null) {
|
|
412
|
+
// Total P&L = openPnl + closedPnl (same formula as R Trader)
|
|
413
|
+
stats.pnl = (stats.openPnl || 0) + (stats.closedPnl || 0);
|
|
414
|
+
}
|
|
401
415
|
});
|
|
402
416
|
|
|
403
417
|
// Initialize AI Strategy Supervisor - agents observe, learn & optimize
|