hedgequantx 2.6.82 → 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 +1 -1
- package/src/pages/algo/one-account.js +44 -12
package/package.json
CHANGED
|
@@ -981,8 +981,8 @@ const launchAlgo = async (service, account, contract, config) => {
|
|
|
981
981
|
};
|
|
982
982
|
|
|
983
983
|
// Start polling and UI refresh
|
|
984
|
-
// UI refreshes every
|
|
985
|
-
const refreshInterval = setInterval(() => { if (running) ui.render(stats); },
|
|
984
|
+
// UI refreshes every 8ms (120 fps - ProMotion display support), P&L polling every 10s
|
|
985
|
+
const refreshInterval = setInterval(() => { if (running) ui.render(stats); }, 8);
|
|
986
986
|
const pnlInterval = setInterval(() => { if (running) pollPnL(); }, 10000);
|
|
987
987
|
pollPnL(); // Initial poll
|
|
988
988
|
|
|
@@ -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
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
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
|
-
}
|
|
1036
|
-
ui.addLog('
|
|
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();
|