@hitrading/ctp-node 2.0.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.
- package/CHANGELOG.md +67 -0
- package/README.md +47 -32
- package/README.zh-CN.md +37 -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 +1875 -415
- 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 +111 -71
- package/dist/trader.d.ts.map +1 -1
- package/dist/trader.js +774 -180
- 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 +1437 -0
- package/docs/API.zh-CN.md +1278 -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 +8 -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 +75 -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 +753 -124
- package/src/native-binding.ts +4 -0
- package/src/trader.ts +971 -204
- package/src/validation.ts +96 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/** Runtime request/config objects must have predictable own-property semantics.
|
|
2
|
+
* Accept ordinary object literals and null-prototype dictionaries; reject class
|
|
3
|
+
* instances and inherited fields so a value cannot reach the CTP wire without
|
|
4
|
+
* appearing in the caller's explicit request shape. */
|
|
5
|
+
export function assertPlainRecord(
|
|
6
|
+
value: unknown,
|
|
7
|
+
label: string
|
|
8
|
+
): asserts value is Record<string, unknown> {
|
|
9
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
10
|
+
throw new TypeError(`${label} must be a plain object`);
|
|
11
|
+
const prototype = Object.getPrototypeOf(value);
|
|
12
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
13
|
+
throw new TypeError(`${label} must be a plain object`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Return every own key, including non-enumerable keys. Symbols cannot name a
|
|
17
|
+
* CTP field and are rejected rather than silently ignored. */
|
|
18
|
+
export function ownStringKeys(value: unknown, label: string): string[] {
|
|
19
|
+
assertPlainRecord(value, label);
|
|
20
|
+
const keys = Reflect.ownKeys(value);
|
|
21
|
+
if (keys.some((key) => typeof key !== "string"))
|
|
22
|
+
throw new TypeError(`${label} contains an unsupported symbol field`);
|
|
23
|
+
return keys as string[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Snapshot only explicit values into a null-prototype object before handing a
|
|
27
|
+
* request to N-API. This prevents Object.prototype pollution from being seen by
|
|
28
|
+
* native Has()/Get() and treats an explicit `undefined` like an omitted optional
|
|
29
|
+
* field, matching the binary codec. */
|
|
30
|
+
export function copyOwnRecord<T extends object>(value: T, label: string): T {
|
|
31
|
+
const source = value as Record<string, unknown>;
|
|
32
|
+
const copy = Object.create(null) as Record<string, unknown>;
|
|
33
|
+
for (const key of ownStringKeys(value, label)) {
|
|
34
|
+
const field = source[key];
|
|
35
|
+
if (field !== undefined) copy[key] = field;
|
|
36
|
+
}
|
|
37
|
+
return copy as T;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Validate and snapshot a dense instrument-id list in one pass. Array iteration
|
|
41
|
+
* helpers such as some() skip holes; treating a hole as an omitted CTP
|
|
42
|
+
* InstrumentID can accidentally turn a scoped metadata request into a query-all
|
|
43
|
+
* request, so holes and inherited indices are rejected (the same explicit-own-
|
|
44
|
+
* value rule as request objects). Callers that cross an async boundary must use
|
|
45
|
+
* this copy: otherwise an accessor or ordinary mutation after validation can
|
|
46
|
+
* change a scoped request into another query. */
|
|
47
|
+
export function copyDenseStringArray(
|
|
48
|
+
value: unknown,
|
|
49
|
+
label: string,
|
|
50
|
+
allowEmpty = true
|
|
51
|
+
): string[] {
|
|
52
|
+
if (!Array.isArray(value))
|
|
53
|
+
throw new TypeError(`${label} must be ${allowEmpty ? "an" : "a non-empty"} instrument-id array`);
|
|
54
|
+
const length = value.length;
|
|
55
|
+
if (!allowEmpty && length === 0)
|
|
56
|
+
throw new TypeError(`${label} must be a non-empty instrument-id array`);
|
|
57
|
+
const copy = new Array<string>(length);
|
|
58
|
+
for (let i = 0; i < length; i++) {
|
|
59
|
+
if (!Object.prototype.hasOwnProperty.call(value, i)) {
|
|
60
|
+
throw new TypeError(`${label} must contain dense, non-empty strings without NUL`);
|
|
61
|
+
}
|
|
62
|
+
const item: unknown = value[i]; // read an accessor exactly once
|
|
63
|
+
if (typeof item !== "string" || item.length === 0 || item.includes("\0"))
|
|
64
|
+
throw new TypeError(`${label} must contain dense, non-empty strings without NUL`);
|
|
65
|
+
copy[i] = item;
|
|
66
|
+
}
|
|
67
|
+
return copy;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Copy a constructor front list without allowing Array.prototype values to
|
|
71
|
+
* become connection addresses. Empty entries are preserved for the native
|
|
72
|
+
* normalization that skips them; at least one non-empty front is still
|
|
73
|
+
* enforced natively. */
|
|
74
|
+
export function copyOwnFronts(
|
|
75
|
+
value: string | string[],
|
|
76
|
+
label: string
|
|
77
|
+
): string | string[] {
|
|
78
|
+
if (typeof value === "string") {
|
|
79
|
+
if (value.includes("\0")) throw new TypeError(`${label} must not contain NUL`);
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
if (!Array.isArray(value))
|
|
83
|
+
throw new TypeError(`${label} must be a string or string array`);
|
|
84
|
+
const length = value.length;
|
|
85
|
+
const copy: string[] = new Array(length);
|
|
86
|
+
for (let i = 0; i < length; i++) {
|
|
87
|
+
if (!Object.prototype.hasOwnProperty.call(value, i)) {
|
|
88
|
+
throw new TypeError(`${label} must contain only explicit strings without NUL`);
|
|
89
|
+
}
|
|
90
|
+
const item: unknown = value[i]; // snapshot an accessor exactly once
|
|
91
|
+
if (typeof item !== "string" || item.includes("\0"))
|
|
92
|
+
throw new TypeError(`${label} must contain only explicit strings without NUL`);
|
|
93
|
+
copy[i] = item;
|
|
94
|
+
}
|
|
95
|
+
return copy;
|
|
96
|
+
}
|