@hitrading/ctp-node 2.0.0 → 4.0.0
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/CHANGELOG.md +82 -0
- package/README.md +54 -32
- package/README.zh-CN.md +44 -27
- package/RELEASING.md +78 -0
- package/dist/client.d.ts +36 -15
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +234 -62
- package/dist/client.js.map +1 -1
- package/dist/codec.d.ts.map +1 -1
- package/dist/codec.js +84 -19
- package/dist/codec.js.map +1 -1
- package/dist/generated/structs.gen.d.ts +5461 -5461
- package/dist/generated/structs.gen.d.ts.map +1 -1
- package/dist/generated/trader.gen.d.ts.map +1 -1
- package/dist/generated/trader.gen.js +788 -94
- package/dist/generated/trader.gen.js.map +1 -1
- package/dist/index.cjs +1909 -417
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/market-data.d.ts +41 -24
- package/dist/market-data.d.ts.map +1 -1
- package/dist/market-data.js +148 -29
- package/dist/market-data.js.map +1 -1
- package/dist/native-binding.d.ts.map +1 -1
- package/dist/native-binding.js +4 -0
- package/dist/native-binding.js.map +1 -1
- package/dist/trader.d.ts +136 -79
- package/dist/trader.d.ts.map +1 -1
- package/dist/trader.js +807 -182
- package/dist/trader.js.map +1 -1
- package/dist/validation.d.ts +27 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +85 -0
- package/dist/validation.js.map +1 -0
- package/docs/API.md +1445 -0
- package/docs/API.zh-CN.md +1285 -0
- package/docs/MIGRATION.md +54 -0
- package/docs/assets/validation.svg +27 -0
- package/docs/integration.md +60 -0
- package/docs/native-hooks.md +281 -0
- package/docs/native-hooks.zh-CN.md +205 -0
- package/docs/troubleshooting.md +257 -0
- package/docs/troubleshooting.zh-CN.md +220 -0
- package/package.json +12 -4
- package/prebuilds/linux-x64/@hitrading+ctp-node.node +0 -0
- package/prebuilds/win32-x64/@hitrading+ctp-node.node +0 -0
- package/scripts/bench-decode.mjs +37 -0
- package/scripts/bench-fullmarket-offline.mjs +207 -0
- package/scripts/stress-fullmarket.mjs +255 -0
- package/src/addon.cc +2 -2
- package/src/client.ts +255 -65
- package/src/codec.ts +86 -19
- package/src/generated/structs.gen.ts +5461 -5461
- package/src/generated/trader.gen.ts +309 -94
- package/src/generated/traderreq.gen.cc +194 -18
- package/src/generated/traderreq.gen.h +4 -0
- package/src/generated/traderspi.gen.cc +129 -15
- package/src/generated/traderspi.gen.h +4 -2
- package/src/index.ts +11 -1
- package/src/market-data.ts +199 -46
- package/src/native/arm.cc +114 -30
- package/src/native/arm.h +16 -4
- package/src/native/channel.cc +209 -81
- package/src/native/channel.h +65 -24
- package/src/native/ctp_field.h +23 -0
- package/src/native/mdapi.cc +582 -69
- package/src/native/mdspi.cc +219 -16
- package/src/native/mdspi.h +59 -10
- package/src/native/order_capability.h +78 -0
- package/src/native/risk.cc +2030 -213
- package/src/native/risk.h +431 -78
- package/src/native/shared_handle.h +37 -0
- package/src/native/snapshot.h +75 -16
- package/src/native/traderapi.cc +769 -124
- package/src/native-binding.ts +4 -0
- package/src/trader.ts +1038 -207
- package/src/validation.ts +96 -0
|
@@ -1,17 +1,52 @@
|
|
|
1
1
|
/* AUTO-GENERATED. Do not edit. */
|
|
2
2
|
#include "traderspi.gen.h"
|
|
3
3
|
#include "structids.gen.h"
|
|
4
|
+
#include <string>
|
|
4
5
|
|
|
5
6
|
namespace ctp {
|
|
6
7
|
|
|
7
8
|
static int eid(CThostFtdcRspInfoField *e) { return e ? e->ErrorID : 0; }
|
|
8
9
|
static const char *emsg(CThostFtdcRspInfoField *e) { return (e && e->ErrorID) ? e->ErrorMsg : ""; }
|
|
9
10
|
|
|
11
|
+
static bool validSingleOffset(const char *flags, size_t capacity) {
|
|
12
|
+
return capacity > 0 && flags[0] >= '0' && flags[0] <= '6' &&
|
|
13
|
+
(capacity == 1 || flags[1] == '\0');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static bool validHedgeFlag(char flag) {
|
|
17
|
+
return flag == '1' || flag == '2' || flag == '3' || flag == '5' ||
|
|
18
|
+
flag == '6' || flag == '7';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static bool validSingleHedge(const char *flags, size_t capacity) {
|
|
22
|
+
return capacity > 0 && validHedgeFlag(flags[0]) &&
|
|
23
|
+
(capacity == 1 || flags[1] == '\0');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
template <size_t N>
|
|
27
|
+
static bool boundedField(const char (&field)[N], std::string &out) {
|
|
28
|
+
size_t length = 0;
|
|
29
|
+
while (length < N && field[length] != '\0')
|
|
30
|
+
++length;
|
|
31
|
+
if (length == N)
|
|
32
|
+
return false;
|
|
33
|
+
out.assign(field, length);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
|
|
10
37
|
void TraderSpi::OnFrontConnected() {
|
|
38
|
+
if (arm_)
|
|
39
|
+
arm_->clear();
|
|
40
|
+
if (risk_)
|
|
41
|
+
risk_->invalidateSession();
|
|
11
42
|
ch_->push(ET_FrontConnected, 0, -1, 0, "", -1, nullptr, 0);
|
|
12
43
|
}
|
|
13
44
|
|
|
14
45
|
void TraderSpi::OnFrontDisconnected(int arg) {
|
|
46
|
+
if (arm_)
|
|
47
|
+
arm_->clear();
|
|
48
|
+
if (risk_)
|
|
49
|
+
risk_->invalidateSession();
|
|
15
50
|
ch_->push(ET_FrontDisconnected, 0, -1, 0, "", -2, &arg, sizeof(arg));
|
|
16
51
|
}
|
|
17
52
|
|
|
@@ -28,12 +63,16 @@ void TraderSpi::OnRtnPrivateSeqNo(int arg) {
|
|
|
28
63
|
}
|
|
29
64
|
|
|
30
65
|
void TraderSpi::OnRspUserLogin(CThostFtdcRspUserLoginField *p, CThostFtdcRspInfoField *e, int id, bool last) {
|
|
31
|
-
if (
|
|
32
|
-
risk_->
|
|
66
|
+
if (risk_ && last) {
|
|
67
|
+
if (!p || eid(e) != 0 || !risk_->acceptLoginSession(id, p->FrontID, p->SessionID, p->BrokerID, p->UserID))
|
|
68
|
+
risk_->finishSessionTransition(id);
|
|
69
|
+
}
|
|
33
70
|
ch_->push(ET_RspUserLogin, id, last ? 1 : 0, eid(e), emsg(e), p ? SID_RspUserLogin : -1, p, p ? (int)sizeof(*p) : 0);
|
|
34
71
|
}
|
|
35
72
|
|
|
36
73
|
void TraderSpi::OnRspUserLogout(CThostFtdcUserLogoutField *p, CThostFtdcRspInfoField *e, int id, bool last) {
|
|
74
|
+
if (risk_ && last)
|
|
75
|
+
risk_->finishSessionTransition(id);
|
|
37
76
|
ch_->push(ET_RspUserLogout, id, last ? 1 : 0, eid(e), emsg(e), p ? SID_UserLogout : -1, p, p ? (int)sizeof(*p) : 0);
|
|
38
77
|
}
|
|
39
78
|
|
|
@@ -58,8 +97,11 @@ void TraderSpi::OnRspGenUserText(CThostFtdcRspGenUserTextField *p, CThostFtdcRsp
|
|
|
58
97
|
}
|
|
59
98
|
|
|
60
99
|
void TraderSpi::OnRspOrderInsert(CThostFtdcInputOrderField *p, CThostFtdcRspInfoField *e, int id, bool last) {
|
|
61
|
-
if (
|
|
62
|
-
|
|
100
|
+
if (risk_ && eid(e) != 0 && (!p || !validSingleOffset(p->CombOffsetFlag, sizeof(p->CombOffsetFlag)) || p->CombOffsetFlag[0] == '0')) {
|
|
101
|
+
std::string orderRef, broker, investor;
|
|
102
|
+
if (p) { boundedField(p->OrderRef, orderRef); boundedField(p->BrokerID, broker); boundedField(p->InvestorID, investor); }
|
|
103
|
+
risk_->rejectInsertByRequest(id, orderRef, broker, investor);
|
|
104
|
+
}
|
|
63
105
|
ch_->push(ET_RspOrderInsert, id, last ? 1 : 0, eid(e), emsg(e), p ? SID_InputOrder : -1, p, p ? (int)sizeof(*p) : 0);
|
|
64
106
|
}
|
|
65
107
|
|
|
@@ -152,10 +194,12 @@ void TraderSpi::OnRspQryTradingCode(CThostFtdcTradingCodeField *p, CThostFtdcRsp
|
|
|
152
194
|
}
|
|
153
195
|
|
|
154
196
|
void TraderSpi::OnRspQryInstrumentMarginRate(CThostFtdcInstrumentMarginRateField *p, CThostFtdcRspInfoField *e, int id, bool last) {
|
|
155
|
-
if (p && risk_) {
|
|
156
|
-
|
|
157
|
-
|
|
197
|
+
if (p && risk_ && eid(e) == 0) {
|
|
198
|
+
std::string broker, investor, investUnit, instrument;
|
|
199
|
+
if (boundedField(p->BrokerID, broker) && boundedField(p->InvestorID, investor) && boundedField(p->InvestUnitID, investUnit) && boundedField(p->InstrumentID, instrument))
|
|
200
|
+
risk_->applyInvestorMarginSchedule(id, broker, investor, investUnit, instrument, p->HedgeFlag, p->LongMarginRatioByMoney, p->LongMarginRatioByVolume, p->ShortMarginRatioByMoney, p->ShortMarginRatioByVolume, p->IsRelative != 0);
|
|
158
201
|
}
|
|
202
|
+
if (risk_ && last) risk_->finishMarginScheduleQuery(id, eid(e) == 0);
|
|
159
203
|
ch_->push(ET_RspQryInstrumentMarginRate, id, last ? 1 : 0, eid(e), emsg(e), p ? SID_InstrumentMarginRate : -1, p, p ? (int)sizeof(*p) : 0);
|
|
160
204
|
}
|
|
161
205
|
|
|
@@ -176,8 +220,13 @@ void TraderSpi::OnRspQryProduct(CThostFtdcProductField *p, CThostFtdcRspInfoFiel
|
|
|
176
220
|
}
|
|
177
221
|
|
|
178
222
|
void TraderSpi::OnRspQryInstrument(CThostFtdcInstrumentField *p, CThostFtdcRspInfoField *e, int id, bool last) {
|
|
179
|
-
if (p && risk_)
|
|
180
|
-
|
|
223
|
+
if (p && risk_ && eid(e) == 0) {
|
|
224
|
+
std::string instrument;
|
|
225
|
+
if (boundedField(p->InstrumentID, instrument))
|
|
226
|
+
risk_->setInstrument(instrument, p->VolumeMultiple, p->ProductClass);
|
|
227
|
+
else
|
|
228
|
+
risk_->invalidateInstrument("");
|
|
229
|
+
}
|
|
181
230
|
ch_->push(ET_RspQryInstrument, id, last ? 1 : 0, eid(e), emsg(e), p ? SID_Instrument : -1, p, p ? (int)sizeof(*p) : 0);
|
|
182
231
|
}
|
|
183
232
|
|
|
@@ -226,6 +275,12 @@ void TraderSpi::OnRspQryInvestorProductGroupMargin(CThostFtdcInvestorProductGrou
|
|
|
226
275
|
}
|
|
227
276
|
|
|
228
277
|
void TraderSpi::OnRspQryExchangeMarginRate(CThostFtdcExchangeMarginRateField *p, CThostFtdcRspInfoField *e, int id, bool last) {
|
|
278
|
+
if (p && risk_ && eid(e) == 0) {
|
|
279
|
+
std::string broker, instrument;
|
|
280
|
+
if (boundedField(p->BrokerID, broker) && boundedField(p->InstrumentID, instrument))
|
|
281
|
+
risk_->applyExchangeMarginSchedule(id, broker, instrument, p->HedgeFlag, p->LongMarginRatioByMoney, p->LongMarginRatioByVolume, p->ShortMarginRatioByMoney, p->ShortMarginRatioByVolume);
|
|
282
|
+
}
|
|
283
|
+
if (risk_ && last) risk_->finishMarginScheduleQuery(id, eid(e) == 0);
|
|
229
284
|
ch_->push(ET_RspQryExchangeMarginRate, id, last ? 1 : 0, eid(e), emsg(e), p ? SID_ExchangeMarginRate : -1, p, p ? (int)sizeof(*p) : 0);
|
|
230
285
|
}
|
|
231
286
|
|
|
@@ -322,20 +377,45 @@ void TraderSpi::OnRspError(CThostFtdcRspInfoField *e, int id, bool last) {
|
|
|
322
377
|
}
|
|
323
378
|
|
|
324
379
|
void TraderSpi::OnRtnOrder(CThostFtdcOrderField *p) {
|
|
325
|
-
if (p && risk_)
|
|
326
|
-
|
|
380
|
+
if (p && risk_) {
|
|
381
|
+
std::string day, broker, investor, exchange, instrument, orderSysId, orderRef;
|
|
382
|
+
const bool stringsValid = boundedField(p->TradingDay, day) && boundedField(p->BrokerID, broker) && boundedField(p->InvestorID, investor) && boundedField(p->ExchangeID, exchange) && boundedField(p->InstrumentID, instrument) && boundedField(p->OrderSysID, orderSysId) && boundedField(p->OrderRef, orderRef);
|
|
383
|
+
const std::string sys = stringsValid && !day.empty() && !broker.empty() && !investor.empty() && !exchange.empty() && !instrument.empty() && !orderSysId.empty() ? day + "|" + broker + "|" + investor + "|" + exchange + "|" + instrument + "|" + orderSysId : std::string();
|
|
384
|
+
if (stringsValid && !broker.empty() && !investor.empty() && validSingleOffset(p->CombOffsetFlag, sizeof(p->CombOffsetFlag)) && validSingleHedge(p->CombHedgeFlag, sizeof(p->CombHedgeFlag)) && (p->Direction == '0' || p->Direction == '1') && !instrument.empty() && !orderRef.empty()) {
|
|
385
|
+
risk_->onOrderUpdate(p->FrontID, p->SessionID, orderRef, instrument, p->CombOffsetFlag[0] == '0', p->Direction == '0', p->CombHedgeFlag[0], p->OrderStatus, p->LimitPrice, p->VolumeTotalOriginal, p->VolumeTraded, sys, broker, investor);
|
|
386
|
+
} else {
|
|
387
|
+
risk_->onUnsupportedOrderUpdate(p->FrontID, p->SessionID, orderRef, p->OrderStatus, sys, broker, investor);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
327
390
|
ch_->push(ET_RtnOrder, 0, -1, 0, "", p ? SID_Order : -1, p, p ? (int)sizeof(*p) : 0);
|
|
328
391
|
}
|
|
329
392
|
|
|
330
393
|
void TraderSpi::OnRtnTrade(CThostFtdcTradeField *p) {
|
|
331
|
-
if (p && risk_)
|
|
332
|
-
|
|
394
|
+
if (p && risk_) {
|
|
395
|
+
std::string tradingDay, tradeDate, broker, investor, exchange, instrument, tradeId, orderSysId, orderRef;
|
|
396
|
+
const bool stringsValid = boundedField(p->TradingDay, tradingDay) && boundedField(p->TradeDate, tradeDate) && boundedField(p->BrokerID, broker) && boundedField(p->InvestorID, investor) && boundedField(p->ExchangeID, exchange) && boundedField(p->InstrumentID, instrument) && boundedField(p->TradeID, tradeId) && boundedField(p->OrderSysID, orderSysId) && boundedField(p->OrderRef, orderRef);
|
|
397
|
+
if (stringsValid && !instrument.empty() && !broker.empty() && !investor.empty() && (p->Direction == '0' || p->Direction == '1') && p->OffsetFlag >= '0' && p->OffsetFlag <= '6' && validHedgeFlag(p->HedgeFlag)) {
|
|
398
|
+
const std::string &day = !tradingDay.empty() ? tradingDay : tradeDate;
|
|
399
|
+
std::string key;
|
|
400
|
+
if (!day.empty() && !exchange.empty() && !tradeId.empty())
|
|
401
|
+
key = day + "|" + broker + "|" + investor + "|" + exchange + "|" + instrument + "|trade|" + tradeId;
|
|
402
|
+
else if (!day.empty() && !exchange.empty() && p->SequenceNo != 0)
|
|
403
|
+
key = day + "|" + broker + "|" + investor + "|" + exchange + "|" + instrument + "|sequence|" + std::to_string(p->SequenceNo);
|
|
404
|
+
const std::string sys = !tradingDay.empty() && !exchange.empty() && !orderSysId.empty() ? tradingDay + "|" + broker + "|" + investor + "|" + exchange + "|" + instrument + "|" + orderSysId : std::string();
|
|
405
|
+
risk_->onTrade(key, orderRef, sys, instrument, p->Direction == '0', p->OffsetFlag == '0', p->HedgeFlag, p->Price, p->Volume, broker, investor);
|
|
406
|
+
} else {
|
|
407
|
+
risk_->markTradeLedgerUncertain();
|
|
408
|
+
}
|
|
409
|
+
}
|
|
333
410
|
ch_->push(ET_RtnTrade, 0, -1, 0, "", p ? SID_Trade : -1, p, p ? (int)sizeof(*p) : 0);
|
|
334
411
|
}
|
|
335
412
|
|
|
336
413
|
void TraderSpi::OnErrRtnOrderInsert(CThostFtdcInputOrderField *p, CThostFtdcRspInfoField *e) {
|
|
337
|
-
if (
|
|
338
|
-
|
|
414
|
+
if (risk_ && (!p || !validSingleOffset(p->CombOffsetFlag, sizeof(p->CombOffsetFlag)) || p->CombOffsetFlag[0] == '0')) {
|
|
415
|
+
std::string orderRef, broker, investor;
|
|
416
|
+
if (p) { boundedField(p->OrderRef, orderRef); boundedField(p->BrokerID, broker); boundedField(p->InvestorID, investor); }
|
|
417
|
+
risk_->rejectInsertUnscoped(orderRef, broker, investor);
|
|
418
|
+
}
|
|
339
419
|
ch_->push(ET_ErrRtnOrderInsert, 0, -1, eid(e), emsg(e), p ? SID_InputOrder : -1, p, p ? (int)sizeof(*p) : 0);
|
|
340
420
|
}
|
|
341
421
|
|
|
@@ -360,6 +440,8 @@ void TraderSpi::OnRtnErrorConditionalOrder(CThostFtdcErrorConditionalOrderField
|
|
|
360
440
|
}
|
|
361
441
|
|
|
362
442
|
void TraderSpi::OnRtnExecOrder(CThostFtdcExecOrderField *p) {
|
|
443
|
+
if (p && risk_)
|
|
444
|
+
risk_->recordUnsupportedRiskMutation();
|
|
363
445
|
ch_->push(ET_RtnExecOrder, 0, -1, 0, "", p ? SID_ExecOrder : -1, p, p ? (int)sizeof(*p) : 0);
|
|
364
446
|
}
|
|
365
447
|
|
|
@@ -376,6 +458,8 @@ void TraderSpi::OnErrRtnForQuoteInsert(CThostFtdcInputForQuoteField *p, CThostFt
|
|
|
376
458
|
}
|
|
377
459
|
|
|
378
460
|
void TraderSpi::OnRtnQuote(CThostFtdcQuoteField *p) {
|
|
461
|
+
if (p && risk_)
|
|
462
|
+
risk_->recordUnsupportedRiskMutation();
|
|
379
463
|
ch_->push(ET_RtnQuote, 0, -1, 0, "", p ? SID_Quote : -1, p, p ? (int)sizeof(*p) : 0);
|
|
380
464
|
}
|
|
381
465
|
|
|
@@ -400,6 +484,8 @@ void TraderSpi::OnErrRtnBatchOrderAction(CThostFtdcBatchOrderActionField *p, CTh
|
|
|
400
484
|
}
|
|
401
485
|
|
|
402
486
|
void TraderSpi::OnRtnOptionSelfClose(CThostFtdcOptionSelfCloseField *p) {
|
|
487
|
+
if (p && risk_)
|
|
488
|
+
risk_->recordUnsupportedRiskMutation();
|
|
403
489
|
ch_->push(ET_RtnOptionSelfClose, 0, -1, 0, "", p ? SID_OptionSelfClose : -1, p, p ? (int)sizeof(*p) : 0);
|
|
404
490
|
}
|
|
405
491
|
|
|
@@ -412,6 +498,8 @@ void TraderSpi::OnErrRtnOptionSelfCloseAction(CThostFtdcOptionSelfCloseActionFie
|
|
|
412
498
|
}
|
|
413
499
|
|
|
414
500
|
void TraderSpi::OnRtnCombAction(CThostFtdcCombActionField *p) {
|
|
501
|
+
if (p && risk_)
|
|
502
|
+
risk_->recordUnsupportedRiskMutation();
|
|
415
503
|
ch_->push(ET_RtnCombAction, 0, -1, 0, "", p ? SID_CombAction : -1, p, p ? (int)sizeof(*p) : 0);
|
|
416
504
|
}
|
|
417
505
|
|
|
@@ -448,34 +536,50 @@ void TraderSpi::OnRspQueryCFMMCTradingAccountToken(CThostFtdcQueryCFMMCTradingAc
|
|
|
448
536
|
}
|
|
449
537
|
|
|
450
538
|
void TraderSpi::OnRtnFromBankToFutureByBank(CThostFtdcRspTransferField *p) {
|
|
539
|
+
if (p && risk_)
|
|
540
|
+
risk_->recordUnsupportedRiskMutation();
|
|
451
541
|
ch_->push(ET_RtnFromBankToFutureByBank, 0, -1, 0, "", p ? SID_RspTransfer : -1, p, p ? (int)sizeof(*p) : 0);
|
|
452
542
|
}
|
|
453
543
|
|
|
454
544
|
void TraderSpi::OnRtnFromFutureToBankByBank(CThostFtdcRspTransferField *p) {
|
|
545
|
+
if (p && risk_)
|
|
546
|
+
risk_->recordUnsupportedRiskMutation();
|
|
455
547
|
ch_->push(ET_RtnFromFutureToBankByBank, 0, -1, 0, "", p ? SID_RspTransfer : -1, p, p ? (int)sizeof(*p) : 0);
|
|
456
548
|
}
|
|
457
549
|
|
|
458
550
|
void TraderSpi::OnRtnRepealFromBankToFutureByBank(CThostFtdcRspRepealField *p) {
|
|
551
|
+
if (p && risk_)
|
|
552
|
+
risk_->recordUnsupportedRiskMutation();
|
|
459
553
|
ch_->push(ET_RtnRepealFromBankToFutureByBank, 0, -1, 0, "", p ? SID_RspRepeal : -1, p, p ? (int)sizeof(*p) : 0);
|
|
460
554
|
}
|
|
461
555
|
|
|
462
556
|
void TraderSpi::OnRtnRepealFromFutureToBankByBank(CThostFtdcRspRepealField *p) {
|
|
557
|
+
if (p && risk_)
|
|
558
|
+
risk_->recordUnsupportedRiskMutation();
|
|
463
559
|
ch_->push(ET_RtnRepealFromFutureToBankByBank, 0, -1, 0, "", p ? SID_RspRepeal : -1, p, p ? (int)sizeof(*p) : 0);
|
|
464
560
|
}
|
|
465
561
|
|
|
466
562
|
void TraderSpi::OnRtnFromBankToFutureByFuture(CThostFtdcRspTransferField *p) {
|
|
563
|
+
if (p && risk_)
|
|
564
|
+
risk_->recordUnsupportedRiskMutation();
|
|
467
565
|
ch_->push(ET_RtnFromBankToFutureByFuture, 0, -1, 0, "", p ? SID_RspTransfer : -1, p, p ? (int)sizeof(*p) : 0);
|
|
468
566
|
}
|
|
469
567
|
|
|
470
568
|
void TraderSpi::OnRtnFromFutureToBankByFuture(CThostFtdcRspTransferField *p) {
|
|
569
|
+
if (p && risk_)
|
|
570
|
+
risk_->recordUnsupportedRiskMutation();
|
|
471
571
|
ch_->push(ET_RtnFromFutureToBankByFuture, 0, -1, 0, "", p ? SID_RspTransfer : -1, p, p ? (int)sizeof(*p) : 0);
|
|
472
572
|
}
|
|
473
573
|
|
|
474
574
|
void TraderSpi::OnRtnRepealFromBankToFutureByFutureManual(CThostFtdcRspRepealField *p) {
|
|
575
|
+
if (p && risk_)
|
|
576
|
+
risk_->recordUnsupportedRiskMutation();
|
|
475
577
|
ch_->push(ET_RtnRepealFromBankToFutureByFutureManual, 0, -1, 0, "", p ? SID_RspRepeal : -1, p, p ? (int)sizeof(*p) : 0);
|
|
476
578
|
}
|
|
477
579
|
|
|
478
580
|
void TraderSpi::OnRtnRepealFromFutureToBankByFutureManual(CThostFtdcRspRepealField *p) {
|
|
581
|
+
if (p && risk_)
|
|
582
|
+
risk_->recordUnsupportedRiskMutation();
|
|
479
583
|
ch_->push(ET_RtnRepealFromFutureToBankByFutureManual, 0, -1, 0, "", p ? SID_RspRepeal : -1, p, p ? (int)sizeof(*p) : 0);
|
|
480
584
|
}
|
|
481
585
|
|
|
@@ -504,10 +608,14 @@ void TraderSpi::OnErrRtnQueryBankBalanceByFuture(CThostFtdcReqQueryAccountField
|
|
|
504
608
|
}
|
|
505
609
|
|
|
506
610
|
void TraderSpi::OnRtnRepealFromBankToFutureByFuture(CThostFtdcRspRepealField *p) {
|
|
611
|
+
if (p && risk_)
|
|
612
|
+
risk_->recordUnsupportedRiskMutation();
|
|
507
613
|
ch_->push(ET_RtnRepealFromBankToFutureByFuture, 0, -1, 0, "", p ? SID_RspRepeal : -1, p, p ? (int)sizeof(*p) : 0);
|
|
508
614
|
}
|
|
509
615
|
|
|
510
616
|
void TraderSpi::OnRtnRepealFromFutureToBankByFuture(CThostFtdcRspRepealField *p) {
|
|
617
|
+
if (p && risk_)
|
|
618
|
+
risk_->recordUnsupportedRiskMutation();
|
|
511
619
|
ch_->push(ET_RtnRepealFromFutureToBankByFuture, 0, -1, 0, "", p ? SID_RspRepeal : -1, p, p ? (int)sizeof(*p) : 0);
|
|
512
620
|
}
|
|
513
621
|
|
|
@@ -668,6 +776,8 @@ void TraderSpi::OnRspCancelOffsetSetting(CThostFtdcInputOffsetSettingField *p, C
|
|
|
668
776
|
}
|
|
669
777
|
|
|
670
778
|
void TraderSpi::OnRtnOffsetSetting(CThostFtdcOffsetSettingField *p) {
|
|
779
|
+
if (p && risk_)
|
|
780
|
+
risk_->recordUnsupportedRiskMutation();
|
|
671
781
|
ch_->push(ET_RtnOffsetSetting, 0, -1, 0, "", p ? SID_OffsetSetting : -1, p, p ? (int)sizeof(*p) : 0);
|
|
672
782
|
}
|
|
673
783
|
|
|
@@ -700,6 +810,8 @@ void TraderSpi::OnRspQrySpdApply(CThostFtdcSpdApplyField *p, CThostFtdcRspInfoFi
|
|
|
700
810
|
}
|
|
701
811
|
|
|
702
812
|
void TraderSpi::OnRtnSpdApply(CThostFtdcSpdApplyField *p) {
|
|
813
|
+
if (p && risk_)
|
|
814
|
+
risk_->recordUnsupportedRiskMutation();
|
|
703
815
|
ch_->push(ET_RtnSpdApply, 0, -1, 0, "", p ? SID_SpdApply : -1, p, p ? (int)sizeof(*p) : 0);
|
|
704
816
|
}
|
|
705
817
|
|
|
@@ -724,6 +836,8 @@ void TraderSpi::OnRspQryHedgeCfm(CThostFtdcHedgeCfmField *p, CThostFtdcRspInfoFi
|
|
|
724
836
|
}
|
|
725
837
|
|
|
726
838
|
void TraderSpi::OnRtnHedgeCfm(CThostFtdcHedgeCfmField *p) {
|
|
839
|
+
if (p && risk_)
|
|
840
|
+
risk_->recordUnsupportedRiskMutation();
|
|
727
841
|
ch_->push(ET_RtnHedgeCfm, 0, -1, 0, "", p ? SID_HedgeCfm : -1, p, p ? (int)sizeof(*p) : 0);
|
|
728
842
|
}
|
|
729
843
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
#ifndef CTP_TRADERSPI_GEN_H
|
|
3
3
|
#define CTP_TRADERSPI_GEN_H
|
|
4
4
|
#include "ThostFtdcTraderApi.h"
|
|
5
|
+
#include "../native/arm.h"
|
|
5
6
|
#include "../native/channel.h"
|
|
6
7
|
#include "../native/risk.h"
|
|
7
8
|
namespace ctp {
|
|
@@ -189,10 +190,11 @@ enum {
|
|
|
189
190
|
|
|
190
191
|
class TraderSpi : public CThostFtdcTraderSpi {
|
|
191
192
|
public:
|
|
192
|
-
TraderSpi(
|
|
193
|
+
explicit TraderSpi(EventChannel *channel) : ch_(channel) {}
|
|
193
194
|
~TraderSpi() {}
|
|
194
195
|
|
|
195
196
|
void setRisk(RiskEngine *r) { risk_ = r; }
|
|
197
|
+
void setArmRegistry(ArmRegistry *a) { arm_ = a; }
|
|
196
198
|
|
|
197
199
|
void OnFrontConnected() override;
|
|
198
200
|
void OnFrontDisconnected(int arg) override;
|
|
@@ -374,9 +376,9 @@ public:
|
|
|
374
376
|
void OnErrRtnHedgeCfmAction(CThostFtdcHedgeCfmActionField *p, CThostFtdcRspInfoField *e) override;
|
|
375
377
|
|
|
376
378
|
private:
|
|
377
|
-
CThostFtdcTraderApi *api_;
|
|
378
379
|
EventChannel *ch_;
|
|
379
380
|
RiskEngine *risk_ = nullptr;
|
|
381
|
+
ArmRegistry *arm_ = nullptr;
|
|
380
382
|
};
|
|
381
383
|
} // namespace ctp
|
|
382
384
|
#endif
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,17 @@
|
|
|
5
5
|
export { MarketData, MarketDataEvent } from "./market-data.js";
|
|
6
6
|
export type { MdLoginReq } from "./market-data.js";
|
|
7
7
|
export { Trader, TraderEvent } from "./trader.js";
|
|
8
|
-
export type {
|
|
8
|
+
export type {
|
|
9
|
+
RiskLimits,
|
|
10
|
+
InstrumentPositionLimit,
|
|
11
|
+
PositionSeed,
|
|
12
|
+
MarginRateSyncOptions,
|
|
13
|
+
TraderSessionIdentity,
|
|
14
|
+
TraderSessionResult,
|
|
15
|
+
SessionOptions,
|
|
16
|
+
ArmSpec,
|
|
17
|
+
ArmHandle,
|
|
18
|
+
} from "./trader.js";
|
|
9
19
|
export { CtpClient } from "./client.js";
|
|
10
20
|
export type { CallbackOptions, RspInfo } from "./client.js";
|
|
11
21
|
|