@hitrading/ctp-node 4.1.2 → 4.1.3-rc.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,3 +1,10 @@
1
+ ## [4.1.3-rc.1](https://github.com/hitrading/ctp-node/compare/v4.1.2...v4.1.3-rc.1) (2026-11-13)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **macos:** CTP 框架与头文件版本不一致时在构建期中止,不再编出运行时崩溃的插件 ([88de78f](https://github.com/hitrading/ctp-node/commit/88de78f956a12e43082a0bc6eb577694df96e94c))
7
+
1
8
  ## [4.1.2](https://github.com/hitrading/ctp-node/compare/v4.1.1...v4.1.2) (2026-11-13)
2
9
 
3
10
 
package/README.md CHANGED
@@ -12,7 +12,7 @@
12
12
  <a href="https://github.com/hitrading/ctp-node/actions/workflows/build.yml"><img alt="CI" src="https://github.com/hitrading/ctp-node/actions/workflows/build.yml/badge.svg"></a>
13
13
  <a href="LICENSE"><img alt="License" src="https://img.shields.io/github/license/hitrading/ctp-node?color=blue"></a>
14
14
  <img alt="Node" src="https://img.shields.io/badge/node-22.22.2%2B-brightgreen">
15
- <img alt="Platform" src="https://img.shields.io/badge/platform-Windows%20%7C%20Linux%20%7C%20macOS-lightgrey">
15
+ <img alt="Platform" src="https://img.shields.io/badge/platform-Windows%20x64%20%7C%20Linux%20x64-lightgrey">
16
16
  <img alt="TypeScript" src="https://img.shields.io/badge/TypeScript-strict-3178c6">
17
17
  <img alt="decode" src="https://img.shields.io/badge/decode-~8M%20ticks%2Fs-ff7f0e">
18
18
  </p>
@@ -41,7 +41,7 @@
41
41
 
42
42
  ## Requirements
43
43
 
44
- Node 22.22.2+ on supported even-numbered release lines (`^22.22.2 || ^24.15.0 || >=26.0.0`). This mirrors the Node.js range required by the bundled `node-gyp`; odd-numbered/EOL releases and Node 24.0–24.14 are not supported. Prebuilt binaries are shipped for **Windows and Linux (x64)** — most users need no compiler there. **macOS (and any other platform) builds from source on install**, which needs a C++ toolchain (macOS: Xcode Command Line Tools; Windows: VS Build Tools; Linux: clang/gcc). The CTP shared libraries are bundled next to the loaded addon and resolved automatically.
44
+ Node 22.22.2+ on supported even-numbered release lines (`^22.22.2 || ^24.15.0 || >=26.0.0`). This mirrors the Node.js range required by the bundled `node-gyp`; odd-numbered/EOL releases and Node 24.0–24.14 are not supported. Prebuilt binaries are shipped for **Windows and Linux (x64)** — most users need no compiler there. **macOS is not supported at the moment**: the bundled CTP macOS frameworks are CTP 6.7.7, while the headers and the Windows/Linux libraries are 6.7.13. An addon built from that mix links but crashes at runtime, so on macOS the install-time build stops with an explanation instead; use a Windows or Linux x64 host. Where no prebuild matches, the addon builds from source on install, which needs a C++ toolchain (Windows: VS Build Tools; Linux: clang/gcc). The CTP shared libraries are bundled next to the loaded addon and resolved automatically.
45
45
 
46
46
  ## Install
47
47
 
package/README.zh-CN.md CHANGED
@@ -12,7 +12,7 @@
12
12
  <a href="https://github.com/hitrading/ctp-node/actions/workflows/build.yml"><img alt="CI" src="https://github.com/hitrading/ctp-node/actions/workflows/build.yml/badge.svg"></a>
13
13
  <a href="LICENSE"><img alt="License" src="https://img.shields.io/github/license/hitrading/ctp-node?color=blue"></a>
14
14
  <img alt="Node" src="https://img.shields.io/badge/node-22.22.2%2B-brightgreen">
15
- <img alt="Platform" src="https://img.shields.io/badge/platform-Windows%20%7C%20Linux%20%7C%20macOS-lightgrey">
15
+ <img alt="Platform" src="https://img.shields.io/badge/platform-Windows%20x64%20%7C%20Linux%20x64-lightgrey">
16
16
  <img alt="TypeScript" src="https://img.shields.io/badge/TypeScript-strict-3178c6">
17
17
  <img alt="decode" src="https://img.shields.io/badge/decode-~8M%20ticks%2Fs-ff7f0e">
18
18
  </p>
@@ -37,7 +37,7 @@
37
37
 
38
38
  ## 环境要求
39
39
 
40
- 受支持的偶数版本线要求 Node 22.22.2+(`^22.22.2 || ^24.15.0 || >=26.0.0`)。该范围与内置 `node-gyp` 的 Node.js 要求一致;不支持奇数/EOL 版本及 Node 24.0–24.14。**Windows 与 Linux(x64)提供预编译二进制**,这两个平台多数用户无需编译器。**macOS(及其他平台)在安装时从源码构建**,需要 C++ 工具链(macOS:Xcode Command Line Tools;Windows:VS Build Tools;Linux:clang/gcc)。CTP 共享库随插件一起打包在旁并自动解析。
40
+ 受支持的偶数版本线要求 Node 22.22.2+(`^22.22.2 || ^24.15.0 || >=26.0.0`)。该范围与内置 `node-gyp` 的 Node.js 要求一致;不支持奇数/EOL 版本及 Node 24.0–24.14。**Windows 与 Linux(x64)提供预编译二进制**,这两个平台多数用户无需编译器。**目前不支持 macOS**:随包的 CTP macOS 框架是 6.7.7,而头文件和 Windows/Linux 库是 6.7.13,混在一起编出的插件能链接、运行时却会崩溃,所以在 macOS 上安装时的构建会直接中止并给出说明;请使用 Windows 或 Linux x64 主机。没有匹配的预编译件时,安装时从源码构建,需要 C++ 工具链(Windows:VS Build Tools;Linux:clang/gcc)。CTP 共享库随插件一起打包在旁并自动解析。
41
41
 
42
42
  ## 安装
43
43
 
package/RELEASING.md CHANGED
@@ -12,7 +12,9 @@ On every push to `master` (stable) or `next` (`rc` prerelease), the CI
12
12
  [`build & prebuild`](.github/workflows/build.yml) workflow:
13
13
 
14
14
  1. builds + tests + prebuilds on Windows / Linux, plus a decoupled best-effort
15
- macOS build;
15
+ macOS build (currently disabled: the bundled CTP macOS frameworks are 6.7.7
16
+ while the headers and Windows/Linux libraries are 6.7.13, see the
17
+ `build-macos` comment in the workflow);
16
18
  2. runs `semantic-release`, which reads the commits since the last release and:
17
19
  - **decides the next version** from the commit types (see below),
18
20
  - updates [`CHANGELOG.md`](CHANGELOG.md) and the `package.json` version,
package/binding.gyp CHANGED
@@ -69,6 +69,15 @@
69
69
  ]
70
70
  }],
71
71
  ["OS=='mac'", {
72
+ # The vendored frameworks must be the same CTP version as ctpsdk/*.h and
73
+ # the Windows/Linux libraries: a mismatched build still links (node-gyp
74
+ # uses -undefined dynamic_lookup on macOS) but segfaults at runtime. The
75
+ # check prints nothing when the versions match and otherwise fails
76
+ # configure with an explanation. gyp expands only the condition branch
77
+ # that applies, so it never runs on Windows/Linux.
78
+ "variables": {
79
+ "ctp_macos_sdk_check": "<!(node scripts/check-macos-sdk.cjs)"
80
+ },
72
81
  "include_dirs": [
73
82
  "<(module_root_dir)/ctpsdk/macos/thostmduserapi_se.framework/Versions/A/Headers",
74
83
  "<(module_root_dir)/ctpsdk/macos/thosttraderapi_se.framework/Versions/A/Headers"
package/docs/API.md CHANGED
@@ -37,8 +37,11 @@ npm install @hitrading/ctp-node
37
37
 
38
38
  Supported Node.js release lines are `^22.22.2 || ^24.15.0 || >=26.0.0`, matching
39
39
  the bundled node-gyp 13 requirement. Prebuilt binaries ship in the npm package
40
- for win32-x64 and linux-x64. macOS and other platforms build from source on
41
- install (a C++ toolchain + Python are required).
40
+ for win32-x64 and linux-x64. macOS is not supported at the moment: the bundled
41
+ CTP macOS frameworks (6.7.7) do not match the 6.7.13 headers, and a build from
42
+ them crashes at runtime, so the install-time build stops on macOS with an
43
+ explanation. Where no prebuild matches, the addon builds from source on install
44
+ (a C++ toolchain + Python are required).
42
45
 
43
46
  ---
44
47
 
package/docs/API.zh-CN.md CHANGED
@@ -34,8 +34,9 @@ npm install @hitrading/ctp-node
34
34
  ```
35
35
 
36
36
  支持的 Node.js 版本线为 `^22.22.2 || ^24.15.0 || >=26.0.0`,与内置 node-gyp 13 的要求一致。
37
- npm 包提供 win32-x64 与 linux-x64 预编译二进制;macOS 及其他平台在安装时从源码编译,需要
38
- C++ 工具链与 Python。
37
+ npm 包提供 win32-x64 与 linux-x64 预编译二进制。目前不支持 macOS:随包的 CTP macOS 框架(6.7.7)
38
+ 与 6.7.13 头文件不匹配,由它编出的插件运行时会崩溃,所以在 macOS 上安装时的构建会中止并给出说明。
39
+ 没有匹配的预编译件时,安装时从源码编译,需要 C++ 工具链与 Python。
39
40
 
40
41
  ---
41
42
 
package/docs/MIGRATION.md CHANGED
@@ -48,7 +48,11 @@ and margin schedule for an instrument have arrived (call `session()` or the
48
48
 
49
49
  ## Platform / toolchain
50
50
 
51
- - **macOS** is no longer shipped as a prebuild — it builds from source on
52
- install (Windows and Linux prebuilds are unchanged).
51
+ - **macOS** is no longer shipped as a prebuild (Windows and Linux prebuilds are
52
+ unchanged), and building it from source does not work either: the bundled
53
+ CTP macOS frameworks are 6.7.7, while the headers and Windows/Linux libraries
54
+ have been 6.7.13 since 1.2.0, so a macOS source build linked but crashed at
55
+ runtime. The macOS build now stops at configure time with an explanation;
56
+ macOS stays unsupported until a matching CTP Mac SDK is bundled.
53
57
  - **Node `engines`** is restricted to the range required by `node-gyp` 13
54
58
  (`^22.22.2 || ^24.15.0 || >=26.0.0`); Node 20 and older 22 lines are excluded.
@@ -218,7 +218,8 @@ CTP reconnects on its own — re-run your handshake **in place** on every
218
218
  | `LNK1104: cannot open file ... ctp.node` | a wedged/zombie `node` process still holds the addon | find and `taskkill /F` the stray node process, then rebuild. |
219
219
  | `fatal error LNK1103: 调试信息损坏` | stale/corrupt build object (e.g. interrupted/parallel build) | `npx node-gyp rebuild` (clean rebuild). |
220
220
  | `MODULE_NOT_FOUND: node-addon-api` on a consumer install | source build with the build deps missing | fixed — `node-addon-api`/`node-gyp` are runtime `dependencies`; on an unshipped platform a C++ toolchain + Python are still required. |
221
- | `.node` won't load on macOS arm64 / linux arm64 | no prebuild for that platform | it builds from source on install; ensure a toolchain is present. |
221
+ | macOS install fails: `ctp-node: refusing to build on macOS - CTP SDK version mismatch` | the bundled CTP macOS frameworks (6.7.7) are older than the 6.7.13 headers and Windows/Linux libraries; a build from them links (`-undefined dynamic_lookup`) but segfaults on the first API call, so `binding.gyp` stops it | macOS is not supported at the moment; use a Windows or Linux x64 host. (An older version that did build on macOS crashes at runtime for the same reason.) |
222
+ | `.node` won't load on linux arm64 | no prebuild for that platform | it builds from source on install; ensure a toolchain is present. |
222
223
  | C4819 codepage warning during build | Chinese comments in `.cc` under a GBK code page | harmless; ignore. |
223
224
 
224
225
  ---
@@ -183,7 +183,8 @@ npm run bench:fullmarket
183
183
  | `LNK1104: cannot open file ... ctp.node` | 一个卡死/僵尸 `node` 进程还占着该插件 | 找到并 `taskkill /F` 掉游离的 node 进程,再重新构建。 |
184
184
  | `fatal error LNK1103: 调试信息损坏` | 陈旧/损坏的构建产物(如被中断/并行构建) | `npx node-gyp rebuild`(干净重建)。 |
185
185
  | 使用方安装时 `MODULE_NOT_FOUND: node-addon-api` | 源码构建但缺构建依赖 | 已修复——`node-addon-api`/`node-gyp` 是运行时 `dependencies`;在未预编译的平台上仍需 C++ 工具链 + Python。 |
186
- | macOS arm64 / linux arm64 上 `.node` 加载失败 | 该平台无预编译 | 安装时从源码构建;确保有工具链。 |
186
+ | macOS 安装失败:`ctp-node: refusing to build on macOS - CTP SDK version mismatch` | 随包的 CTP macOS 框架(6.7.7)比 6.7.13 头文件和 Windows/Linux 库旧;由它编出的插件能链接(`-undefined dynamic_lookup`),但首次调用 API 就段错误,所以 `binding.gyp` 直接中止构建 | 目前不支持 macOS;请使用 Windows 或 Linux x64 主机。(旧版本若在 macOS 上编译成功,运行时同样会因此崩溃。) |
187
+ | linux arm64 上 `.node` 加载失败 | 该平台无预编译 | 安装时从源码构建;确保有工具链。 |
187
188
  | 构建时 C4819 代码页警告 | GBK 代码页下 `.cc` 里的中文注释 | 无害;忽略。 |
188
189
 
189
190
  ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hitrading/ctp-node",
3
- "version": "4.1.2",
3
+ "version": "4.1.3-rc.1",
4
4
  "description": "High-performance, type-safe CTP (Chinese futures) binding for Node.js",
5
5
  "keywords": [
6
6
  "ctp",
@@ -49,6 +49,7 @@
49
49
  "scripts/bench-decode.mjs",
50
50
  "scripts/bench-fullmarket-offline.mjs",
51
51
  "scripts/stress-fullmarket.mjs",
52
+ "scripts/check-macos-sdk.cjs",
52
53
  "dist/",
53
54
  "src/",
54
55
  "ctpsdk/",
@@ -65,7 +66,7 @@
65
66
  "build": "npm run gen && npm run build:native && npm run build:ts",
66
67
  "prebuild:napi": "prebuildify --napi",
67
68
  "install": "node-gyp-build",
68
- "test": "node scripts/test-codec.mjs && node scripts/test-md.mjs && node scripts/test-trader.mjs && node scripts/test-arm.mjs && node scripts/test-gbk.mjs && node scripts/test-lifecycle.mjs && node scripts/test-backpressure.mjs && node scripts/test-codec-edge.mjs && node scripts/test-md-unit.mjs && node scripts/test-client-unit.mjs && node scripts/test-trader-unit.mjs && node scripts/smoke-cjs.cjs && node scripts/test-product-rates.mjs",
69
+ "test": "node scripts/test-codec.mjs && node scripts/test-md.mjs && node scripts/test-trader.mjs && node scripts/test-arm.mjs && node scripts/test-gbk.mjs && node scripts/test-lifecycle.mjs && node scripts/test-backpressure.mjs && node scripts/test-codec-edge.mjs && node scripts/test-md-unit.mjs && node scripts/test-client-unit.mjs && node scripts/test-trader-unit.mjs && node scripts/smoke-cjs.cjs && node scripts/test-product-rates.mjs && node scripts/test-macos-sdk-guard.mjs",
69
70
  "coverage": "c8 --config .c8rc.json npm test",
70
71
  "test:cpp": "node scripts/test-cpp.mjs",
71
72
  "test:integration": "node scripts/integration/run.mjs",
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ * check-macos-sdk.cjs - build-time guard, run by binding.gyp on macOS only.
4
+ *
5
+ * The addon compiles against the CTP headers in ctpsdk/*.h, which belong to the
6
+ * Windows/Linux libraries in ctpsdk/windows and ctpsdk/linux. A macOS framework
7
+ * from another CTP version still compiles and links, because node-gyp links
8
+ * macOS addons with `-undefined dynamic_lookup`, but the result crashes at
9
+ * runtime: the factory signatures and the API/SPI vtables change between CTP
10
+ * versions (a v6.7.7 framework under v6.7.13 headers segfaults on the first
11
+ * CreateFtdcMdApi call). So refuse to configure unless every vendored framework
12
+ * binary reports the same CTP version (x.y.z) as the reference Linux library.
13
+ *
14
+ * Usage: node scripts/check-macos-sdk.cjs [package-root]
15
+ * Prints nothing and exits 0 when the versions match (binding.gyp ignores the
16
+ * output); otherwise explains on stderr and exits 1, which fails node-gyp.
17
+ */
18
+ "use strict";
19
+
20
+ const { readFileSync } = require("node:fs");
21
+ const { join, resolve } = require("node:path");
22
+
23
+ const root = resolve(process.argv[2] ?? join(__dirname, ".."));
24
+
25
+ const REFERENCE = "ctpsdk/linux/thosttraderapi_se.so";
26
+ const FRAMEWORKS = [
27
+ "ctpsdk/macos/thostmduserapi_se.framework/Versions/A/thostmduserapi_se",
28
+ "ctpsdk/macos/thosttraderapi_se.framework/Versions/A/thosttraderapi_se",
29
+ ];
30
+
31
+ // The vendor libraries embed a build stamp such as
32
+ // "v6.7.13_20260225 14:16:30.12079" or "v6.7.7_MacOS_20240716 15:00:00".
33
+ const STAMP = /v(\d+\.\d+\.\d+)_(?:MacOS_)?\d{8} \d{2}:\d{2}:\d{2}/g;
34
+
35
+ function readStamp(rel) {
36
+ let bytes;
37
+ try {
38
+ bytes = readFileSync(join(root, rel));
39
+ } catch (err) {
40
+ return { rel, error: `cannot read (${err.code ?? err.message})` };
41
+ }
42
+ const stamps = new Set();
43
+ const versions = new Set();
44
+ for (const m of bytes.toString("latin1").matchAll(STAMP)) {
45
+ stamps.add(m[0]);
46
+ versions.add(m[1]);
47
+ }
48
+ if (versions.size !== 1) {
49
+ return { rel, error: versions.size ? `ambiguous CTP version (${[...stamps].join(", ")})` : "no CTP version stamp found" };
50
+ }
51
+ return { rel, version: [...versions][0], stamp: [...stamps][0] };
52
+ }
53
+
54
+ const ref = readStamp(REFERENCE);
55
+ const frameworks = FRAMEWORKS.map(readStamp);
56
+ const ok = !ref.error && frameworks.every((f) => !f.error && f.version === ref.version);
57
+
58
+ if (!ok) {
59
+ const line = (f) => ` ${f.rel}: ${f.error ?? `v${f.version} (${f.stamp})`}`;
60
+ process.stderr.write(
61
+ [
62
+ "",
63
+ "ctp-node: refusing to build on macOS - CTP SDK version mismatch.",
64
+ " The addon is compiled against the CTP headers in ctpsdk/*.h, which match:",
65
+ line(ref),
66
+ " but the bundled macOS frameworks are:",
67
+ ...frameworks.map(line),
68
+ " An addon built from these links (node-gyp uses -undefined dynamic_lookup) but",
69
+ " crashes at runtime, because the factory functions and the API/SPI vtables differ",
70
+ " between CTP versions. macOS is not supported by this release; use Windows or",
71
+ " Linux x64 (prebuilt). See docs/troubleshooting.md, \"Build & install\".",
72
+ " Maintainers: replace ctpsdk/macos/*.framework with the SFIT MacOS build of the",
73
+ " same CTP version as ctpsdk/linux, then rebuild.",
74
+ "ctp-node:macOS 框架的 CTP 版本与头文件(及 Windows/Linux 库)不一致,这样编出的插件",
75
+ "运行时会崩溃,构建已中止。当前版本不支持 macOS,请使用 Windows 或 Linux x64。",
76
+ "",
77
+ ].join("\n"),
78
+ );
79
+ process.exit(1);
80
+ }