hedgequantx 2.6.136 → 2.6.138
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 +1 -1
- package/src/pages/algo/one-account.js +42 -14
package/package.json
CHANGED
|
@@ -1431,6 +1431,9 @@ const launchMultiSymbolRithmic = async (service, account, contracts, config) =>
|
|
|
1431
1431
|
// Calculate total qty across all symbols
|
|
1432
1432
|
const totalQty = contracts.reduce((sum, c) => sum + (c.qty || 1), 0);
|
|
1433
1433
|
|
|
1434
|
+
// Baseline P&L captured at session start (to show only THIS session's P&L)
|
|
1435
|
+
let baselineClosedPnl = null; // Will be set on first pnlUpdate
|
|
1436
|
+
|
|
1434
1437
|
// Shared stats (same structure as launchAlgo)
|
|
1435
1438
|
const stats = {
|
|
1436
1439
|
accountName,
|
|
@@ -1441,8 +1444,8 @@ const launchMultiSymbolRithmic = async (service, account, contracts, config) =>
|
|
|
1441
1444
|
propfirm: account.propfirm || 'Unknown',
|
|
1442
1445
|
platform: 'RITHMIC',
|
|
1443
1446
|
pnl: null,
|
|
1444
|
-
openPnl:
|
|
1445
|
-
closedPnl:
|
|
1447
|
+
openPnl: 0, // Start at 0 for session
|
|
1448
|
+
closedPnl: 0, // Start at 0 for session (will show delta from baseline)
|
|
1446
1449
|
balance: null,
|
|
1447
1450
|
buyingPower: null,
|
|
1448
1451
|
margin: null,
|
|
@@ -1839,29 +1842,45 @@ const launchMultiSymbolRithmic = async (service, account, contracts, config) =>
|
|
|
1839
1842
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
1840
1843
|
// TARGET/RISK CHECK - Stop algo when limits reached
|
|
1841
1844
|
// Uses SESSION P&L (trades from this HQX session only) + Open P&L
|
|
1842
|
-
//
|
|
1845
|
+
// Risk triggers if: closedPnl hits risk OR openPnl hits risk OR total hits risk
|
|
1843
1846
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
1844
1847
|
const checkTargetRisk = () => {
|
|
1845
1848
|
if (!running) return;
|
|
1846
1849
|
|
|
1847
|
-
|
|
1848
|
-
const
|
|
1850
|
+
const closedPnl = stats.closedPnl || 0; // Session closed P&L
|
|
1851
|
+
const openPnl = stats.openPnl || 0; // Current open P&L
|
|
1852
|
+
const totalPnl = closedPnl + openPnl; // Total session P&L
|
|
1849
1853
|
|
|
1850
1854
|
// Daily target reached - STOP with profit
|
|
1851
|
-
if (
|
|
1855
|
+
if (totalPnl >= dailyTarget) {
|
|
1852
1856
|
stopReason = 'target';
|
|
1853
1857
|
running = false;
|
|
1854
|
-
algoLogger.info(ui, 'TARGET REACHED', `+$${
|
|
1855
|
-
ui.addLog('success', `████ DAILY TARGET REACHED: +$${
|
|
1856
|
-
emergencyStopAll();
|
|
1858
|
+
algoLogger.info(ui, 'TARGET REACHED', `+$${totalPnl.toFixed(2)} >= $${dailyTarget}`);
|
|
1859
|
+
ui.addLog('success', `████ DAILY TARGET REACHED: +$${totalPnl.toFixed(2)} ████`);
|
|
1860
|
+
emergencyStopAll();
|
|
1861
|
+
return;
|
|
1857
1862
|
}
|
|
1863
|
+
|
|
1858
1864
|
// Max risk reached - STOP to protect capital
|
|
1859
|
-
|
|
1865
|
+
// Trigger if: closed P&L hits risk OR open P&L hits risk OR total hits risk
|
|
1866
|
+
if (closedPnl <= -maxRisk) {
|
|
1860
1867
|
stopReason = 'risk';
|
|
1861
1868
|
running = false;
|
|
1862
|
-
algoLogger.info(ui, '
|
|
1863
|
-
ui.addLog('error', `████ MAX RISK
|
|
1864
|
-
emergencyStopAll();
|
|
1869
|
+
algoLogger.info(ui, 'CLOSED P&L RISK', `Closed: -$${Math.abs(closedPnl).toFixed(2)} <= -$${maxRisk}`);
|
|
1870
|
+
ui.addLog('error', `████ MAX RISK (CLOSED): -$${Math.abs(closedPnl).toFixed(2)} ████`);
|
|
1871
|
+
emergencyStopAll();
|
|
1872
|
+
} else if (openPnl <= -maxRisk) {
|
|
1873
|
+
stopReason = 'risk';
|
|
1874
|
+
running = false;
|
|
1875
|
+
algoLogger.info(ui, 'OPEN P&L RISK', `Open: -$${Math.abs(openPnl).toFixed(2)} <= -$${maxRisk}`);
|
|
1876
|
+
ui.addLog('error', `████ MAX RISK (OPEN): -$${Math.abs(openPnl).toFixed(2)} ████`);
|
|
1877
|
+
emergencyStopAll();
|
|
1878
|
+
} else if (totalPnl <= -maxRisk) {
|
|
1879
|
+
stopReason = 'risk';
|
|
1880
|
+
running = false;
|
|
1881
|
+
algoLogger.info(ui, 'TOTAL P&L RISK', `Total: -$${Math.abs(totalPnl).toFixed(2)} <= -$${maxRisk}`);
|
|
1882
|
+
ui.addLog('error', `████ MAX RISK (TOTAL): -$${Math.abs(totalPnl).toFixed(2)} ████`);
|
|
1883
|
+
emergencyStopAll();
|
|
1865
1884
|
}
|
|
1866
1885
|
};
|
|
1867
1886
|
|
|
@@ -1874,7 +1893,16 @@ const launchMultiSymbolRithmic = async (service, account, contracts, config) =>
|
|
|
1874
1893
|
if (pnlData.accountId !== rithmicAccountId) return;
|
|
1875
1894
|
|
|
1876
1895
|
if (pnlData.closedPositionPnl !== undefined) {
|
|
1877
|
-
|
|
1896
|
+
const accountClosedPnl = parseFloat(pnlData.closedPositionPnl);
|
|
1897
|
+
|
|
1898
|
+
// Capture baseline on first update (P&L at session start)
|
|
1899
|
+
if (baselineClosedPnl === null) {
|
|
1900
|
+
baselineClosedPnl = accountClosedPnl;
|
|
1901
|
+
algoLogger.info(ui, 'SESSION START', `Baseline P&L: $${baselineClosedPnl.toFixed(2)}`);
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1904
|
+
// stats.closedPnl shows ONLY this session's closed P&L (delta from baseline)
|
|
1905
|
+
stats.closedPnl = accountClosedPnl - baselineClosedPnl;
|
|
1878
1906
|
}
|
|
1879
1907
|
if (pnlData.accountBalance !== undefined) {
|
|
1880
1908
|
stats.balance = parseFloat(pnlData.accountBalance);
|