hedgequantx 1.2.50 → 1.2.53
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/app.js +2 -1
- package/src/pages/stats.js +23 -17
- package/src/services/rithmic/index.js +133 -0
- package/src/services/session.js +50 -6
- package/src/services/tradovate/index.js +102 -0
package/package.json
CHANGED
package/src/app.js
CHANGED
|
@@ -158,9 +158,10 @@ const loginPrompt = async (propfirmName) => {
|
|
|
158
158
|
}
|
|
159
159
|
},
|
|
160
160
|
{
|
|
161
|
-
type: '
|
|
161
|
+
type: 'password',
|
|
162
162
|
name: 'password',
|
|
163
163
|
message: chalk.white.bold('Password:'),
|
|
164
|
+
mask: '*',
|
|
164
165
|
validate: (input) => {
|
|
165
166
|
try {
|
|
166
167
|
validatePassword(input);
|
package/src/pages/stats.js
CHANGED
|
@@ -117,27 +117,33 @@ const showStats = async (service) => {
|
|
|
117
117
|
const ordResult = await svc.getOrders(account.accountId);
|
|
118
118
|
if (ordResult.success) totalOpenOrders += ordResult.orders.filter(o => o.status === 1).length;
|
|
119
119
|
|
|
120
|
-
// Lifetime stats
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
120
|
+
// Lifetime stats (if available)
|
|
121
|
+
if (typeof svc.getLifetimeStats === 'function') {
|
|
122
|
+
const lifetimeResult = await svc.getLifetimeStats(account.accountId);
|
|
123
|
+
if (lifetimeResult.success && lifetimeResult.stats) {
|
|
124
|
+
account.lifetimeStats = lifetimeResult.stats;
|
|
125
|
+
}
|
|
124
126
|
}
|
|
125
127
|
|
|
126
|
-
// Daily stats
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
// Daily stats (if available)
|
|
129
|
+
if (typeof svc.getDailyStats === 'function') {
|
|
130
|
+
const dailyResult = await svc.getDailyStats(account.accountId);
|
|
131
|
+
if (dailyResult.success && dailyResult.stats) {
|
|
132
|
+
account.dailyStats = dailyResult.stats;
|
|
133
|
+
allDailyStats = allDailyStats.concat(dailyResult.stats);
|
|
134
|
+
}
|
|
131
135
|
}
|
|
132
136
|
|
|
133
|
-
// Trade history
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
// Trade history (if available)
|
|
138
|
+
if (typeof svc.getTradeHistory === 'function') {
|
|
139
|
+
const tradesResult = await svc.getTradeHistory(account.accountId, 30);
|
|
140
|
+
if (tradesResult.success && tradesResult.trades.length > 0) {
|
|
141
|
+
allTrades = allTrades.concat(tradesResult.trades.map(t => ({
|
|
142
|
+
...t,
|
|
143
|
+
accountName: account.accountName,
|
|
144
|
+
propfirm: account.propfirm
|
|
145
|
+
})));
|
|
146
|
+
}
|
|
141
147
|
}
|
|
142
148
|
}
|
|
143
149
|
|
|
@@ -578,6 +578,139 @@ class RithmicService extends EventEmitter {
|
|
|
578
578
|
});
|
|
579
579
|
}
|
|
580
580
|
|
|
581
|
+
/**
|
|
582
|
+
* Get lifetime stats (stub for Rithmic - not available via API)
|
|
583
|
+
*/
|
|
584
|
+
async getLifetimeStats(accountId) {
|
|
585
|
+
return { success: true, stats: null };
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Get daily stats (stub for Rithmic - not available via API)
|
|
590
|
+
*/
|
|
591
|
+
async getDailyStats(accountId) {
|
|
592
|
+
return { success: true, stats: [] };
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Get trade history (stub for Rithmic)
|
|
597
|
+
*/
|
|
598
|
+
async getTradeHistory(accountId, days = 30) {
|
|
599
|
+
return { success: true, trades: [] };
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Get market status
|
|
604
|
+
*/
|
|
605
|
+
async getMarketStatus(accountId) {
|
|
606
|
+
const marketHours = this.checkMarketHours();
|
|
607
|
+
return {
|
|
608
|
+
success: true,
|
|
609
|
+
isOpen: marketHours.isOpen,
|
|
610
|
+
message: marketHours.message,
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Get token (stub - Rithmic uses WebSocket, not tokens)
|
|
616
|
+
*/
|
|
617
|
+
getToken() {
|
|
618
|
+
return this.loginInfo ? 'connected' : null;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Search contracts (stub - would need TICKER_PLANT)
|
|
623
|
+
*/
|
|
624
|
+
async searchContracts(searchText) {
|
|
625
|
+
// Common futures contracts
|
|
626
|
+
const contracts = [
|
|
627
|
+
{ symbol: 'ESH5', name: 'E-mini S&P 500 Mar 2025', exchange: 'CME' },
|
|
628
|
+
{ symbol: 'NQH5', name: 'E-mini NASDAQ-100 Mar 2025', exchange: 'CME' },
|
|
629
|
+
{ symbol: 'CLH5', name: 'Crude Oil Mar 2025', exchange: 'NYMEX' },
|
|
630
|
+
{ symbol: 'GCG5', name: 'Gold Feb 2025', exchange: 'COMEX' },
|
|
631
|
+
{ symbol: 'MESH5', name: 'Micro E-mini S&P 500 Mar 2025', exchange: 'CME' },
|
|
632
|
+
{ symbol: 'MNQH5', name: 'Micro E-mini NASDAQ-100 Mar 2025', exchange: 'CME' },
|
|
633
|
+
];
|
|
634
|
+
const search = searchText.toUpperCase();
|
|
635
|
+
return contracts.filter(c => c.symbol.includes(search) || c.name.toUpperCase().includes(search));
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Place order via ORDER_PLANT
|
|
640
|
+
*/
|
|
641
|
+
async placeOrder(orderData) {
|
|
642
|
+
if (!this.orderConn || !this.loginInfo) {
|
|
643
|
+
return { success: false, error: 'Not connected' };
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
try {
|
|
647
|
+
this.orderConn.send('RequestNewOrder', {
|
|
648
|
+
templateId: REQ.NEW_ORDER,
|
|
649
|
+
userMsg: ['HQX'],
|
|
650
|
+
fcmId: this.loginInfo.fcmId,
|
|
651
|
+
ibId: this.loginInfo.ibId,
|
|
652
|
+
accountId: orderData.accountId,
|
|
653
|
+
symbol: orderData.symbol,
|
|
654
|
+
exchange: orderData.exchange || 'CME',
|
|
655
|
+
quantity: orderData.size,
|
|
656
|
+
transactionType: orderData.side === 0 ? 1 : 2, // 1=Buy, 2=Sell
|
|
657
|
+
duration: 1, // DAY
|
|
658
|
+
orderType: orderData.type === 2 ? 1 : 2, // 1=Market, 2=Limit
|
|
659
|
+
price: orderData.price || 0,
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
return { success: true, message: 'Order submitted' };
|
|
663
|
+
} catch (error) {
|
|
664
|
+
return { success: false, error: error.message };
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Cancel order
|
|
670
|
+
*/
|
|
671
|
+
async cancelOrder(orderId) {
|
|
672
|
+
if (!this.orderConn || !this.loginInfo) {
|
|
673
|
+
return { success: false, error: 'Not connected' };
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
try {
|
|
677
|
+
this.orderConn.send('RequestCancelOrder', {
|
|
678
|
+
templateId: REQ.CANCEL_ORDER,
|
|
679
|
+
userMsg: ['HQX'],
|
|
680
|
+
fcmId: this.loginInfo.fcmId,
|
|
681
|
+
ibId: this.loginInfo.ibId,
|
|
682
|
+
orderId: orderId,
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
return { success: true };
|
|
686
|
+
} catch (error) {
|
|
687
|
+
return { success: false, error: error.message };
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Close position (market order to flatten)
|
|
693
|
+
*/
|
|
694
|
+
async closePosition(accountId, symbol) {
|
|
695
|
+
// Get current position
|
|
696
|
+
const positions = Array.from(this.positions.values());
|
|
697
|
+
const position = positions.find(p => p.accountId === accountId && p.symbol === symbol);
|
|
698
|
+
|
|
699
|
+
if (!position) {
|
|
700
|
+
return { success: false, error: 'Position not found' };
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// Place opposite order
|
|
704
|
+
return this.placeOrder({
|
|
705
|
+
accountId,
|
|
706
|
+
symbol,
|
|
707
|
+
exchange: position.exchange,
|
|
708
|
+
size: Math.abs(position.quantity),
|
|
709
|
+
side: position.quantity > 0 ? 1 : 0, // Sell if long, Buy if short
|
|
710
|
+
type: 2, // Market
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
|
|
581
714
|
/**
|
|
582
715
|
* Get order history
|
|
583
716
|
* Uses RequestShowOrderHistorySummary (template 324)
|
package/src/services/session.js
CHANGED
|
@@ -8,6 +8,8 @@ const path = require('path');
|
|
|
8
8
|
const os = require('os');
|
|
9
9
|
const { encrypt, decrypt, maskSensitive } = require('../security');
|
|
10
10
|
const { ProjectXService } = require('./projectx');
|
|
11
|
+
const { RithmicService } = require('./rithmic');
|
|
12
|
+
const { TradovateService } = require('./tradovate');
|
|
11
13
|
|
|
12
14
|
const SESSION_DIR = path.join(os.homedir(), '.hedgequantx');
|
|
13
15
|
const SESSION_FILE = path.join(SESSION_DIR, 'session.enc');
|
|
@@ -107,11 +109,22 @@ const connections = {
|
|
|
107
109
|
* Saves all sessions to encrypted storage
|
|
108
110
|
*/
|
|
109
111
|
saveToStorage() {
|
|
110
|
-
const sessions = this.services.map(conn =>
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
const sessions = this.services.map(conn => {
|
|
113
|
+
const session = {
|
|
114
|
+
type: conn.type,
|
|
115
|
+
propfirm: conn.propfirm,
|
|
116
|
+
propfirmKey: conn.service.propfirmKey || conn.propfirmKey,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
if (conn.type === 'projectx') {
|
|
120
|
+
session.token = conn.service.token || conn.token;
|
|
121
|
+
} else if (conn.type === 'rithmic' || conn.type === 'tradovate') {
|
|
122
|
+
// Save encrypted credentials for reconnection
|
|
123
|
+
session.credentials = conn.service.credentials;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return session;
|
|
127
|
+
});
|
|
115
128
|
storage.save(sessions);
|
|
116
129
|
},
|
|
117
130
|
|
|
@@ -125,7 +138,7 @@ const connections = {
|
|
|
125
138
|
for (const session of sessions) {
|
|
126
139
|
try {
|
|
127
140
|
if (session.type === 'projectx' && session.token) {
|
|
128
|
-
const propfirmKey = session.propfirm.toLowerCase().replace(/ /g, '_');
|
|
141
|
+
const propfirmKey = session.propfirmKey || session.propfirm.toLowerCase().replace(/ /g, '_');
|
|
129
142
|
const service = new ProjectXService(propfirmKey);
|
|
130
143
|
service.token = session.token;
|
|
131
144
|
|
|
@@ -136,10 +149,41 @@ const connections = {
|
|
|
136
149
|
type: session.type,
|
|
137
150
|
service,
|
|
138
151
|
propfirm: session.propfirm,
|
|
152
|
+
propfirmKey: propfirmKey,
|
|
139
153
|
token: session.token,
|
|
140
154
|
connectedAt: new Date()
|
|
141
155
|
});
|
|
142
156
|
}
|
|
157
|
+
} else if (session.type === 'rithmic' && session.credentials) {
|
|
158
|
+
const propfirmKey = session.propfirmKey || 'apex_rithmic';
|
|
159
|
+
const service = new RithmicService(propfirmKey);
|
|
160
|
+
|
|
161
|
+
// Try to reconnect
|
|
162
|
+
const result = await service.login(session.credentials.username, session.credentials.password);
|
|
163
|
+
if (result.success) {
|
|
164
|
+
this.services.push({
|
|
165
|
+
type: session.type,
|
|
166
|
+
service,
|
|
167
|
+
propfirm: session.propfirm,
|
|
168
|
+
propfirmKey: propfirmKey,
|
|
169
|
+
connectedAt: new Date()
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
} else if (session.type === 'tradovate' && session.credentials) {
|
|
173
|
+
const propfirmKey = session.propfirmKey || 'tradovate';
|
|
174
|
+
const service = new TradovateService(propfirmKey);
|
|
175
|
+
|
|
176
|
+
// Try to reconnect
|
|
177
|
+
const result = await service.login(session.credentials.username, session.credentials.password);
|
|
178
|
+
if (result.success) {
|
|
179
|
+
this.services.push({
|
|
180
|
+
type: session.type,
|
|
181
|
+
service,
|
|
182
|
+
propfirm: session.propfirm,
|
|
183
|
+
propfirmKey: propfirmKey,
|
|
184
|
+
connectedAt: new Date()
|
|
185
|
+
});
|
|
186
|
+
}
|
|
143
187
|
}
|
|
144
188
|
} catch (e) {
|
|
145
189
|
// Invalid session - skip
|
|
@@ -22,6 +22,7 @@ class TradovateService extends EventEmitter {
|
|
|
22
22
|
this.isDemo = true; // Default to demo
|
|
23
23
|
this.ws = null;
|
|
24
24
|
this.renewalTimer = null;
|
|
25
|
+
this.credentials = null; // Store for session restore
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
/**
|
|
@@ -71,6 +72,7 @@ class TradovateService extends EventEmitter {
|
|
|
71
72
|
this.userId = result.userId;
|
|
72
73
|
this.tokenExpiration = new Date(result.expirationTime);
|
|
73
74
|
this.user = { userName: result.name, userId: result.userId };
|
|
75
|
+
this.credentials = { username, password }; // Store for session restore
|
|
74
76
|
|
|
75
77
|
// Setup token renewal
|
|
76
78
|
this.setupTokenRenewal();
|
|
@@ -257,6 +259,105 @@ class TradovateService extends EventEmitter {
|
|
|
257
259
|
return this.user;
|
|
258
260
|
}
|
|
259
261
|
|
|
262
|
+
/**
|
|
263
|
+
* Get market status
|
|
264
|
+
*/
|
|
265
|
+
async getMarketStatus(accountId) {
|
|
266
|
+
const marketHours = this.checkMarketHours();
|
|
267
|
+
return {
|
|
268
|
+
success: true,
|
|
269
|
+
isOpen: marketHours.isOpen,
|
|
270
|
+
message: marketHours.message,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Get token
|
|
276
|
+
*/
|
|
277
|
+
getToken() {
|
|
278
|
+
return this.accessToken;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Get orders for an account
|
|
283
|
+
*/
|
|
284
|
+
async getOrders(accountId) {
|
|
285
|
+
try {
|
|
286
|
+
const orders = await this._request(API_PATHS.ORDER_LIST, 'GET');
|
|
287
|
+
const filtered = accountId
|
|
288
|
+
? orders.filter(o => o.accountId === accountId)
|
|
289
|
+
: orders;
|
|
290
|
+
return {
|
|
291
|
+
success: true,
|
|
292
|
+
orders: filtered.map(o => ({
|
|
293
|
+
orderId: o.id,
|
|
294
|
+
accountId: o.accountId,
|
|
295
|
+
symbol: o.contractId,
|
|
296
|
+
side: o.action === 'Buy' ? 0 : 1,
|
|
297
|
+
quantity: o.orderQty,
|
|
298
|
+
filledQuantity: o.filledQty || 0,
|
|
299
|
+
price: o.price,
|
|
300
|
+
status: o.ordStatus === 'Working' ? 1 : (o.ordStatus === 'Filled' ? 2 : 0),
|
|
301
|
+
orderType: o.orderType,
|
|
302
|
+
}))
|
|
303
|
+
};
|
|
304
|
+
} catch (error) {
|
|
305
|
+
return { success: false, error: error.message, orders: [] };
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Get order history
|
|
311
|
+
*/
|
|
312
|
+
async getOrderHistory(days = 30) {
|
|
313
|
+
try {
|
|
314
|
+
const orders = await this._request(API_PATHS.ORDER_LIST, 'GET');
|
|
315
|
+
return { success: true, orders };
|
|
316
|
+
} catch (error) {
|
|
317
|
+
return { success: false, error: error.message, orders: [] };
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Get lifetime stats (stub - Tradovate doesn't provide this directly)
|
|
323
|
+
*/
|
|
324
|
+
async getLifetimeStats(accountId) {
|
|
325
|
+
return { success: true, stats: null };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Get daily stats (stub - Tradovate doesn't provide this directly)
|
|
330
|
+
*/
|
|
331
|
+
async getDailyStats(accountId) {
|
|
332
|
+
return { success: true, stats: [] };
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Get trade history
|
|
337
|
+
*/
|
|
338
|
+
async getTradeHistory(accountId, days = 30) {
|
|
339
|
+
try {
|
|
340
|
+
const fills = await this.getFills();
|
|
341
|
+
const filtered = accountId
|
|
342
|
+
? fills.filter(f => f.accountId === accountId)
|
|
343
|
+
: fills;
|
|
344
|
+
return {
|
|
345
|
+
success: true,
|
|
346
|
+
trades: filtered.map(f => ({
|
|
347
|
+
tradeId: f.id,
|
|
348
|
+
accountId: f.accountId,
|
|
349
|
+
symbol: f.contractId,
|
|
350
|
+
side: f.action === 'Buy' ? 0 : 1,
|
|
351
|
+
quantity: f.qty,
|
|
352
|
+
price: f.price,
|
|
353
|
+
timestamp: f.timestamp,
|
|
354
|
+
}))
|
|
355
|
+
};
|
|
356
|
+
} catch (error) {
|
|
357
|
+
return { success: false, error: error.message, trades: [] };
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
260
361
|
/**
|
|
261
362
|
* Check market hours (same logic as ProjectX)
|
|
262
363
|
*/
|
|
@@ -430,6 +531,7 @@ class TradovateService extends EventEmitter {
|
|
|
430
531
|
this.mdAccessToken = null;
|
|
431
532
|
this.accounts = [];
|
|
432
533
|
this.user = null;
|
|
534
|
+
this.credentials = null;
|
|
433
535
|
}
|
|
434
536
|
|
|
435
537
|
/**
|