@hitrading/ctp-node 4.2.1-rc.1 → 4.2.1

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 CHANGED
@@ -1,4 +1,4 @@
1
- ## [4.2.1-rc.1](https://github.com/hitrading/ctp-node/compare/v4.2.0...v4.2.1-rc.1) (2026-11-24)
1
+ ## [4.2.1](https://github.com/hitrading/ctp-node/compare/v4.2.0...v4.2.1) (2026-11-24)
2
2
 
3
3
 
4
4
  ### Bug Fixes
@@ -6,6 +6,8 @@
6
6
  * **risk:** 对成交先到的终态核验实际成交手数 ([f5f8ad3](https://github.com/hitrading/ctp-node/commit/f5f8ad3842ee3962df68f213c98781bf4ea8bf05))
7
7
  * **risk:** 核对成交身份与开仓委托终态凭证 ([0649ec1](https://github.com/hitrading/ctp-node/commit/0649ec1daaca390598655b0345e36cbf8752d736))
8
8
  * **risk:** 核验成交数量并统一交易所回报编号 ([4bdac73](https://github.com/hitrading/ctp-node/commit/4bdac733d9783ae045953962490eeb1ec90ab754))
9
+ * **risk:** 禁止同号快照恢复已矛盾的委托终态凭证 ([c25e49c](https://github.com/hitrading/ctp-node/commit/c25e49c5ae4b6830990120e15bc263fc5adff9ff))
10
+ * **risk:** 首次终态也须核对已知委托的原始手数 ([f35c682](https://github.com/hitrading/ctp-node/commit/f35c682870f7b0959c3aa7a69661f28b17239fd0))
9
11
 
10
12
  # [4.2.0](https://github.com/hitrading/ctp-node/compare/v4.1.3...v4.2.0) (2026-11-24)
11
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hitrading/ctp-node",
3
- "version": "4.2.1-rc.1",
3
+ "version": "4.2.1",
4
4
  "description": "High-performance, type-safe CTP (Chinese futures) binding for Node.js",
5
5
  "keywords": [
6
6
  "ctp",
@@ -1727,8 +1727,7 @@ void RiskEngine::onOrderUpdate(int frontId, int sessionId,
1727
1727
  if (sit != orderStates_.end() &&
1728
1728
  (sit->second.conflictingTerminal || !sit->second.matchesOpening(instrumentId, isLong, hedgeFlag) ||
1729
1729
  (sit->second.terminal && !sit->second.matchesFinalVolume(volTotal, volTraded, terminal)))) {
1730
- if (sit->second.terminal && terminal && sit->second.orderSysKey == orderSysKey)
1731
- sit->second.conflictingTerminal = true;
1730
+ sit->second.recordTerminalConflict(orderSysKey);
1732
1731
  orderLedgerUncertain_ = true;
1733
1732
  revision_.fetch_add(1, std::memory_order_release);
1734
1733
  return;
@@ -1769,7 +1768,8 @@ void RiskEngine::onOrderUpdate(int frontId, int sessionId,
1769
1768
  revision_.fetch_add(1, std::memory_order_release);
1770
1769
  return;
1771
1770
  }
1772
- if (terminal && (volTraded < s.reportedTraded || volTraded < s.appliedTraded)) {
1771
+ if (terminal && (volTotal != s.originalVolume ||
1772
+ volTraded < s.reportedTraded || volTraded < s.appliedTraded)) {
1773
1773
  orderLedgerUncertain_ = true;
1774
1774
  revision_.fetch_add(1, std::memory_order_release);
1775
1775
  return;
@@ -1889,8 +1889,7 @@ void RiskEngine::onUnsupportedOrderUpdate(int frontId, int sessionId,
1889
1889
  auto state = orderStates_.find(key);
1890
1890
  if (state != orderStates_.end()) {
1891
1891
  if (!state->second.instrumentId.empty()) {
1892
- if (state->second.terminal && terminalOrderStatus(status) && state->second.orderSysKey == orderSysKey)
1893
- state->second.conflictingTerminal = true;
1892
+ state->second.recordTerminalConflict(orderSysKey);
1894
1893
  orderLedgerUncertain_ = true;
1895
1894
  revision_.fetch_add(1, std::memory_order_release);
1896
1895
  return;
@@ -2214,15 +2213,22 @@ bool RiskEngine::rebuildOpenReservationsLocked(
2214
2213
  // skipped. A different concrete id proves key reuse and may supersede the
2215
2214
  // tombstone. Without both fingerprints the snapshot is ambiguous and must
2216
2215
  // leave the current ledger intact and fail closed.
2216
+ bool canRebuild = true;
2217
2217
  for (const auto &o : orders) {
2218
2218
  const std::string key = resvKey(o.frontId, o.sessionId, o.orderRef);
2219
2219
  auto tomb = orderStates_.find(key);
2220
2220
  if (tomb != orderStates_.end() && tomb->second.terminal &&
2221
2221
  !tomb->second.canReconcileWorking(o)) {
2222
- orderLedgerUncertain_ = true;
2223
- return false;
2222
+ // Contradictory evidence for a concrete exchange order survives retries.
2223
+ // A later row that agrees with the old final count cannot restore proof.
2224
+ tomb->second.recordTerminalConflict(o.orderSysKey);
2225
+ canRebuild = false;
2224
2226
  }
2225
2227
  }
2228
+ if (!canRebuild) {
2229
+ orderLedgerUncertain_ = true;
2230
+ return false;
2231
+ }
2226
2232
  clearPendingLocked();
2227
2233
  for (const auto &o : orders) {
2228
2234
  const std::string key = resvKey(o.frontId, o.sessionId, o.orderRef);
package/src/native/risk.h CHANGED
@@ -452,6 +452,10 @@ private:
452
452
  char hedgeFlag = '\0';
453
453
  bool conflictingTerminal = false;
454
454
  double originalVolume = 0.0;
455
+ void recordTerminalConflict(const std::string &sys) {
456
+ if (terminal && !sys.empty() && sys == orderSysKey)
457
+ conflictingTerminal = true;
458
+ }
455
459
  bool matchesFinalVolume(double original, double traded, bool final) const {
456
460
  return original == originalVolume &&
457
461
  (final ? traded == reportedTraded : traded <= reportedTraded);