hedgequantx 2.9.249 → 2.9.250

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.9.249",
3
+ "version": "2.9.250",
4
4
  "description": "HedgeQuantX - Prop Futures Trading CLI",
5
5
  "main": "src/app.js",
6
6
  "bin": {
@@ -119,30 +119,33 @@ const executeAlgo = async ({ service, account, contract, config, strategy: strat
119
119
  ui.addLog('system', 'Connecting to market data...');
120
120
 
121
121
  // Listen for position updates from Rithmic (external closes, manual trades)
122
+ // Only if service supports events (RithmicService or DaemonProxyService)
122
123
  const accId = account.rithmicAccountId || account.accountId;
123
- service.on('positionUpdate', (pos) => {
124
- // Match by account and symbol
125
- const posSymbol = pos.contractId || pos.symbol || '';
126
- const matchesSymbol = posSymbol.includes(contract.name) || posSymbol.includes(contractId) ||
127
- posSymbol === symbolCode || contractId.includes(posSymbol);
128
- const matchesAccount = pos.accountId === accId || pos.accountId === account.accountId;
129
-
130
- if (matchesSymbol && matchesAccount) {
131
- const qty = parseInt(pos.quantity) || 0;
132
- if (!isNaN(qty) && Math.abs(qty) < 1000 && qty !== currentPosition) {
133
- const oldPos = currentPosition;
134
- currentPosition = qty;
135
- if (qty === 0 && oldPos !== 0) {
136
- ui.addLog('trade', `Position closed externally (was ${oldPos})`);
137
- sessionLogger.log('POSITION', `External close: ${oldPos} -> 0`);
138
- pendingOrder = false; // Reset pending order flag
139
- } else if (qty !== 0 && oldPos === 0) {
140
- ui.addLog('trade', `Position opened externally: ${qty}`);
141
- sessionLogger.log('POSITION', `External open: 0 -> ${qty}`);
124
+ if (typeof service.on === 'function') {
125
+ service.on('positionUpdate', (pos) => {
126
+ // Match by account and symbol
127
+ const posSymbol = pos.contractId || pos.symbol || '';
128
+ const matchesSymbol = posSymbol.includes(contract.name) || posSymbol.includes(contractId) ||
129
+ posSymbol === symbolCode || contractId.includes(posSymbol);
130
+ const matchesAccount = pos.accountId === accId || pos.accountId === account.accountId;
131
+
132
+ if (matchesSymbol && matchesAccount) {
133
+ const qty = parseInt(pos.quantity) || 0;
134
+ if (!isNaN(qty) && Math.abs(qty) < 1000 && qty !== currentPosition) {
135
+ const oldPos = currentPosition;
136
+ currentPosition = qty;
137
+ if (qty === 0 && oldPos !== 0) {
138
+ ui.addLog('trade', `Position closed externally (was ${oldPos})`);
139
+ sessionLogger.log('POSITION', `External close: ${oldPos} -> 0`);
140
+ pendingOrder = false; // Reset pending order flag
141
+ } else if (qty !== 0 && oldPos === 0) {
142
+ ui.addLog('trade', `Position opened externally: ${qty}`);
143
+ sessionLogger.log('POSITION', `External open: 0 -> ${qty}`);
144
+ }
142
145
  }
143
146
  }
144
- }
145
- });
147
+ });
148
+ }
146
149
 
147
150
  strategy.on('signal', async (signal) => {
148
151
  const dir = signal.direction?.toUpperCase() || 'UNKNOWN';