hedgequantx 2.9.188 → 2.9.190
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
|
@@ -39,6 +39,9 @@ const createOrderHandler = (service) => {
|
|
|
39
39
|
case RES.SHOW_ORDERS:
|
|
40
40
|
handleShowOrdersResponse(service, data);
|
|
41
41
|
break;
|
|
42
|
+
case RES.NEW_ORDER:
|
|
43
|
+
handleNewOrderResponse(service, data);
|
|
44
|
+
break;
|
|
42
45
|
case STREAM.EXCHANGE_NOTIFICATION:
|
|
43
46
|
handleExchangeNotification(service, data);
|
|
44
47
|
break;
|
|
@@ -154,6 +157,36 @@ const handleShowOrdersResponse = (service, data) => {
|
|
|
154
157
|
}
|
|
155
158
|
};
|
|
156
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Handle new order response (template 313)
|
|
162
|
+
*/
|
|
163
|
+
const handleNewOrderResponse = (service, data) => {
|
|
164
|
+
try {
|
|
165
|
+
const res = proto.decode('ResponseNewOrder', data);
|
|
166
|
+
debug('New order response:', JSON.stringify(res));
|
|
167
|
+
|
|
168
|
+
// Emit as orderNotification for the placeOrder listener
|
|
169
|
+
if (res.basketId || res.orderId) {
|
|
170
|
+
const order = {
|
|
171
|
+
basketId: res.basketId || res.orderId,
|
|
172
|
+
accountId: res.accountId,
|
|
173
|
+
symbol: res.symbol,
|
|
174
|
+
exchange: res.exchange || 'CME',
|
|
175
|
+
status: res.rpCode?.[0] === '0' ? 2 : 5, // 2=Working, 5=Rejected
|
|
176
|
+
notifyType: res.rpCode?.[0] === '0' ? 1 : 0, // 1=Accepted
|
|
177
|
+
rpCode: res.rpCode,
|
|
178
|
+
userMsg: res.userMsg,
|
|
179
|
+
};
|
|
180
|
+
service.emit('orderNotification', order);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Also emit specific event
|
|
184
|
+
service.emit('newOrderResponse', res);
|
|
185
|
+
} catch (e) {
|
|
186
|
+
debug('Error decoding ResponseNewOrder:', e.message);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
157
190
|
/**
|
|
158
191
|
* Handle account PnL update
|
|
159
192
|
*/
|
|
@@ -14,9 +14,26 @@ const DEBUG = process.env.HQX_DEBUG === '1';
|
|
|
14
14
|
* @param {Object} orderData - Order parameters
|
|
15
15
|
*/
|
|
16
16
|
const placeOrder = async (service, orderData) => {
|
|
17
|
+
// Check connection state
|
|
18
|
+
const connState = service.orderConn?.connectionState;
|
|
19
|
+
const wsState = service.orderConn?.ws?.readyState;
|
|
20
|
+
|
|
21
|
+
if (DEBUG) {
|
|
22
|
+
console.log('[ORDER] Connection check:', {
|
|
23
|
+
hasOrderConn: !!service.orderConn,
|
|
24
|
+
connState,
|
|
25
|
+
wsState,
|
|
26
|
+
hasLoginInfo: !!service.loginInfo
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
17
30
|
if (!service.orderConn || !service.loginInfo) {
|
|
18
31
|
return { success: false, error: 'Not connected' };
|
|
19
32
|
}
|
|
33
|
+
|
|
34
|
+
if (connState !== 'LOGGED_IN') {
|
|
35
|
+
return { success: false, error: `ORDER_PLANT not logged in (state: ${connState})` };
|
|
36
|
+
}
|
|
20
37
|
|
|
21
38
|
// Generate unique user message for tracking
|
|
22
39
|
const orderTag = `HQX-${Date.now()}`;
|
|
@@ -58,7 +75,7 @@ const placeOrder = async (service, orderData) => {
|
|
|
58
75
|
service.on('orderNotification', onNotification);
|
|
59
76
|
|
|
60
77
|
try {
|
|
61
|
-
|
|
78
|
+
const orderRequest = {
|
|
62
79
|
templateId: REQ.NEW_ORDER,
|
|
63
80
|
userMsg: [orderTag],
|
|
64
81
|
fcmId: service.loginInfo.fcmId,
|
|
@@ -69,9 +86,16 @@ const placeOrder = async (service, orderData) => {
|
|
|
69
86
|
quantity: orderData.size,
|
|
70
87
|
transactionType: orderData.side === 0 ? 1 : 2, // 1=Buy, 2=Sell
|
|
71
88
|
duration: 1, // DAY
|
|
72
|
-
|
|
89
|
+
priceType: orderData.type === 2 ? 2 : 1, // 2=Market, 1=Limit
|
|
73
90
|
price: orderData.price || 0,
|
|
74
|
-
|
|
91
|
+
manualOrAuto: 2, // AUTO
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
if (DEBUG) {
|
|
95
|
+
console.log('[ORDER] Sending RequestNewOrder:', JSON.stringify(orderRequest));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
service.orderConn.send('RequestNewOrder', orderRequest);
|
|
75
99
|
} catch (error) {
|
|
76
100
|
clearTimeout(timeout);
|
|
77
101
|
service.removeListener('orderNotification', onNotification);
|