hedgequantx 2.6.134 → 2.6.136

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hedgequantx",
3
- "version": "2.6.134",
3
+ "version": "2.6.136",
4
4
  "description": "HedgeQuantX - Prop Futures Trading CLI",
5
5
  "main": "src/app.js",
6
6
  "bin": {
@@ -1838,26 +1838,29 @@ const launchMultiSymbolRithmic = async (service, account, contracts, config) =>
1838
1838
 
1839
1839
  // ═══════════════════════════════════════════════════════════════════════════
1840
1840
  // TARGET/RISK CHECK - Stop algo when limits reached
1841
+ // Uses SESSION P&L (trades from this HQX session only) + Open P&L
1842
+ // NOT account-wide closedPnl which includes all trades from today
1841
1843
  // ═══════════════════════════════════════════════════════════════════════════
1842
1844
  const checkTargetRisk = () => {
1843
1845
  if (!running) return;
1844
1846
 
1845
- const totalPnl = (stats.openPnl || 0) + (stats.closedPnl || 0);
1847
+ // Session P&L = closed trades from THIS session + current open P&L
1848
+ const sessionTotalPnl = (stats.sessionPnl || 0) + (stats.openPnl || 0);
1846
1849
 
1847
1850
  // Daily target reached - STOP with profit
1848
- if (totalPnl >= dailyTarget) {
1851
+ if (sessionTotalPnl >= dailyTarget) {
1849
1852
  stopReason = 'target';
1850
1853
  running = false;
1851
- algoLogger.info(ui, 'TARGET REACHED', `+$${totalPnl.toFixed(2)} >= $${dailyTarget}`);
1852
- ui.addLog('success', `████ DAILY TARGET REACHED: +$${totalPnl.toFixed(2)} ████`);
1854
+ algoLogger.info(ui, 'TARGET REACHED', `+$${sessionTotalPnl.toFixed(2)} >= $${dailyTarget}`);
1855
+ ui.addLog('success', `████ DAILY TARGET REACHED: +$${sessionTotalPnl.toFixed(2)} ████`);
1853
1856
  emergencyStopAll(); // Close all positions
1854
1857
  }
1855
1858
  // Max risk reached - STOP to protect capital
1856
- else if (totalPnl <= -maxRisk) {
1859
+ else if (sessionTotalPnl <= -maxRisk) {
1857
1860
  stopReason = 'risk';
1858
1861
  running = false;
1859
- algoLogger.info(ui, 'MAX RISK HIT', `-$${Math.abs(totalPnl).toFixed(2)} <= -$${maxRisk}`);
1860
- ui.addLog('error', `████ MAX RISK REACHED: -$${Math.abs(totalPnl).toFixed(2)} ████`);
1862
+ algoLogger.info(ui, 'MAX RISK HIT', `-$${Math.abs(sessionTotalPnl).toFixed(2)} <= -$${maxRisk}`);
1863
+ ui.addLog('error', `████ MAX RISK REACHED: -$${Math.abs(sessionTotalPnl).toFixed(2)} ████`);
1861
1864
  emergencyStopAll(); // Close all positions
1862
1865
  }
1863
1866
  };
@@ -1934,19 +1937,25 @@ const launchMultiSymbolRithmic = async (service, account, contracts, config) =>
1934
1937
  const emergencyStopAll = async () => {
1935
1938
  ui.addLog('warning', '████ EMERGENCY STOP ████');
1936
1939
 
1937
- // Close all positions
1938
- for (const [symbolName, pm] of Object.entries(positionManagers)) {
1939
- try {
1940
- if (pm.hasPosition(symbolName)) {
1941
- pm.closePosition(symbolName);
1942
- ui.addLog('info', `[${symbolName}] Closing position...`);
1940
+ try {
1941
+ // Use Rithmic emergencyStop to flatten all positions
1942
+ if (service && typeof service.emergencyStop === 'function') {
1943
+ await service.emergencyStop(rithmicAccountId);
1944
+ ui.addLog('info', 'Emergency stop executed - all positions flattened');
1945
+ } else if (service && typeof service.flattenAll === 'function') {
1946
+ await service.flattenAll(rithmicAccountId);
1947
+ ui.addLog('info', 'Flatten all executed - all positions closed');
1948
+ } else {
1949
+ // Fallback: cancel all orders
1950
+ if (service && typeof service.cancelAllOrders === 'function') {
1951
+ await service.cancelAllOrders(rithmicAccountId);
1952
+ ui.addLog('info', 'All orders cancelled');
1943
1953
  }
1944
- } catch (e) {
1945
- ui.addLog('error', `[${symbolName}] Close failed: ${e.message}`);
1946
1954
  }
1955
+ } catch (e) {
1956
+ ui.addLog('error', `Emergency stop error: ${e.message}`);
1947
1957
  }
1948
1958
 
1949
- ui.addLog('info', 'All close orders sent');
1950
1959
  ui.render(stats);
1951
1960
  };
1952
1961