hedgequantx 2.9.122 → 2.9.123
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
|
@@ -98,6 +98,18 @@ class RithmicService extends EventEmitter {
|
|
|
98
98
|
|
|
99
99
|
await this.orderConn.connect(config);
|
|
100
100
|
this.orderConn.on('message', createOrderHandler(this));
|
|
101
|
+
|
|
102
|
+
// Auto-reconnect on disconnect
|
|
103
|
+
this.orderConn.on('disconnected', async ({ code, reason }) => {
|
|
104
|
+
log.warn('ORDER_PLANT disconnected', { code, reason });
|
|
105
|
+
this.emit('disconnected', { plant: 'ORDER', code, reason });
|
|
106
|
+
|
|
107
|
+
// Auto-reconnect if we have credentials (not manual disconnect)
|
|
108
|
+
if (this.credentials && code !== 1000) {
|
|
109
|
+
log.info('Attempting auto-reconnect in 3s...');
|
|
110
|
+
setTimeout(() => this._autoReconnect(), 3000);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
101
113
|
|
|
102
114
|
return new Promise((resolve) => {
|
|
103
115
|
const timeout = setTimeout(() => {
|
|
@@ -163,6 +175,13 @@ class RithmicService extends EventEmitter {
|
|
|
163
175
|
|
|
164
176
|
await this.pnlConn.connect(config);
|
|
165
177
|
this.pnlConn.on('message', createPnLHandler(this));
|
|
178
|
+
|
|
179
|
+
// Auto-reconnect PnL on disconnect
|
|
180
|
+
this.pnlConn.on('disconnected', ({ code }) => {
|
|
181
|
+
if (this.credentials && code !== 1000) {
|
|
182
|
+
setTimeout(() => this.connectPnL(this.credentials.username, this.credentials.password), 3000);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
166
185
|
|
|
167
186
|
return new Promise((resolve) => {
|
|
168
187
|
const timeout = setTimeout(() => resolve(false), TIMEOUTS.RITHMIC_PNL);
|
|
@@ -200,6 +219,13 @@ class RithmicService extends EventEmitter {
|
|
|
200
219
|
};
|
|
201
220
|
|
|
202
221
|
await this.tickerConn.connect(config);
|
|
222
|
+
|
|
223
|
+
// Auto-reconnect Ticker on disconnect
|
|
224
|
+
this.tickerConn.on('disconnected', ({ code }) => {
|
|
225
|
+
if (this.credentials && code !== 1000) {
|
|
226
|
+
setTimeout(() => this.connectTicker(this.credentials.username, this.credentials.password), 3000);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
203
229
|
|
|
204
230
|
return new Promise((resolve) => {
|
|
205
231
|
const timeout = setTimeout(() => {
|
|
@@ -383,9 +409,42 @@ class RithmicService extends EventEmitter {
|
|
|
383
409
|
return { isOpen: true, message: 'Market is open' };
|
|
384
410
|
}
|
|
385
411
|
|
|
412
|
+
// ==================== AUTO-RECONNECT ====================
|
|
413
|
+
|
|
414
|
+
async _autoReconnect() {
|
|
415
|
+
if (!this.credentials) {
|
|
416
|
+
log.warn('Cannot auto-reconnect: no credentials');
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const { username, password } = this.credentials;
|
|
421
|
+
log.info('Auto-reconnecting...');
|
|
422
|
+
this.emit('reconnecting');
|
|
423
|
+
|
|
424
|
+
try {
|
|
425
|
+
const result = await this.login(username, password);
|
|
426
|
+
if (result.success) {
|
|
427
|
+
log.info('Auto-reconnect successful');
|
|
428
|
+
this.emit('reconnected', { accounts: result.accounts });
|
|
429
|
+
} else {
|
|
430
|
+
log.warn('Auto-reconnect failed', { error: result.error });
|
|
431
|
+
this.emit('reconnectFailed', { error: result.error });
|
|
432
|
+
// Retry in 10s
|
|
433
|
+
setTimeout(() => this._autoReconnect(), 10000);
|
|
434
|
+
}
|
|
435
|
+
} catch (err) {
|
|
436
|
+
log.error('Auto-reconnect error', { error: err.message });
|
|
437
|
+
this.emit('reconnectFailed', { error: err.message });
|
|
438
|
+
// Retry in 10s
|
|
439
|
+
setTimeout(() => this._autoReconnect(), 10000);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
386
443
|
// ==================== CLEANUP ====================
|
|
387
444
|
|
|
388
445
|
async disconnect() {
|
|
446
|
+
// Clear credentials to prevent auto-reconnect on manual disconnect
|
|
447
|
+
this.credentials = null;
|
|
389
448
|
const connections = [this.orderConn, this.pnlConn, this.tickerConn];
|
|
390
449
|
|
|
391
450
|
for (const conn of connections) {
|