hedgequantx 1.2.38 → 1.2.40
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 +1 -1
- package/src/services/rithmic/index.js +31 -51
package/package.json
CHANGED
package/src/app.js
CHANGED
|
@@ -467,7 +467,7 @@ const mainMenu = async () => {
|
|
|
467
467
|
// Connection menu box
|
|
468
468
|
console.log(chalk.cyan('╔' + '═'.repeat(innerWidth) + '╗'));
|
|
469
469
|
console.log(chalk.cyan('║') + chalk.white.bold(centerText('SELECT PLATFORM', innerWidth)) + chalk.cyan('║'));
|
|
470
|
-
console.log(chalk.cyan('
|
|
470
|
+
console.log(chalk.cyan('╠' + '═'.repeat(innerWidth) + '╣'));
|
|
471
471
|
|
|
472
472
|
// Menu row helper (2 columns)
|
|
473
473
|
const menuRow = (left, right) => {
|
|
@@ -142,69 +142,44 @@ class RithmicService extends EventEmitter {
|
|
|
142
142
|
|
|
143
143
|
/**
|
|
144
144
|
* Fetch accounts from ORDER_PLANT
|
|
145
|
+
* Note: Rithmic often fails to return accounts, so we use a short timeout
|
|
145
146
|
*/
|
|
146
147
|
async fetchAccounts() {
|
|
147
148
|
if (!this.orderConn || !this.loginInfo) {
|
|
148
|
-
|
|
149
|
+
return [];
|
|
149
150
|
}
|
|
150
151
|
|
|
151
|
-
//
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
// Then request accounts
|
|
155
|
-
return new Promise((resolve, reject) => {
|
|
152
|
+
// Quick timeout - don't wait too long for accounts
|
|
153
|
+
return new Promise((resolve) => {
|
|
156
154
|
const accounts = [];
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
|
|
159
156
|
const timeout = setTimeout(() => {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}, 5000);
|
|
166
|
-
|
|
167
|
-
const handleAccount = (account) => {
|
|
157
|
+
this.accounts = accounts;
|
|
158
|
+
resolve(accounts);
|
|
159
|
+
}, 2000); // 2 seconds max
|
|
160
|
+
|
|
161
|
+
this.once('accountReceived', (account) => {
|
|
168
162
|
accounts.push(account);
|
|
169
|
-
};
|
|
163
|
+
});
|
|
170
164
|
|
|
171
|
-
this.once('accountReceived', handleAccount);
|
|
172
165
|
this.once('accountListComplete', () => {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
this.accounts = accounts;
|
|
177
|
-
resolve(accounts);
|
|
178
|
-
}
|
|
166
|
+
clearTimeout(timeout);
|
|
167
|
+
this.accounts = accounts;
|
|
168
|
+
resolve(accounts);
|
|
179
169
|
});
|
|
180
170
|
|
|
181
171
|
// Request account list
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Request login info
|
|
193
|
-
*/
|
|
194
|
-
async requestLoginInfo() {
|
|
195
|
-
return new Promise((resolve) => {
|
|
196
|
-
const timeout = setTimeout(() => resolve(), 3000);
|
|
197
|
-
|
|
198
|
-
this.once('loginInfoReceived', (info) => {
|
|
172
|
+
try {
|
|
173
|
+
this.orderConn.send('RequestAccountList', {
|
|
174
|
+
templateId: REQ.ACCOUNT_LIST,
|
|
175
|
+
userMsg: ['HQX'],
|
|
176
|
+
fcmId: this.loginInfo.fcmId,
|
|
177
|
+
ibId: this.loginInfo.ibId,
|
|
178
|
+
});
|
|
179
|
+
} catch (e) {
|
|
199
180
|
clearTimeout(timeout);
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
this.orderConn.send('RequestLoginInfo', {
|
|
205
|
-
templateId: REQ.LOGIN_INFO,
|
|
206
|
-
userMsg: ['HQX'],
|
|
207
|
-
});
|
|
181
|
+
resolve([]);
|
|
182
|
+
}
|
|
208
183
|
});
|
|
209
184
|
}
|
|
210
185
|
|
|
@@ -212,8 +187,13 @@ class RithmicService extends EventEmitter {
|
|
|
212
187
|
* Get trading accounts (formatted like ProjectX)
|
|
213
188
|
*/
|
|
214
189
|
async getTradingAccounts() {
|
|
215
|
-
if
|
|
216
|
-
|
|
190
|
+
// Only try to fetch if we don't have accounts yet
|
|
191
|
+
if (this.accounts.length === 0 && this.orderConn && this.loginInfo) {
|
|
192
|
+
try {
|
|
193
|
+
await this.fetchAccounts();
|
|
194
|
+
} catch (e) {
|
|
195
|
+
// Ignore fetch errors
|
|
196
|
+
}
|
|
217
197
|
}
|
|
218
198
|
|
|
219
199
|
let tradingAccounts = this.accounts.map((acc, index) => {
|