hedgequantx 2.9.187 → 2.9.188

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.187",
3
+ "version": "2.9.188",
4
4
  "description": "HedgeQuantX - Prop Futures Trading CLI",
5
5
  "main": "src/app.js",
6
6
  "bin": {
@@ -9,7 +9,7 @@ const { REQ } = require('./constants');
9
9
  const DEBUG = process.env.HQX_DEBUG === '1';
10
10
 
11
11
  /**
12
- * Place order via ORDER_PLANT
12
+ * Place order via ORDER_PLANT and wait for confirmation
13
13
  * @param {RithmicService} service - The Rithmic service instance
14
14
  * @param {Object} orderData - Order parameters
15
15
  */
@@ -18,26 +18,66 @@ const placeOrder = async (service, orderData) => {
18
18
  return { success: false, error: 'Not connected' };
19
19
  }
20
20
 
21
- try {
22
- service.orderConn.send('RequestNewOrder', {
23
- templateId: REQ.NEW_ORDER,
24
- userMsg: ['HQX'],
25
- fcmId: service.loginInfo.fcmId,
26
- ibId: service.loginInfo.ibId,
27
- accountId: orderData.accountId,
28
- symbol: orderData.symbol,
29
- exchange: orderData.exchange || 'CME',
30
- quantity: orderData.size,
31
- transactionType: orderData.side === 0 ? 1 : 2, // 1=Buy, 2=Sell
32
- duration: 1, // DAY
33
- orderType: orderData.type === 2 ? 1 : 2, // 1=Market, 2=Limit
34
- price: orderData.price || 0,
35
- });
21
+ // Generate unique user message for tracking
22
+ const orderTag = `HQX-${Date.now()}`;
36
23
 
37
- return { success: true, message: 'Order submitted' };
38
- } catch (error) {
39
- return { success: false, error: error.message };
40
- }
24
+ return new Promise((resolve) => {
25
+ const timeout = setTimeout(() => {
26
+ service.removeListener('orderNotification', onNotification);
27
+ resolve({ success: false, error: 'Order timeout - no confirmation received' });
28
+ }, 5000);
29
+
30
+ const onNotification = (order) => {
31
+ // Match by symbol and approximate timing
32
+ if (order.symbol === orderData.symbol) {
33
+ clearTimeout(timeout);
34
+ service.removeListener('orderNotification', onNotification);
35
+
36
+ // Check if order was accepted/filled
37
+ if (order.status === 2 || order.status === 3 || order.notifyType === 15) {
38
+ // Status 2 = Working, 3 = Filled, notifyType 15 = Complete
39
+ resolve({
40
+ success: true,
41
+ orderId: order.basketId,
42
+ status: order.status,
43
+ fillPrice: order.avgFillPrice || orderData.price,
44
+ filledQty: order.totalFillSize || orderData.size,
45
+ });
46
+ } else if (order.status === 5 || order.status === 6) {
47
+ // Status 5 = Rejected, 6 = Cancelled
48
+ resolve({
49
+ success: false,
50
+ error: `Order rejected: status ${order.status}`,
51
+ orderId: order.basketId,
52
+ });
53
+ }
54
+ // Keep listening for other statuses
55
+ }
56
+ };
57
+
58
+ service.on('orderNotification', onNotification);
59
+
60
+ try {
61
+ service.orderConn.send('RequestNewOrder', {
62
+ templateId: REQ.NEW_ORDER,
63
+ userMsg: [orderTag],
64
+ fcmId: service.loginInfo.fcmId,
65
+ ibId: service.loginInfo.ibId,
66
+ accountId: orderData.accountId,
67
+ symbol: orderData.symbol,
68
+ exchange: orderData.exchange || 'CME',
69
+ quantity: orderData.size,
70
+ transactionType: orderData.side === 0 ? 1 : 2, // 1=Buy, 2=Sell
71
+ duration: 1, // DAY
72
+ orderType: orderData.type === 2 ? 1 : 2, // 1=Market, 2=Limit
73
+ price: orderData.price || 0,
74
+ });
75
+ } catch (error) {
76
+ clearTimeout(timeout);
77
+ service.removeListener('orderNotification', onNotification);
78
+ resolve({ success: false, error: error.message });
79
+ }
80
+ });
41
81
  };
42
82
 
43
83
  /**