@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.
- package/CHANGELOG.md +67 -0
- package/README.md +52 -31
- package/README.zh-CN.md +42 -26
- package/RELEASING.md +78 -0
- package/binding.gyp +13 -13
- package/dist/client.d.ts +40 -15
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +241 -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 +1896 -420
- 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 +48 -21
- package/dist/market-data.d.ts.map +1 -1
- package/dist/market-data.js +165 -26
- package/dist/market-data.js.map +1 -1
- package/dist/native-binding.d.ts.map +1 -1
- package/dist/native-binding.js +5 -1
- package/dist/native-binding.js.map +1 -1
- package/dist/trader.d.ts +127 -79
- package/dist/trader.d.ts.map +1 -1
- package/dist/trader.js +788 -200
- 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 +14 -6
- 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 +263 -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 +130 -10
- package/src/generated/traderspi.gen.h +4 -2
- package/src/index.ts +8 -1
- package/src/market-data.ts +219 -43
- 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 +621 -61
- package/src/native/mdspi.cc +221 -14
- package/src/native/mdspi.h +62 -9
- package/src/native/order_capability.h +75 -0
- package/src/native/risk.cc +2051 -205
- package/src/native/risk.h +450 -57
- package/src/native/shared_handle.h +37 -0
- package/src/native/snapshot.h +120 -0
- package/src/native/traderapi.cc +749 -170
- package/src/native-binding.ts +5 -1
- package/src/trader.ts +993 -229
- package/src/validation.ts +96 -0
- /package/{tradeapi → ctpsdk}/ThostFtdcMdApi.h +0 -0
- /package/{tradeapi → ctpsdk}/ThostFtdcTraderApi.h +0 -0
- /package/{tradeapi → ctpsdk}/ThostFtdcUserApiDataType.h +0 -0
- /package/{tradeapi → ctpsdk}/ThostFtdcUserApiStruct.h +0 -0
- /package/{tradeapi → ctpsdk}/error.dtd +0 -0
- /package/{tradeapi → ctpsdk}/error.xml +0 -0
- /package/{tradeapi → ctpsdk}/linux/thostmduserapi_se.so +0 -0
- /package/{tradeapi → ctpsdk}/linux/thosttraderapi_se.so +0 -0
- /package/{tradeapi → ctpsdk}/macos/thostmduserapi_se.framework/Versions/A/Headers/ThostFtdcMdApi.h +0 -0
- /package/{tradeapi → ctpsdk}/macos/thostmduserapi_se.framework/Versions/A/Headers/ThostFtdcUserApiDataType.h +0 -0
- /package/{tradeapi → ctpsdk}/macos/thostmduserapi_se.framework/Versions/A/Headers/ThostFtdcUserApiStruct.h +0 -0
- /package/{tradeapi → ctpsdk}/macos/thostmduserapi_se.framework/Versions/A/Resources/Info.plist +0 -0
- /package/{tradeapi → ctpsdk}/macos/thostmduserapi_se.framework/Versions/A/_CodeSignature/CodeResources +0 -0
- /package/{tradeapi → ctpsdk}/macos/thostmduserapi_se.framework/Versions/A/thostmduserapi_se +0 -0
- /package/{tradeapi → ctpsdk}/macos/thosttraderapi_se.framework/Versions/A/Headers/ThostFtdcTraderApi.h +0 -0
- /package/{tradeapi → ctpsdk}/macos/thosttraderapi_se.framework/Versions/A/Headers/ThostFtdcUserApiDataType.h +0 -0
- /package/{tradeapi → ctpsdk}/macos/thosttraderapi_se.framework/Versions/A/Headers/ThostFtdcUserApiStruct.h +0 -0
- /package/{tradeapi → ctpsdk}/macos/thosttraderapi_se.framework/Versions/A/Resources/Info.plist +0 -0
- /package/{tradeapi → ctpsdk}/macos/thosttraderapi_se.framework/Versions/A/_CodeSignature/CodeResources +0 -0
- /package/{tradeapi → ctpsdk}/macos/thosttraderapi_se.framework/Versions/A/thosttraderapi_se +0 -0
- /package/{tradeapi → ctpsdk}/windows/thostmduserapi_se.dll +0 -0
- /package/{tradeapi → ctpsdk}/windows/thostmduserapi_se.lib +0 -0
- /package/{tradeapi → ctpsdk}/windows/thosttraderapi_se.dll +0 -0
- /package/{tradeapi → ctpsdk}/windows/thosttraderapi_se.lib +0 -0
package/dist/trader.d.ts
CHANGED
|
@@ -3,34 +3,61 @@ import type { CallbackOptions } from "./client.js";
|
|
|
3
3
|
import type { Order, Trade, InputOrder, RspUserLogin } from "./generated/structs.gen.js";
|
|
4
4
|
import type { MarketData } from "./market-data.js";
|
|
5
5
|
/** Pre-trade risk limits, enforced in C++ before each order is sent. */
|
|
6
|
-
export interface
|
|
6
|
+
export interface RiskLimits {
|
|
7
7
|
/** Max volume per single order. Omit/0 = disabled. */
|
|
8
8
|
maxOrderVolume?: number;
|
|
9
9
|
/** Reject if order price deviates from the reference by > this ratio (e.g.
|
|
10
|
-
* 0.02 = 2%). Feed the reference via trackMarketData()
|
|
11
|
-
*
|
|
10
|
+
* 0.02 = 2%). Feed the reference via trackMarketData(md) (the MD snapshot is
|
|
11
|
+
* read in C++); missing or stale data rejects opening orders. */
|
|
12
12
|
maxPriceDeviation?: number;
|
|
13
|
-
/** Max notional (price × volume) per order.
|
|
13
|
+
/** Max futures notional (price × volume × multiplier) per opening order.
|
|
14
|
+
* Unknown/unsupported product metadata fails closed. Omit/0 = disabled. */
|
|
14
15
|
maxNotional?: number;
|
|
15
|
-
/** Max order sends per second (token bucket). Omit/0 = disabled. */
|
|
16
|
+
/** Max opening-order sends per second (token bucket). Omit/0 = disabled. */
|
|
16
17
|
maxOrdersPerSec?: number;
|
|
17
18
|
/** Token-bucket burst; defaults to maxOrdersPerSec. */
|
|
18
19
|
orderBurst?: number;
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
/** Independent rate for risk-reducing close inserts. Disabled by default so
|
|
21
|
+
* emergency exits are not throttled by the opening-order bucket. */
|
|
22
|
+
maxCloseOrdersPerSec?: number;
|
|
23
|
+
/** Close-order token-bucket burst; defaults to maxCloseOrdersPerSec. */
|
|
24
|
+
closeOrderBurst?: number;
|
|
25
|
+
/** Maximum age of the market-data reference used by the deviation guard.
|
|
26
|
+
* Default 3000 ms. Missing or older data fails closed when the guard is on. */
|
|
27
|
+
maxReferenceAgeMs?: number;
|
|
28
|
+
/** Cap on total open-position MARGIN (Σ open price × volume × multiplier ×
|
|
29
|
+
* absolute by-money/by-volume margin schedule) — a zero-lag hard cap enforced in
|
|
30
|
+
* C++ on every opening order (regular AND armed). 0/undefined = disabled.
|
|
31
|
+
* Margin rates are fed automatically from CTP's OnRspQryInstrumentMarginRate
|
|
32
|
+
* inside C++ (populate them by calling reqQryInstrumentMarginRate); until a
|
|
33
|
+
* multiplier or usable absolute schedule is missing, opening orders fail
|
|
34
|
+
* closed. Both by-money and per-lot components are included; relative
|
|
35
|
+
* investor schedules are combined with their exchange base schedule.
|
|
36
|
+
* Multipliers / existing positions are picked up via syncMultipliers() /
|
|
37
|
+
* syncPositions(). */
|
|
38
|
+
maxAccountMargin?: number;
|
|
23
39
|
}
|
|
24
40
|
/** A per-instrument lot cap: a single number caps both sides at that value;
|
|
25
41
|
* `{ long, short }` caps each side separately (omit a side to leave it open). */
|
|
26
|
-
export type
|
|
42
|
+
export type InstrumentPositionLimit = number | {
|
|
27
43
|
long?: number;
|
|
28
44
|
short?: number;
|
|
29
45
|
};
|
|
46
|
+
/** One bucket in a complete manually reconciled held-position snapshot. */
|
|
47
|
+
export interface PositionSeed {
|
|
48
|
+
instrumentId: string;
|
|
49
|
+
side: "long" | "short";
|
|
50
|
+
hedgeFlag: "1" | "2" | "3" | "5" | "6" | "7";
|
|
51
|
+
volume: number;
|
|
52
|
+
margin: number;
|
|
53
|
+
}
|
|
30
54
|
/** Options for the one-call post-connect handshake, {@link Trader.session}. */
|
|
31
55
|
export interface SessionOptions {
|
|
32
56
|
brokerId: string;
|
|
33
57
|
userId: string;
|
|
58
|
+
/** Trading account. Defaults to userId for ordinary retail accounts; set it
|
|
59
|
+
* explicitly when the login operator UserID differs from InvestorID. */
|
|
60
|
+
investorId?: string;
|
|
34
61
|
password: string;
|
|
35
62
|
/** Terminal authentication (real accounts require it; SimNow uses
|
|
36
63
|
* appId "simnow_client_test" / authCode of 16 zeros). Omit both to skip. */
|
|
@@ -40,10 +67,14 @@ export interface SessionOptions {
|
|
|
40
67
|
* before trading (brokers reject orders otherwise). Default true; set false
|
|
41
68
|
* for environments that don't need it. */
|
|
42
69
|
confirmSettlement?: boolean;
|
|
43
|
-
/** Which risk inputs to fetch after login
|
|
70
|
+
/** Which risk inputs to fetch after login. Multipliers/positions/orders default
|
|
71
|
+
* on; margin rates require an explicit contract list. `multipliers` may
|
|
44
72
|
* be `true` (all instruments) or a list of symbols. */
|
|
45
73
|
sync?: {
|
|
46
74
|
multipliers?: boolean | string[];
|
|
75
|
+
/** Contracts whose speculation margin schedules should be queried. Omitted
|
|
76
|
+
* by default because CTP requires one rate query per contract. */
|
|
77
|
+
marginRates?: string[];
|
|
47
78
|
positions?: boolean;
|
|
48
79
|
orders?: boolean;
|
|
49
80
|
};
|
|
@@ -69,18 +100,31 @@ export declare class Trader extends TraderBase {
|
|
|
69
100
|
private investor?;
|
|
70
101
|
private orderRefSeq;
|
|
71
102
|
constructor(flowPath: string, fronts: string | string[]);
|
|
72
|
-
|
|
73
|
-
|
|
103
|
+
/** A raw login Promise may resolve only with a structurally usable session.
|
|
104
|
+
* Account confirmation itself happens in session(), after request-vs-response
|
|
105
|
+
* identity validation; merely observing a protocol event never grants order
|
|
106
|
+
* authority. */
|
|
107
|
+
protected onRequestResolved(eventName: string | undefined, value: unknown, _options: CallbackOptions): void;
|
|
108
|
+
/** Generated login/logout methods call this only after their request has
|
|
109
|
+
* encoded successfully. Revoke the confirmed JS account at that same atomic
|
|
110
|
+
* transition boundary, so a concurrent sync helper cannot start with the old
|
|
111
|
+
* identity while native risk state is already fail-closed for the new session. */
|
|
112
|
+
protected beginRequestContextTransition(reason: string): void;
|
|
113
|
+
protected shouldTimeoutRequest(requestId: number, sessionTransition: boolean): boolean;
|
|
114
|
+
get apiVersion(): string;
|
|
115
|
+
get tradingDay(): string;
|
|
74
116
|
/**
|
|
75
117
|
* One-call post-connect handshake. Call it from the `front-connected` handler
|
|
76
118
|
* (and again after a reconnect): authenticate (if appId/authCode given) →
|
|
77
|
-
* login → confirm settlement → sync multipliers /
|
|
119
|
+
* login → confirm settlement → sync multipliers / margin rates / orders /
|
|
120
|
+
* positions. Each
|
|
78
121
|
* step just wraps the matching req / sync method, so you can hand-roll your
|
|
79
122
|
* own flow instead when you need finer control. Returns the row counts from
|
|
80
123
|
* the sync steps. Must run on a connected front (queries need the session up).
|
|
81
124
|
*/
|
|
82
125
|
session(opts: SessionOptions): Promise<{
|
|
83
126
|
multipliers: number;
|
|
127
|
+
marginRates: number;
|
|
84
128
|
positions: number;
|
|
85
129
|
orders: number;
|
|
86
130
|
}>;
|
|
@@ -88,6 +132,8 @@ export declare class Trader extends TraderBase {
|
|
|
88
132
|
* OrderRef as a per-session sequence and rejects a duplicate or non-numeric
|
|
89
133
|
* ref with "不允许重复报单", so an unset ref would otherwise collide. */
|
|
90
134
|
private withAutoOrderRef;
|
|
135
|
+
private commitOrderRef;
|
|
136
|
+
private validateOrder;
|
|
91
137
|
/**
|
|
92
138
|
* Insert an order through the C++ pre-trade risk gate. Resolves on submission:
|
|
93
139
|
* CTP sends no success acknowledgement for an accepted order - only
|
|
@@ -98,70 +144,74 @@ export declare class Trader extends TraderBase {
|
|
|
98
144
|
*/
|
|
99
145
|
reqOrderInsert(req?: Partial<InputOrder>): Promise<void>;
|
|
100
146
|
/** Publish pre-trade risk limits to the C++ enforcer (takes effect at once). */
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
*
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
|
|
109
|
-
|
|
147
|
+
setRiskLimits(config: RiskLimits): this;
|
|
148
|
+
/** Enter REDUCE_ONLY atomically at the final vendor-API send barrier. Armed
|
|
149
|
+
* opens remain registered but cannot send until resume(). */
|
|
150
|
+
reduceOnly(): this;
|
|
151
|
+
/** Enter HALT_ALL atomically: both opening and closing order inserts, advanced
|
|
152
|
+
* mutations and bank/futures transfers are refused, and all existing armed
|
|
153
|
+
* triggers are cleared. New arm() calls are rejected until resume().
|
|
154
|
+
* Cancellation actions remain available so working
|
|
155
|
+
* exchange orders can still be withdrawn. */
|
|
156
|
+
haltAll(): this;
|
|
157
|
+
/** Return to NORMAL mode after reduceOnly() or haltAll(). */
|
|
110
158
|
resume(): this;
|
|
111
|
-
/**
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
*
|
|
159
|
+
/** Use a MarketData feed as the live reference for the maxPriceDeviation check.
|
|
160
|
+
* Wires the feed's C++ snapshot cache straight into this Trader's risk engine,
|
|
161
|
+
* so the deviation check reads current prices in C++ on the order path (no JS
|
|
162
|
+
* round-trip, and it also covers armed orders that fire with no JS in the loop).
|
|
163
|
+
* Without a fresh reference, an enabled deviation check fails closed. */
|
|
115
164
|
trackMarketData(md: MarketData): this;
|
|
116
|
-
/** Set a contract's multiplier (合约乘数) for position-cost accounting. */
|
|
117
|
-
setMultiplier(instrumentId: string, multiplier: number): this;
|
|
118
165
|
/**
|
|
119
166
|
* Cap the open position (in lots) for one instrument, enforced in C++ on
|
|
120
167
|
* every opening order. Pass a number to cap both sides at once, or
|
|
121
168
|
* `{ long, short }` to cap each side separately. Within `{ long, short }`,
|
|
122
169
|
* **omitting a side leaves that side's current cap unchanged** (on a re-call it
|
|
123
|
-
* is NOT reset to uncapped), and passing
|
|
170
|
+
* is NOT reset to uncapped), and passing `0` for a side removes its cap.
|
|
124
171
|
* Long and short are always tracked independently.
|
|
125
172
|
*
|
|
126
|
-
*
|
|
127
|
-
* so rapid bursts of opens can momentarily overshoot before the fills land —
|
|
128
|
-
* size the cap with that in mind.
|
|
173
|
+
* Held positions and in-flight working opens are counted atomically.
|
|
129
174
|
*
|
|
130
|
-
* td.
|
|
131
|
-
* td.
|
|
175
|
+
* td.setInstrumentPositionLimit("rb2610", 100);
|
|
176
|
+
* td.setInstrumentPositionLimit("ru2610", { long: 100, short: 20 });
|
|
132
177
|
*/
|
|
133
|
-
|
|
178
|
+
setInstrumentPositionLimit(instrumentId: string, limit: InstrumentPositionLimit): this;
|
|
134
179
|
/** Cap several instruments at once, e.g.
|
|
135
180
|
* `{ rb2610: 100, ru2610: { long: 100, short: 20 } }`. */
|
|
136
|
-
|
|
181
|
+
setInstrumentPositionLimits(limits: Record<string, InstrumentPositionLimit>): this;
|
|
182
|
+
private normalizePositionLimit;
|
|
137
183
|
/**
|
|
138
|
-
* Cap one instrument's open
|
|
139
|
-
* long and short summed
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* `maxCost <= 0` to remove it. Fill-based, same caveat as maxPositionCost.
|
|
184
|
+
* Cap one instrument's scheduled open margin (CTP by-money + by-volume,
|
|
185
|
+
* long and short summed), enforced in C++ on every opening order. This is
|
|
186
|
+
* independent of the account-wide maxAccountMargin cap; both apply. Pass
|
|
187
|
+
* `limit = 0` to remove it. Held and in-flight exposure both count.
|
|
143
188
|
*/
|
|
144
|
-
|
|
145
|
-
/** Cap several instruments' open
|
|
189
|
+
setInstrumentMarginLimit(instrumentId: string, limit: number): this;
|
|
190
|
+
/** Cap several instruments' scheduled open margin at once, e.g.
|
|
146
191
|
* `{ ag2608: 2_000_000, au2608: 5_000_000 }`. */
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
*
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
*
|
|
192
|
+
setInstrumentMarginLimits(limits: Record<string, number>): this;
|
|
193
|
+
/** Atomically replace held positions from a complete manually reconciled
|
|
194
|
+
* snapshot. `margin` is CTP InvestorPosition.UseMargin. An empty array is an
|
|
195
|
+
* authoritative flat book. Partial/incremental seeding is intentionally not
|
|
196
|
+
* exposed because armed orders can run between JS calls. */
|
|
197
|
+
seedPositions(positions: ReadonlyArray<PositionSeed>): this;
|
|
198
|
+
private replacePositionSeeds;
|
|
199
|
+
/** Atomically replace held position margin from complete gross-mode query rows
|
|
200
|
+
* (`posiDirection` '2' long, '3' short). Net/unknown direction is rejected
|
|
201
|
+
* because guessing a side corrupts per-side volume caps. */
|
|
156
202
|
seedFromPositions(positions: ReadonlyArray<{
|
|
157
203
|
instrumentId: string;
|
|
158
204
|
posiDirection: string;
|
|
205
|
+
hedgeFlag: string;
|
|
159
206
|
position: number;
|
|
160
|
-
|
|
207
|
+
useMargin: number;
|
|
161
208
|
}>): this;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
209
|
+
private aggregatePositions;
|
|
210
|
+
/** Current total open-position margin tracked by the C++ risk engine. */
|
|
211
|
+
get accountMargin(): number;
|
|
212
|
+
/** Clear held position state only and mark it uncertain. Working-order
|
|
213
|
+
* reservations are preserved; openings remain blocked until a complete
|
|
214
|
+
* seedFromPositions() or syncPositions() succeeds. */
|
|
165
215
|
resetPositions(): this;
|
|
166
216
|
/**
|
|
167
217
|
* Run a CTP query with flow-control retries. CTP rate-limits queries (~1/sec)
|
|
@@ -172,16 +222,23 @@ export declare class Trader extends TraderBase {
|
|
|
172
222
|
* position book, so a flat account doesn't waste the full retry budget).
|
|
173
223
|
*/
|
|
174
224
|
private queryWithRetry;
|
|
175
|
-
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
225
|
+
/** Empty position/order snapshots are ambiguous immediately after login. Require
|
|
226
|
+
* the same empty result twice, one query interval apart, before treating it as
|
|
227
|
+
* authoritative. */
|
|
228
|
+
private authoritativeQuery;
|
|
229
|
+
/** Query instruments so the C++ risk engine picks up their multipliers (it
|
|
230
|
+
* sources them directly from OnRspQryInstrument — no JS feed). No args queries
|
|
231
|
+
* all instruments (one request); otherwise the given symbols. Retries through
|
|
232
|
+
* cold-start flow control. Returns the count of contracts with a multiplier. */
|
|
178
233
|
syncMultipliers(instrumentIds?: string[]): Promise<number>;
|
|
179
|
-
/**
|
|
180
|
-
*
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
234
|
+
/** Query investor margin schedules for a bounded universe. The exchange-base
|
|
235
|
+
* query is issued only when the investor row is relative; the shared query
|
|
236
|
+
* scheduler enforces spacing. Returns the number of usable schedules. */
|
|
237
|
+
syncMarginRates(instrumentIds: string[], hedgeFlag?: "1" | "2" | "3" | "5" | "6" | "7"): Promise<number>;
|
|
238
|
+
/** Replace held position margin from CTP (`reqQryInvestorPosition`). The
|
|
239
|
+
* replacement is revision-checked: if an order/trade callback races the
|
|
240
|
+
* snapshot it retries without clearing live state or reservations. */
|
|
241
|
+
syncPositions(): Promise<number>;
|
|
185
242
|
/**
|
|
186
243
|
* Rebuild the in-flight reservation from CTP's currently-working orders
|
|
187
244
|
* (reqQryOrder) - an authoritative resync. Call it after login and after any
|
|
@@ -191,16 +248,7 @@ export declare class Trader extends TraderBase {
|
|
|
191
248
|
* of working open orders re-reserved. Run syncMultipliers() first so the
|
|
192
249
|
* reserved cost uses the right contract multiplier.
|
|
193
250
|
*/
|
|
194
|
-
syncOrders(
|
|
195
|
-
brokerId?: string;
|
|
196
|
-
investorId?: string;
|
|
197
|
-
}): Promise<number>;
|
|
198
|
-
/** @internal test-only: feed a synthetic fill into the position-cost tracker. */
|
|
199
|
-
_applyTestTrade(instrumentId: string, isBuy: boolean, isOpen: boolean, price: number, volume: number): void;
|
|
200
|
-
/** @internal test-only: drive the in-flight reservation tracker (OnRtnOrder).
|
|
201
|
-
* status: '1'/'3' = working (queueing), others (e.g. '0' filled, '5'
|
|
202
|
-
* cancelled) = terminal. */
|
|
203
|
-
_applyTestOrder(frontId: number, sessionId: number, orderRef: string, instrumentId: string, isOpen: boolean, isLong: boolean, status: string, limitPrice: number, volTotal: number, volTraded: number): void;
|
|
251
|
+
syncOrders(): Promise<number>;
|
|
204
252
|
/**
|
|
205
253
|
* Arm a latency-critical trigger: when `md` sees the condition, the order is
|
|
206
254
|
* sent from C++ on the callback thread (through this Trader's risk gate),
|
|
@@ -212,7 +260,7 @@ export declare class Trader extends TraderBase {
|
|
|
212
260
|
* how many fired and were sent vs were refused by the risk gate / send.
|
|
213
261
|
* A blocked armed order is otherwise invisible, so poll this after a trigger
|
|
214
262
|
* you expected to fire. */
|
|
215
|
-
armStats(): {
|
|
263
|
+
get armStats(): {
|
|
216
264
|
fired: number;
|
|
217
265
|
blocked: number;
|
|
218
266
|
};
|
|
@@ -226,8 +274,8 @@ export declare class Trader extends TraderBase {
|
|
|
226
274
|
on(event: "rtn-trade", cb: (data: Trade, opts: CallbackOptions) => void): this;
|
|
227
275
|
on(event: "front-connected", cb: (data: undefined, opts: CallbackOptions) => void): this;
|
|
228
276
|
on(event: "front-disconnected", cb: (reason: number, opts: CallbackOptions) => void): this;
|
|
229
|
-
on(event: "rsp-user-login", cb: (data: RspUserLogin, opts: CallbackOptions) => void): this;
|
|
230
|
-
on(event: "err-rtn-order-insert", cb: (data: InputOrder, opts: CallbackOptions) => void): this;
|
|
277
|
+
on(event: "rsp-user-login", cb: (data: RspUserLogin | undefined, opts: CallbackOptions) => void): this;
|
|
278
|
+
on(event: "err-rtn-order-insert", cb: (data: InputOrder | undefined, opts: CallbackOptions) => void): this;
|
|
231
279
|
on(event: string, cb: (...args: never[]) => void): this;
|
|
232
280
|
}
|
|
233
281
|
export { TraderEvent };
|
package/dist/trader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trader.d.ts","sourceRoot":"","sources":["../src/trader.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,UAAU,EAAiB,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAEnF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACzF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"trader.d.ts","sourceRoot":"","sources":["../src/trader.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,UAAU,EAAiB,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAEnF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACzF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAWnD,wEAAwE;AACxE,MAAM,WAAW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