hedgequantx 2.6.83 → 2.6.84

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.83",
3
+ "version": "2.6.84",
4
4
  "description": "HedgeQuantX - Prop Futures Trading CLI",
5
5
  "main": "src/app.js",
6
6
  "bin": {
@@ -1023,20 +1023,52 @@ const launchAlgo = async (service, account, contract, config) => {
1023
1023
  clearInterval(pnlInterval);
1024
1024
 
1025
1025
  // EMERGENCY STOP: Cancel all orders and flatten all positions
1026
- if (useFastPath && service && account.rithmicAccountId) {
1027
- try {
1028
- ui.addLog('warning', 'EMERGENCY STOP - Cancelling orders & flattening positions...');
1029
- const stopResult = await service.emergencyStop(account.rithmicAccountId);
1030
- if (stopResult.success) {
1031
- ui.addLog('success', 'All orders cancelled, positions flattened');
1032
- } else {
1033
- ui.addLog('error', 'Emergency stop partial - check positions manually');
1026
+ // Works for BOTH Rithmic (fast path) and ProjectX (slow path)
1027
+ ui.addLog('warning', 'STOPPING - Cancelling orders & flattening positions...');
1028
+ ui.render(stats); // Force render to show message
1029
+
1030
+ try {
1031
+ const accountId = account.rithmicAccountId || account.accountId;
1032
+
1033
+ // 1. Cancel ALL open orders first
1034
+ if (typeof service.cancelAllOrders === 'function') {
1035
+ await service.cancelAllOrders(accountId);
1036
+ ui.addLog('info', 'All orders cancelled');
1037
+ }
1038
+
1039
+ // 2. Flatten position if we have one
1040
+ if (currentPosition !== 0 || stats.position !== 0) {
1041
+ const posQty = Math.abs(currentPosition || stats.position);
1042
+ const closeSide = (currentPosition || stats.position) > 0 ? 1 : 0; // 1=Sell to close long, 0=Buy to close short
1043
+
1044
+ // Try emergency stop first (Rithmic)
1045
+ if (typeof service.emergencyStop === 'function') {
1046
+ const stopResult = await service.emergencyStop(accountId);
1047
+ if (stopResult.success) {
1048
+ ui.addLog('success', 'Position flattened (emergency stop)');
1049
+ }
1050
+ }
1051
+ // Fallback: place market order to close (ProjectX)
1052
+ else if (typeof service.placeOrder === 'function') {
1053
+ await service.placeOrder({
1054
+ accountId: account.accountId,
1055
+ contractId: contractId,
1056
+ type: 2, // Market order
1057
+ side: closeSide,
1058
+ size: posQty
1059
+ });
1060
+ ui.addLog('success', `Position flattened (market order ${posQty}x)`);
1034
1061
  }
1035
- } catch (e) {
1036
- ui.addLog('error', `Emergency stop failed: ${e.message}`);
1062
+ } else {
1063
+ ui.addLog('success', 'No open position - clean exit');
1037
1064
  }
1065
+ } catch (e) {
1066
+ ui.addLog('error', `Emergency stop error: ${e.message}`);
1067
+ ui.addLog('warning', 'CHECK POSITIONS MANUALLY!');
1038
1068
  }
1039
1069
 
1070
+ ui.render(stats); // Force render to show final status
1071
+
1040
1072
  // Stop Position Manager (fast path)
1041
1073
  if (positionManager) {
1042
1074
  positionManager.stop();