@hitrading/ctp-node 1.2.0 → 3.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.
Files changed (104) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.md +52 -31
  3. package/README.zh-CN.md +42 -26
  4. package/RELEASING.md +78 -0
  5. package/binding.gyp +13 -13
  6. package/dist/client.d.ts +40 -15
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/client.js +241 -62
  9. package/dist/client.js.map +1 -1
  10. package/dist/codec.d.ts.map +1 -1
  11. package/dist/codec.js +84 -19
  12. package/dist/codec.js.map +1 -1
  13. package/dist/generated/structs.gen.d.ts +5461 -5461
  14. package/dist/generated/structs.gen.d.ts.map +1 -1
  15. package/dist/generated/trader.gen.d.ts.map +1 -1
  16. package/dist/generated/trader.gen.js +788 -94
  17. package/dist/generated/trader.gen.js.map +1 -1
  18. package/dist/index.cjs +1896 -420
  19. package/dist/index.d.cts +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/market-data.d.ts +48 -21
  24. package/dist/market-data.d.ts.map +1 -1
  25. package/dist/market-data.js +165 -26
  26. package/dist/market-data.js.map +1 -1
  27. package/dist/native-binding.d.ts.map +1 -1
  28. package/dist/native-binding.js +5 -1
  29. package/dist/native-binding.js.map +1 -1
  30. package/dist/trader.d.ts +127 -79
  31. package/dist/trader.d.ts.map +1 -1
  32. package/dist/trader.js +788 -200
  33. package/dist/trader.js.map +1 -1
  34. package/dist/validation.d.ts +27 -0
  35. package/dist/validation.d.ts.map +1 -0
  36. package/dist/validation.js +85 -0
  37. package/dist/validation.js.map +1 -0
  38. package/docs/API.md +1437 -0
  39. package/docs/API.zh-CN.md +1278 -0
  40. package/docs/MIGRATION.md +54 -0
  41. package/docs/assets/validation.svg +27 -0
  42. package/docs/integration.md +60 -0
  43. package/docs/native-hooks.md +281 -0
  44. package/docs/native-hooks.zh-CN.md +205 -0
  45. package/docs/troubleshooting.md +257 -0
  46. package/docs/troubleshooting.zh-CN.md +220 -0
  47. package/package.json +14 -6
  48. package/prebuilds/linux-x64/@hitrading+ctp-node.node +0 -0
  49. package/prebuilds/win32-x64/@hitrading+ctp-node.node +0 -0
  50. package/scripts/bench-decode.mjs +37 -0
  51. package/scripts/bench-fullmarket-offline.mjs +207 -0
  52. package/scripts/stress-fullmarket.mjs +255 -0
  53. package/src/addon.cc +2 -2
  54. package/src/client.ts +263 -65
  55. package/src/codec.ts +86 -19
  56. package/src/generated/structs.gen.ts +5461 -5461
  57. package/src/generated/trader.gen.ts +309 -94
  58. package/src/generated/traderreq.gen.cc +194 -18
  59. package/src/generated/traderreq.gen.h +4 -0
  60. package/src/generated/traderspi.gen.cc +130 -10
  61. package/src/generated/traderspi.gen.h +4 -2
  62. package/src/index.ts +8 -1
  63. package/src/market-data.ts +219 -43
  64. package/src/native/arm.cc +114 -30
  65. package/src/native/arm.h +16 -4
  66. package/src/native/channel.cc +209 -81
  67. package/src/native/channel.h +65 -24
  68. package/src/native/ctp_field.h +23 -0
  69. package/src/native/mdapi.cc +621 -61
  70. package/src/native/mdspi.cc +221 -14
  71. package/src/native/mdspi.h +62 -9
  72. package/src/native/order_capability.h +75 -0
  73. package/src/native/risk.cc +2051 -205
  74. package/src/native/risk.h +450 -57
  75. package/src/native/shared_handle.h +37 -0
  76. package/src/native/snapshot.h +120 -0
  77. package/src/native/traderapi.cc +749 -170
  78. package/src/native-binding.ts +5 -1
  79. package/src/trader.ts +993 -229
  80. package/src/validation.ts +96 -0
  81. /package/{tradeapi → ctpsdk}/ThostFtdcMdApi.h +0 -0
  82. /package/{tradeapi → ctpsdk}/ThostFtdcTraderApi.h +0 -0
  83. /package/{tradeapi → ctpsdk}/ThostFtdcUserApiDataType.h +0 -0
  84. /package/{tradeapi → ctpsdk}/ThostFtdcUserApiStruct.h +0 -0
  85. /package/{tradeapi → ctpsdk}/error.dtd +0 -0
  86. /package/{tradeapi → ctpsdk}/error.xml +0 -0
  87. /package/{tradeapi → ctpsdk}/linux/thostmduserapi_se.so +0 -0
  88. /package/{tradeapi → ctpsdk}/linux/thosttraderapi_se.so +0 -0
  89. /package/{tradeapi → ctpsdk}/macos/thostmduserapi_se.framework/Versions/A/Headers/ThostFtdcMdApi.h +0 -0
  90. /package/{tradeapi → ctpsdk}/macos/thostmduserapi_se.framework/Versions/A/Headers/ThostFtdcUserApiDataType.h +0 -0
  91. /package/{tradeapi → ctpsdk}/macos/thostmduserapi_se.framework/Versions/A/Headers/ThostFtdcUserApiStruct.h +0 -0
  92. /package/{tradeapi → ctpsdk}/macos/thostmduserapi_se.framework/Versions/A/Resources/Info.plist +0 -0
  93. /package/{tradeapi → ctpsdk}/macos/thostmduserapi_se.framework/Versions/A/_CodeSignature/CodeResources +0 -0
  94. /package/{tradeapi → ctpsdk}/macos/thostmduserapi_se.framework/Versions/A/thostmduserapi_se +0 -0
  95. /package/{tradeapi → ctpsdk}/macos/thosttraderapi_se.framework/Versions/A/Headers/ThostFtdcTraderApi.h +0 -0
  96. /package/{tradeapi → ctpsdk}/macos/thosttraderapi_se.framework/Versions/A/Headers/ThostFtdcUserApiDataType.h +0 -0
  97. /package/{tradeapi → ctpsdk}/macos/thosttraderapi_se.framework/Versions/A/Headers/ThostFtdcUserApiStruct.h +0 -0
  98. /package/{tradeapi → ctpsdk}/macos/thosttraderapi_se.framework/Versions/A/Resources/Info.plist +0 -0
  99. /package/{tradeapi → ctpsdk}/macos/thosttraderapi_se.framework/Versions/A/_CodeSignature/CodeResources +0 -0
  100. /package/{tradeapi → ctpsdk}/macos/thosttraderapi_se.framework/Versions/A/thosttraderapi_se +0 -0
  101. /package/{tradeapi → ctpsdk}/windows/thostmduserapi_se.dll +0 -0
  102. /package/{tradeapi → ctpsdk}/windows/thostmduserapi_se.lib +0 -0
  103. /package/{tradeapi → ctpsdk}/windows/thosttraderapi_se.dll +0 -0
  104. /package/{tradeapi → ctpsdk}/windows/thosttraderapi_se.lib +0 -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 (p && risk_)
32
- risk_->setSession(p->FrontID, p->SessionID);
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 (p && risk_)
62
- risk_->releaseReservation(p->OrderRef);
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,6 +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) {
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);
201
+ }
202
+ if (risk_ && last) risk_->finishMarginScheduleQuery(id, eid(e) == 0);
155
203
  ch_->push(ET_RspQryInstrumentMarginRate, id, last ? 1 : 0, eid(e), emsg(e), p ? SID_InstrumentMarginRate : -1, p, p ? (int)sizeof(*p) : 0);
156
204
  }
157
205
 
@@ -172,6 +220,13 @@ void TraderSpi::OnRspQryProduct(CThostFtdcProductField *p, CThostFtdcRspInfoFiel
172
220
  }
173
221
 
174
222
  void TraderSpi::OnRspQryInstrument(CThostFtdcInstrumentField *p, CThostFtdcRspInfoField *e, int id, bool last) {
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
+ }
175
230
  ch_->push(ET_RspQryInstrument, id, last ? 1 : 0, eid(e), emsg(e), p ? SID_Instrument : -1, p, p ? (int)sizeof(*p) : 0);
176
231
  }
177
232
 
@@ -220,6 +275,12 @@ void TraderSpi::OnRspQryInvestorProductGroupMargin(CThostFtdcInvestorProductGrou
220
275
  }
221
276
 
222
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);
223
284
  ch_->push(ET_RspQryExchangeMarginRate, id, last ? 1 : 0, eid(e), emsg(e), p ? SID_ExchangeMarginRate : -1, p, p ? (int)sizeof(*p) : 0);
224
285
  }
225
286
 
@@ -316,20 +377,45 @@ void TraderSpi::OnRspError(CThostFtdcRspInfoField *e, int id, bool last) {
316
377
  }
317
378
 
318
379
  void TraderSpi::OnRtnOrder(CThostFtdcOrderField *p) {
319
- if (p && risk_)
320
- risk_->onOrderUpdate(p->FrontID, p->SessionID, p->OrderRef, p->InstrumentID, p->CombOffsetFlag[0] == '0', p->Direction == '0', p->OrderStatus, p->LimitPrice, p->VolumeTotalOriginal, p->VolumeTraded);
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
+ }
321
390
  ch_->push(ET_RtnOrder, 0, -1, 0, "", p ? SID_Order : -1, p, p ? (int)sizeof(*p) : 0);
322
391
  }
323
392
 
324
393
  void TraderSpi::OnRtnTrade(CThostFtdcTradeField *p) {
325
- if (p && risk_)
326
- risk_->onTrade(p->InstrumentID, p->Direction == '0', p->OffsetFlag == '0', p->Price, p->Volume);
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
+ }
327
410
  ch_->push(ET_RtnTrade, 0, -1, 0, "", p ? SID_Trade : -1, p, p ? (int)sizeof(*p) : 0);
328
411
  }
329
412
 
330
413
  void TraderSpi::OnErrRtnOrderInsert(CThostFtdcInputOrderField *p, CThostFtdcRspInfoField *e) {
331
- if (p && risk_)
332
- risk_->releaseReservation(p->OrderRef);
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
+ }
333
419
  ch_->push(ET_ErrRtnOrderInsert, 0, -1, eid(e), emsg(e), p ? SID_InputOrder : -1, p, p ? (int)sizeof(*p) : 0);
334
420
  }
335
421
 
@@ -354,6 +440,8 @@ void TraderSpi::OnRtnErrorConditionalOrder(CThostFtdcErrorConditionalOrderField
354
440
  }
355
441
 
356
442
  void TraderSpi::OnRtnExecOrder(CThostFtdcExecOrderField *p) {
443
+ if (p && risk_)
444
+ risk_->recordUnsupportedRiskMutation();
357
445
  ch_->push(ET_RtnExecOrder, 0, -1, 0, "", p ? SID_ExecOrder : -1, p, p ? (int)sizeof(*p) : 0);
358
446
  }
359
447
 
@@ -370,6 +458,8 @@ void TraderSpi::OnErrRtnForQuoteInsert(CThostFtdcInputForQuoteField *p, CThostFt
370
458
  }
371
459
 
372
460
  void TraderSpi::OnRtnQuote(CThostFtdcQuoteField *p) {
461
+ if (p && risk_)
462
+ risk_->recordUnsupportedRiskMutation();
373
463
  ch_->push(ET_RtnQuote, 0, -1, 0, "", p ? SID_Quote : -1, p, p ? (int)sizeof(*p) : 0);
374
464
  }
375
465
 
@@ -394,6 +484,8 @@ void TraderSpi::OnErrRtnBatchOrderAction(CThostFtdcBatchOrderActionField *p, CTh
394
484
  }
395
485
 
396
486
  void TraderSpi::OnRtnOptionSelfClose(CThostFtdcOptionSelfCloseField *p) {
487
+ if (p && risk_)
488
+ risk_->recordUnsupportedRiskMutation();
397
489
  ch_->push(ET_RtnOptionSelfClose, 0, -1, 0, "", p ? SID_OptionSelfClose : -1, p, p ? (int)sizeof(*p) : 0);
398
490
  }
399
491
 
@@ -406,6 +498,8 @@ void TraderSpi::OnErrRtnOptionSelfCloseAction(CThostFtdcOptionSelfCloseActionFie
406
498
  }
407
499
 
408
500
  void TraderSpi::OnRtnCombAction(CThostFtdcCombActionField *p) {
501
+ if (p && risk_)
502
+ risk_->recordUnsupportedRiskMutation();
409
503
  ch_->push(ET_RtnCombAction, 0, -1, 0, "", p ? SID_CombAction : -1, p, p ? (int)sizeof(*p) : 0);
410
504
  }
411
505
 
@@ -442,34 +536,50 @@ void TraderSpi::OnRspQueryCFMMCTradingAccountToken(CThostFtdcQueryCFMMCTradingAc
442
536
  }
443
537
 
444
538
  void TraderSpi::OnRtnFromBankToFutureByBank(CThostFtdcRspTransferField *p) {
539
+ if (p && risk_)
540
+ risk_->recordUnsupportedRiskMutation();
445
541
  ch_->push(ET_RtnFromBankToFutureByBank, 0, -1, 0, "", p ? SID_RspTransfer : -1, p, p ? (int)sizeof(*p) : 0);
446
542
  }
447
543
 
448
544
  void TraderSpi::OnRtnFromFutureToBankByBank(CThostFtdcRspTransferField *p) {
545
+ if (p && risk_)
546
+ risk_->recordUnsupportedRiskMutation();
449
547
  ch_->push(ET_RtnFromFutureToBankByBank, 0, -1, 0, "", p ? SID_RspTransfer : -1, p, p ? (int)sizeof(*p) : 0);
450
548
  }
451
549
 
452
550
  void TraderSpi::OnRtnRepealFromBankToFutureByBank(CThostFtdcRspRepealField *p) {
551
+ if (p && risk_)
552
+ risk_->recordUnsupportedRiskMutation();
453
553
  ch_->push(ET_RtnRepealFromBankToFutureByBank, 0, -1, 0, "", p ? SID_RspRepeal : -1, p, p ? (int)sizeof(*p) : 0);
454
554
  }
455
555
 
456
556
  void TraderSpi::OnRtnRepealFromFutureToBankByBank(CThostFtdcRspRepealField *p) {
557
+ if (p && risk_)
558
+ risk_->recordUnsupportedRiskMutation();
457
559
  ch_->push(ET_RtnRepealFromFutureToBankByBank, 0, -1, 0, "", p ? SID_RspRepeal : -1, p, p ? (int)sizeof(*p) : 0);
458
560
  }
459
561
 
460
562
  void TraderSpi::OnRtnFromBankToFutureByFuture(CThostFtdcRspTransferField *p) {
563
+ if (p && risk_)
564
+ risk_->recordUnsupportedRiskMutation();
461
565
  ch_->push(ET_RtnFromBankToFutureByFuture, 0, -1, 0, "", p ? SID_RspTransfer : -1, p, p ? (int)sizeof(*p) : 0);
462
566
  }
463
567
 
464
568
  void TraderSpi::OnRtnFromFutureToBankByFuture(CThostFtdcRspTransferField *p) {
569
+ if (p && risk_)
570
+ risk_->recordUnsupportedRiskMutation();
465
571
  ch_->push(ET_RtnFromFutureToBankByFuture, 0, -1, 0, "", p ? SID_RspTransfer : -1, p, p ? (int)sizeof(*p) : 0);
466
572
  }
467
573
 
468
574
  void TraderSpi::OnRtnRepealFromBankToFutureByFutureManual(CThostFtdcRspRepealField *p) {
575
+ if (p && risk_)
576
+ risk_->recordUnsupportedRiskMutation();
469
577
  ch_->push(ET_RtnRepealFromBankToFutureByFutureManual, 0, -1, 0, "", p ? SID_RspRepeal : -1, p, p ? (int)sizeof(*p) : 0);
470
578
  }
471
579
 
472
580
  void TraderSpi::OnRtnRepealFromFutureToBankByFutureManual(CThostFtdcRspRepealField *p) {
581
+ if (p && risk_)
582
+ risk_->recordUnsupportedRiskMutation();
473
583
  ch_->push(ET_RtnRepealFromFutureToBankByFutureManual, 0, -1, 0, "", p ? SID_RspRepeal : -1, p, p ? (int)sizeof(*p) : 0);
474
584
  }
475
585
 
@@ -498,10 +608,14 @@ void TraderSpi::OnErrRtnQueryBankBalanceByFuture(CThostFtdcReqQueryAccountField
498
608
  }
499
609
 
500
610
  void TraderSpi::OnRtnRepealFromBankToFutureByFuture(CThostFtdcRspRepealField *p) {
611
+ if (p && risk_)
612
+ risk_->recordUnsupportedRiskMutation();
501
613
  ch_->push(ET_RtnRepealFromBankToFutureByFuture, 0, -1, 0, "", p ? SID_RspRepeal : -1, p, p ? (int)sizeof(*p) : 0);
502
614
  }
503
615
 
504
616
  void TraderSpi::OnRtnRepealFromFutureToBankByFuture(CThostFtdcRspRepealField *p) {
617
+ if (p && risk_)
618
+ risk_->recordUnsupportedRiskMutation();
505
619
  ch_->push(ET_RtnRepealFromFutureToBankByFuture, 0, -1, 0, "", p ? SID_RspRepeal : -1, p, p ? (int)sizeof(*p) : 0);
506
620
  }
507
621
 
@@ -662,6 +776,8 @@ void TraderSpi::OnRspCancelOffsetSetting(CThostFtdcInputOffsetSettingField *p, C
662
776
  }
663
777
 
664
778
  void TraderSpi::OnRtnOffsetSetting(CThostFtdcOffsetSettingField *p) {
779
+ if (p && risk_)
780
+ risk_->recordUnsupportedRiskMutation();
665
781
  ch_->push(ET_RtnOffsetSetting, 0, -1, 0, "", p ? SID_OffsetSetting : -1, p, p ? (int)sizeof(*p) : 0);
666
782
  }
667
783
 
@@ -694,6 +810,8 @@ void TraderSpi::OnRspQrySpdApply(CThostFtdcSpdApplyField *p, CThostFtdcRspInfoFi
694
810
  }
695
811
 
696
812
  void TraderSpi::OnRtnSpdApply(CThostFtdcSpdApplyField *p) {
813
+ if (p && risk_)
814
+ risk_->recordUnsupportedRiskMutation();
697
815
  ch_->push(ET_RtnSpdApply, 0, -1, 0, "", p ? SID_SpdApply : -1, p, p ? (int)sizeof(*p) : 0);
698
816
  }
699
817
 
@@ -718,6 +836,8 @@ void TraderSpi::OnRspQryHedgeCfm(CThostFtdcHedgeCfmField *p, CThostFtdcRspInfoFi
718
836
  }
719
837
 
720
838
  void TraderSpi::OnRtnHedgeCfm(CThostFtdcHedgeCfmField *p) {
839
+ if (p && risk_)
840
+ risk_->recordUnsupportedRiskMutation();
721
841
  ch_->push(ET_RtnHedgeCfm, 0, -1, 0, "", p ? SID_HedgeCfm : -1, p, p ? (int)sizeof(*p) : 0);
722
842
  }
723
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(CThostFtdcTraderApi *api, EventChannel *channel) : api_(api), ch_(channel) {}
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,14 @@
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 { RiskConfig, LotCap, SessionOptions, ArmSpec, ArmHandle } from "./trader.js";
8
+ export type {
9
+ RiskLimits,
10
+ InstrumentPositionLimit,
11
+ PositionSeed,
12
+ SessionOptions,
13
+ ArmSpec,
14
+ ArmHandle,
15
+ } from "./trader.js";
9
16
  export { CtpClient } from "./client.js";
10
17
  export type { CallbackOptions, RspInfo } from "./client.js";
11
18