hedgequantx 2.9.126 → 2.9.127

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.126",
3
+ "version": "2.9.127",
4
4
  "description": "HedgeQuantX - Prop Futures Trading CLI",
5
5
  "main": "src/app.js",
6
6
  "bin": {
@@ -172,11 +172,13 @@ class RithmicConnection extends EventEmitter {
172
172
 
173
173
  if (res.rpCode?.[0] === '0') {
174
174
  this.state = 'LOGGED_IN';
175
- this.startHeartbeat(res.heartbeatInterval || 60);
175
+ // Use heartbeat interval from server, minimum 10s, default 30s
176
+ const hbInterval = Math.max(10, res.heartbeatInterval || 30);
177
+ this.startHeartbeat(hbInterval);
176
178
  this.emit('loggedIn', {
177
179
  fcmId: res.fcmId,
178
180
  ibId: res.ibId,
179
- heartbeatInterval: res.heartbeatInterval,
181
+ heartbeatInterval: hbInterval,
180
182
  });
181
183
  } else {
182
184
  const errorCode = res.rpCode?.[0] || 'UNKNOWN';
@@ -202,13 +204,23 @@ class RithmicConnection extends EventEmitter {
202
204
 
203
205
  startHeartbeat(intervalSec) {
204
206
  this.stopHeartbeat();
207
+ // Send heartbeat at half the interval to be safe (minimum every 5 seconds)
208
+ const hbMs = Math.max(5000, Math.floor(intervalSec * 1000 / 2));
205
209
  this.heartbeatTimer = setInterval(() => {
206
210
  try {
207
- this.send('RequestHeartbeat', { templateId: REQ.HEARTBEAT });
211
+ if (this.ws?.readyState === WebSocket.OPEN) {
212
+ this.send('RequestHeartbeat', { templateId: REQ.HEARTBEAT });
213
+ }
208
214
  } catch (e) {
209
- // Ignore
215
+ // Ignore heartbeat errors
216
+ }
217
+ }, hbMs);
218
+ // Send first heartbeat immediately
219
+ try {
220
+ if (this.ws?.readyState === WebSocket.OPEN) {
221
+ this.send('RequestHeartbeat', { templateId: REQ.HEARTBEAT });
210
222
  }
211
- }, (intervalSec - 5) * 1000);
223
+ } catch (e) {}
212
224
  }
213
225
 
214
226
  stopHeartbeat() {