hedgequantx 2.9.33 → 2.9.34

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": "2.9.33",
3
+ "version": "2.9.34",
4
4
  "description": "HedgeQuantX - Prop Futures Trading CLI",
5
5
  "main": "src/app.js",
6
6
  "bin": {
@@ -292,33 +292,64 @@ const getOrderHistory = async (service, date) => {
292
292
  };
293
293
 
294
294
  /**
295
- * Get full trade history for multiple dates
295
+ * Get full trade history (fills) from ORDER_PLANT
296
296
  * @param {RithmicService} service - The Rithmic service instance
297
- * @param {number} days - Number of days to fetch (default 30)
297
+ * @param {number} days - Number of days to fetch (default 7, max 14)
298
298
  * @returns {Promise<{success: boolean, trades: Array}>}
299
299
  */
300
- const getTradeHistoryFull = async (service, days = 30) => {
300
+ const getTradeHistoryFull = async (service, days = 7) => {
301
301
  if (!service.orderConn || !service.loginInfo) {
302
302
  return { success: false, trades: [] };
303
303
  }
304
304
 
305
- // Get available dates
306
- const { dates } = await getOrderHistoryDates(service);
305
+ // Get available dates with timeout
306
+ let dates;
307
+ try {
308
+ const datesPromise = getOrderHistoryDates(service);
309
+ const timeoutPromise = new Promise((_, reject) =>
310
+ setTimeout(() => reject(new Error('Timeout')), 5000)
311
+ );
312
+ const result = await Promise.race([datesPromise, timeoutPromise]);
313
+ dates = result.dates;
314
+ } catch (e) {
315
+ return { success: true, trades: [] };
316
+ }
317
+
307
318
  if (!dates || dates.length === 0) {
308
319
  return { success: true, trades: [] };
309
320
  }
310
321
 
311
- // Sort dates descending and limit to requested days
312
- const sortedDates = dates.sort((a, b) => b.localeCompare(a)).slice(0, days);
322
+ // Filter to recent dates only (last N days from today)
323
+ const today = new Date();
324
+ const cutoffDate = new Date(today.getTime() - (Math.min(days, 14) * 24 * 60 * 60 * 1000));
325
+ const cutoffStr = cutoffDate.toISOString().slice(0, 10).replace(/-/g, '');
326
+
327
+ // Sort dates descending and filter to recent only
328
+ const recentDates = dates
329
+ .filter(d => d >= cutoffStr)
330
+ .sort((a, b) => b.localeCompare(a))
331
+ .slice(0, 7); // Max 7 dates to avoid long waits
332
+
333
+ if (recentDates.length === 0) {
334
+ return { success: true, trades: [] };
335
+ }
313
336
 
314
337
  const allTrades = [];
315
338
 
316
- // Fetch history for each date
317
- for (const date of sortedDates) {
318
- const { orders } = await getOrderHistory(service, date);
319
- // Filter only fills (notifyType 5)
320
- const fills = orders.filter(o => o.notifyType === 5 || o.fillPrice);
321
- allTrades.push(...fills);
339
+ // Fetch history for each date with short timeout
340
+ for (const date of recentDates) {
341
+ try {
342
+ const histPromise = getOrderHistory(service, date);
343
+ const timeoutPromise = new Promise((resolve) =>
344
+ setTimeout(() => resolve({ orders: [] }), 3000)
345
+ );
346
+ const { orders } = await Promise.race([histPromise, timeoutPromise]);
347
+ // Filter only fills (notifyType 5)
348
+ const fills = (orders || []).filter(o => o.notifyType === 5 || o.fillPrice);
349
+ allTrades.push(...fills);
350
+ } catch (e) {
351
+ // Skip failed dates
352
+ }
322
353
  }
323
354
 
324
355
  return { success: true, trades: allTrades };