hedgequantx 1.2.37 → 1.2.39
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/services/rithmic/index.js +49 -52
package/package.json
CHANGED
|
@@ -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,11 +187,16 @@ 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) => {
|
|
220
200
|
const pnl = this.accountPnL.get(acc.accountId) || {};
|
|
221
201
|
const balance = parseFloat(pnl.accountBalance || pnl.marginBalance || pnl.cashOnHand || 0) || this.propfirm.defaultBalance;
|
|
222
202
|
const startingBalance = this.propfirm.defaultBalance;
|
|
@@ -236,6 +216,23 @@ class RithmicService extends EventEmitter {
|
|
|
236
216
|
};
|
|
237
217
|
});
|
|
238
218
|
|
|
219
|
+
// If no accounts but user is logged in, create a default account from login info
|
|
220
|
+
if (tradingAccounts.length === 0 && this.user) {
|
|
221
|
+
const userName = this.user.userName || 'Unknown';
|
|
222
|
+
tradingAccounts = [{
|
|
223
|
+
accountId: this.hashAccountId(userName),
|
|
224
|
+
rithmicAccountId: userName,
|
|
225
|
+
accountName: userName,
|
|
226
|
+
name: userName,
|
|
227
|
+
balance: this.propfirm.defaultBalance,
|
|
228
|
+
startingBalance: this.propfirm.defaultBalance,
|
|
229
|
+
profitAndLoss: 0,
|
|
230
|
+
status: 0, // Active
|
|
231
|
+
platform: 'Rithmic',
|
|
232
|
+
propfirm: this.propfirm.name,
|
|
233
|
+
}];
|
|
234
|
+
}
|
|
235
|
+
|
|
239
236
|
return { success: true, accounts: tradingAccounts };
|
|
240
237
|
}
|
|
241
238
|
|