hedgequantx 1.2.52 → 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
CHANGED
|
@@ -599,6 +599,118 @@ class RithmicService extends EventEmitter {
|
|
|
599
599
|
return { success: true, trades: [] };
|
|
600
600
|
}
|
|
601
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
|
+
|
|
602
714
|
/**
|
|
603
715
|
* Get order history
|
|
604
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,25 @@ 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
|
+
|
|
260
281
|
/**
|
|
261
282
|
* Get orders for an account
|
|
262
283
|
*/
|
|
@@ -510,6 +531,7 @@ class TradovateService extends EventEmitter {
|
|
|
510
531
|
this.mdAccessToken = null;
|
|
511
532
|
this.accounts = [];
|
|
512
533
|
this.user = null;
|
|
534
|
+
this.credentials = null;
|
|
513
535
|
}
|
|
514
536
|
|
|
515
537
|
/**
|