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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hedgequantx",
3
- "version": "1.2.37",
3
+ "version": "1.2.39",
4
4
  "description": "Prop Futures Algo Trading CLI - Connect to Topstep, Alpha Futures, and other prop firms",
5
5
  "main": "src/app.js",
6
6
  "bin": {
@@ -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
- throw new Error('Not connected');
149
+ return [];
149
150
  }
150
151
 
151
- // Request login info first
152
- await this.requestLoginInfo();
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
- let completed = false;
158
-
155
+
159
156
  const timeout = setTimeout(() => {
160
- if (!completed) {
161
- completed = true;
162
- this.accounts = accounts;
163
- resolve(accounts);
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
- if (!completed) {
174
- completed = true;
175
- clearTimeout(timeout);
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
- this.orderConn.send('RequestAccountList', {
183
- templateId: REQ.ACCOUNT_LIST,
184
- userMsg: ['HQX'],
185
- fcmId: this.loginInfo.fcmId,
186
- ibId: this.loginInfo.ibId,
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
- this.loginInfo = { ...this.loginInfo, ...info };
201
- resolve(info);
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 (this.accounts.length === 0) {
216
- await this.fetchAccounts();
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
- const tradingAccounts = this.accounts.map((acc, index) => {
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