tigeropen 0.4.0 → 0.5.5
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/README.md +55 -2
- package/dist/cjs/client/api-response.js +28 -7
- package/dist/cjs/client/case-convert.js +4 -3
- package/dist/cjs/client/http-client.js +124 -8
- package/dist/cjs/client/token-methods.js +42 -0
- package/dist/cjs/config/client-config.js +115 -16
- package/dist/cjs/config/config-parser.js +19 -9
- package/dist/cjs/config/index.js +4 -1
- package/dist/cjs/config/token-manager.js +54 -4
- package/dist/cjs/index.js +53 -2
- package/dist/cjs/model/enums.js +18 -1
- package/dist/cjs/model/order-helpers.js +149 -0
- package/dist/cjs/push/index.js +1 -0
- package/dist/cjs/push/push-client.js +47 -19
- package/dist/cjs/push/tick-util.js +172 -0
- package/dist/cjs/quote/quote-client.js +300 -70
- package/dist/cjs/trade/trade-client.js +174 -13
- package/dist/cjs/version.js +4 -0
- package/dist/esm/client/api-request.js +1 -1
- package/dist/esm/client/api-response.js +29 -8
- package/dist/esm/client/case-convert.js +4 -3
- package/dist/esm/client/http-client.js +128 -12
- package/dist/esm/client/index.js +6 -6
- package/dist/esm/client/token-methods.js +37 -0
- package/dist/esm/config/client-config.js +118 -20
- package/dist/esm/config/config-parser.js +19 -9
- package/dist/esm/config/index.js +4 -3
- package/dist/esm/config/token-manager.js +55 -5
- package/dist/esm/index.js +15 -1
- package/dist/esm/logger/index.js +1 -1
- package/dist/esm/model/contract-helpers.js +1 -1
- package/dist/esm/model/enums.js +17 -0
- package/dist/esm/model/order-helpers.js +142 -1
- package/dist/esm/model/order-status.js +1 -1
- package/dist/esm/push/index.js +6 -5
- package/dist/esm/push/pb/PushData.js +11 -11
- package/dist/esm/push/pb/QuoteBasicData.js +1 -1
- package/dist/esm/push/pb/Response.js +1 -1
- package/dist/esm/push/pb/index.js +17 -17
- package/dist/esm/push/proto-message.js +3 -3
- package/dist/esm/push/push-client.js +54 -26
- package/dist/esm/push/tick-util.js +165 -0
- package/dist/esm/quote/index.js +1 -1
- package/dist/esm/quote/quote-client.js +269 -72
- package/dist/esm/signer/index.js +2 -2
- package/dist/esm/trade/index.js +1 -1
- package/dist/esm/trade/trade-client.js +144 -16
- package/dist/esm/version.js +1 -0
- package/dist/types/client/api-response.d.ts +6 -4
- package/dist/types/client/case-convert.d.ts +3 -1
- package/dist/types/client/http-client.d.ts +32 -1
- package/dist/types/client/token-methods.d.ts +34 -0
- package/dist/types/config/client-config.d.ts +22 -1
- package/dist/types/config/index.d.ts +3 -1
- package/dist/types/config/token-manager.d.ts +27 -3
- package/dist/types/index.d.ts +22 -1
- package/dist/types/model/enums.d.ts +18 -2
- package/dist/types/model/order-helpers.d.ts +52 -1
- package/dist/types/model/order.d.ts +127 -10
- package/dist/types/model/quote-requests.d.ts +27 -15
- package/dist/types/model/quote.d.ts +150 -24
- package/dist/types/model/trade-requests.d.ts +118 -4
- package/dist/types/model/trade.d.ts +121 -17
- package/dist/types/push/callbacks.d.ts +3 -7
- package/dist/types/push/index.d.ts +1 -0
- package/dist/types/push/push-client.d.ts +5 -3
- package/dist/types/push/tick-util.d.ts +30 -0
- package/dist/types/quote/quote-client.d.ts +101 -36
- package/dist/types/trade/trade-client.d.ts +57 -11
- package/dist/types/version.d.ts +1 -0
- package/package.json +5 -2
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* TradeClient — trading client.
|
|
3
|
+
*
|
|
4
|
+
* All methods return strongly-typed responses; request parameters are
|
|
5
|
+
* written in camelCase in TypeScript and converted to snake_case on the wire.
|
|
6
|
+
*
|
|
7
|
+
* v0.4.0: 所有查询类方法改为 Request 对象签名(OrdersRequest 等),补齐 17
|
|
8
|
+
* 个新方法(账户管理 / 资产分析 / 资金调拨 / 持仓划转等)。
|
|
9
|
+
*/
|
|
10
|
+
import { HttpClient } from '../client/http-client.js';
|
|
11
|
+
import { createApiRequest } from '../client/api-request.js';
|
|
12
|
+
import { unmarshalData } from '../client/api-response.js';
|
|
13
|
+
import * as tokenMethods from '../client/token-methods.js';
|
|
14
|
+
import { normalizeOrderStatus } from '../model/order-status.js';
|
|
4
15
|
/** Normalize `Order.status` field in-place (handles int → string). */
|
|
5
16
|
function normalizeOrderInPlace(o) {
|
|
6
17
|
if (o && o.status !== undefined && o.status !== null) {
|
|
@@ -22,12 +33,51 @@ function withAccount(req, account) {
|
|
|
22
33
|
}
|
|
23
34
|
/** Trading client wrapping all trade-related APIs. */
|
|
24
35
|
export class TradeClient {
|
|
25
|
-
constructor(httpClient, account) {
|
|
36
|
+
constructor(httpClient, account, secretKey) {
|
|
26
37
|
this.httpClient = httpClient;
|
|
27
38
|
this.account = account;
|
|
39
|
+
this.secretKey = secretKey;
|
|
40
|
+
}
|
|
41
|
+
/** Create a TradeClient directly from a ClientConfig — no need to construct HttpClient manually. */
|
|
42
|
+
static fromConfig(config, account, secretKey) {
|
|
43
|
+
return new TradeClient(new HttpClient(config), account, secretKey);
|
|
44
|
+
}
|
|
45
|
+
// ── Token management ──────────────────────────────────────────────────────
|
|
46
|
+
/** Call the `user_token_refresh` API and return the new token. Read-only. */
|
|
47
|
+
async queryToken() {
|
|
48
|
+
return tokenMethods.queryToken(this.httpClient);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Refresh the token: call the API, update the in-memory config token, and
|
|
52
|
+
* optionally persist via the provided TokenManager (file + writer callback).
|
|
53
|
+
*
|
|
54
|
+
* @param tokenManager - optional TokenManager for file persistence and writer callback
|
|
55
|
+
*/
|
|
56
|
+
async refreshToken(tokenManager) {
|
|
57
|
+
return tokenMethods.refreshToken(this.httpClient, tokenManager);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Start background token auto-refresh. Returns a TokenManager that can be
|
|
61
|
+
* used to stop the background task via `tm.stopAutoRefresh()`.
|
|
62
|
+
*
|
|
63
|
+
* @param refreshDurationSecs - Refresh threshold in seconds (minimum 30).
|
|
64
|
+
* @param checkIntervalMs - How often to check, in milliseconds (default 300 000 / 5 min).
|
|
65
|
+
* @param tokenWriter - Optional callback invoked after each successful refresh.
|
|
66
|
+
*/
|
|
67
|
+
startTokenAutoRefresh(refreshDurationSecs, checkIntervalMs, tokenWriter) {
|
|
68
|
+
return tokenMethods.startTokenAutoRefresh(this.httpClient, refreshDurationSecs, checkIntervalMs, tokenWriter);
|
|
28
69
|
}
|
|
29
70
|
async callInto(method, bizParams) {
|
|
30
|
-
|
|
71
|
+
// Inject secretKey into every request when available (institution accounts require it).
|
|
72
|
+
// Individual methods that already set secretKey will not be overwritten (|| not &&).
|
|
73
|
+
let params = bizParams;
|
|
74
|
+
if (this.secretKey && params !== null && typeof params === 'object' && !Array.isArray(params)) {
|
|
75
|
+
const p = params;
|
|
76
|
+
if (p['secretKey'] == null && p['secret_key'] == null) {
|
|
77
|
+
params = { ...p, secretKey: this.secretKey };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const request = createApiRequest(method, params);
|
|
31
81
|
const response = await this.httpClient.executeRequest(request);
|
|
32
82
|
return unmarshalData(response.data);
|
|
33
83
|
}
|
|
@@ -59,17 +109,60 @@ export class TradeClient {
|
|
|
59
109
|
});
|
|
60
110
|
}
|
|
61
111
|
// === Order operations ===
|
|
112
|
+
/**
|
|
113
|
+
* Prepare an order request for the wire.
|
|
114
|
+
*
|
|
115
|
+
* The gateway expects `algo_params` as a `[{tag, value}, ...]` array
|
|
116
|
+
* (matching the Python SDK's AlgoParams.to_dict serialization), not the
|
|
117
|
+
* plain object shape that reads naturally in TypeScript. This helper
|
|
118
|
+
* normalizes the object form into the array form on outbound payloads
|
|
119
|
+
* so callers can pass the natural object and TWAP/VWAP orders work end
|
|
120
|
+
* to end without wire-format workarounds.
|
|
121
|
+
*
|
|
122
|
+
* Fields with undefined/null values are dropped; empty algoParams
|
|
123
|
+
* becomes an empty array rather than being stripped, matching the
|
|
124
|
+
* Python SDK behavior when the user passes an empty AlgoParams().
|
|
125
|
+
*/
|
|
126
|
+
marshalOrderForWire(order) {
|
|
127
|
+
const { algoParams, ...rest } = order;
|
|
128
|
+
const withAccount = { ...rest, account: this.account };
|
|
129
|
+
if (algoParams === undefined)
|
|
130
|
+
return withAccount;
|
|
131
|
+
// Already a tag/value array (advanced callers who want raw control)
|
|
132
|
+
if (Array.isArray(algoParams)) {
|
|
133
|
+
withAccount.algoParams = algoParams;
|
|
134
|
+
return withAccount;
|
|
135
|
+
}
|
|
136
|
+
// Object shape → tag/value array.
|
|
137
|
+
// Keys are converted to snake_case explicitly here (e.g. `startTime` →
|
|
138
|
+
// `start_time`) so they land correctly in the `tag` string that the
|
|
139
|
+
// gateway reads. `keysToSnakeCase` only rewrites object *keys*, not
|
|
140
|
+
// string *values*, so `tag` would be left camelCase if we didn't do
|
|
141
|
+
// this conversion ourselves.
|
|
142
|
+
const tagValues = [];
|
|
143
|
+
for (const [key, value] of Object.entries(algoParams)) {
|
|
144
|
+
if (value === undefined || value === null)
|
|
145
|
+
continue;
|
|
146
|
+
const snakeKey = key.replace(/[A-Z]/g, (c) => '_' + c.toLowerCase());
|
|
147
|
+
tagValues.push({ tag: snakeKey, value });
|
|
148
|
+
}
|
|
149
|
+
withAccount.algoParams = tagValues;
|
|
150
|
+
return withAccount;
|
|
151
|
+
}
|
|
62
152
|
async placeOrder(order) {
|
|
63
|
-
return this.callInto('place_order',
|
|
153
|
+
return this.callInto('place_order', this.marshalOrderForWire(order));
|
|
64
154
|
}
|
|
65
155
|
async previewOrder(order) {
|
|
66
|
-
return this.callInto('preview_order',
|
|
156
|
+
return this.callInto('preview_order', this.marshalOrderForWire(order));
|
|
67
157
|
}
|
|
68
158
|
async modifyOrder(id, order) {
|
|
69
|
-
return this.callInto('modify_order', { ...
|
|
159
|
+
return this.callInto('modify_order', { ...this.marshalOrderForWire(order), id });
|
|
70
160
|
}
|
|
71
|
-
async cancelOrder(id) {
|
|
72
|
-
|
|
161
|
+
async cancelOrder(id, secretKey) {
|
|
162
|
+
const params = { account: this.account, id };
|
|
163
|
+
if (secretKey !== undefined)
|
|
164
|
+
params.secretKey = secretKey; // per-call override takes precedence; undefined means use config default
|
|
165
|
+
return this.callInto('cancel_order', params);
|
|
73
166
|
}
|
|
74
167
|
// === Order queries (BREAKING v0.4.0) ===
|
|
75
168
|
/**
|
|
@@ -106,14 +199,11 @@ export class TradeClient {
|
|
|
106
199
|
}
|
|
107
200
|
/**
|
|
108
201
|
* Get a single order by ID (v0.4.0 new).
|
|
109
|
-
* Wire method: `orders` with id/order_id param; server returns a single Order object
|
|
110
|
-
* (not `{items:[]}` envelope).
|
|
111
|
-
*
|
|
112
202
|
* Returns `undefined` if no match.
|
|
113
203
|
*/
|
|
114
204
|
async getOrder(req) {
|
|
115
205
|
const merged = withAccount(req, this.account);
|
|
116
|
-
const out = await this.callInto('
|
|
206
|
+
const out = await this.callInto('order_no', merged);
|
|
117
207
|
if (!out || (!out.id && !out.orderId))
|
|
118
208
|
return undefined;
|
|
119
209
|
normalizeOrderInPlace(out);
|
|
@@ -191,9 +281,10 @@ export class TradeClient {
|
|
|
191
281
|
async getFundDetails(req) {
|
|
192
282
|
return this.callIntoItems('fund_details', withAccount(req, this.account));
|
|
193
283
|
}
|
|
194
|
-
/** Funding history (wire method: `transfer_fund`).
|
|
284
|
+
/** Funding history (wire method: `transfer_fund`).
|
|
285
|
+
* Server returns bare list (no items wrapper). */
|
|
195
286
|
async getFundingHistory(req) {
|
|
196
|
-
return this.
|
|
287
|
+
return this.callInto('transfer_fund', withAccount(req, this.account));
|
|
197
288
|
}
|
|
198
289
|
// ===== v0.4.0 NEW: Internal / external position transfer =====
|
|
199
290
|
/**
|
|
@@ -227,4 +318,41 @@ export class TradeClient {
|
|
|
227
318
|
merged.accountId = this.account;
|
|
228
319
|
return this.callIntoItems('position_transfer_external_records', merged);
|
|
229
320
|
}
|
|
321
|
+
/** 行权检验:预估行权/作废后正股持仓变化 (wire: option_exercise_check) */
|
|
322
|
+
async checkOptionExercise(req) {
|
|
323
|
+
const merged = { ...req };
|
|
324
|
+
if (!merged.account)
|
|
325
|
+
merged.account = this.account;
|
|
326
|
+
return this.callInto('option_exercise_check', merged);
|
|
327
|
+
}
|
|
328
|
+
/** 查询可行权持仓列表 (wire: option_exercise_position) */
|
|
329
|
+
async getOptionExercisePositions(req) {
|
|
330
|
+
const merged = { ...req };
|
|
331
|
+
if (!merged.account)
|
|
332
|
+
merged.account = this.account;
|
|
333
|
+
return this.callInto('option_exercise_position', merged);
|
|
334
|
+
}
|
|
335
|
+
/** 提交行权/作废申请 (wire: option_exercise_submit) */
|
|
336
|
+
async submitOptionExercise(req) {
|
|
337
|
+
const merged = { ...req };
|
|
338
|
+
if (!merged.account)
|
|
339
|
+
merged.account = this.account;
|
|
340
|
+
const result = await this.callInto('option_exercise_submit', merged);
|
|
341
|
+
return result ?? false;
|
|
342
|
+
}
|
|
343
|
+
/** 分页查询行权记录 (wire: option_exercise_record) */
|
|
344
|
+
async getOptionExerciseRecords(req) {
|
|
345
|
+
const merged = { ...req };
|
|
346
|
+
if (!merged.account)
|
|
347
|
+
merged.account = this.account;
|
|
348
|
+
return this.callInto('option_exercise_record', merged);
|
|
349
|
+
}
|
|
350
|
+
/** 撤销行权申请 (wire: option_exercise_cancel) */
|
|
351
|
+
async cancelOptionExercise(req) {
|
|
352
|
+
const merged = { ...req };
|
|
353
|
+
if (!merged.account)
|
|
354
|
+
merged.account = this.account;
|
|
355
|
+
const result = await this.callInto('option_exercise_cancel', merged);
|
|
356
|
+
return result ?? false;
|
|
357
|
+
}
|
|
230
358
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SDK_VERSION = '0.4.8';
|
|
@@ -12,13 +12,15 @@ export interface ApiResponse {
|
|
|
12
12
|
sign?: string;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* Parse the raw HTTP response body.
|
|
16
|
-
*
|
|
15
|
+
* Parse the raw HTTP response body. Throws TigerError when code != 0.
|
|
16
|
+
*
|
|
17
|
+
* patchLargeIntegers is applied before JSON.parse to preserve int64 order IDs
|
|
18
|
+
* (e.g. 28868646234578944) as strings rather than losing precision.
|
|
17
19
|
*/
|
|
18
20
|
export declare function parseApiResponse(body: string): ApiResponse;
|
|
19
21
|
/**
|
|
20
22
|
* Decode an ApiResponse.data payload into a typed value.
|
|
21
|
-
* Handles
|
|
22
|
-
*
|
|
23
|
+
* Handles double-encoded JSON (where `data` is a JSON string wrapping JSON),
|
|
24
|
+
* seen on some trade endpoints.
|
|
23
25
|
*/
|
|
24
26
|
export declare function unmarshalData<T>(data: unknown): T | undefined;
|
|
@@ -11,6 +11,8 @@ export declare function camelToSnake(key: string): string;
|
|
|
11
11
|
/**
|
|
12
12
|
* Recursively convert all object keys from camelCase to snake_case.
|
|
13
13
|
* Preserves arrays, primitives, and Date/null/undefined.
|
|
14
|
-
*
|
|
14
|
+
*
|
|
15
|
+
* Note: camelToSnake is idempotent for pure snake_case keys (no uppercase
|
|
16
|
+
* letters → no replacements), so no pre-check is needed.
|
|
15
17
|
*/
|
|
16
18
|
export declare function keysToSnakeCase(value: unknown): unknown;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Uses Node.js built-in fetch (Node 18+).
|
|
6
6
|
*/
|
|
7
7
|
import type { ClientConfig } from '../config/client-config';
|
|
8
|
+
import { TokenManager, type TokenManagerOptions } from '../config/token-manager';
|
|
8
9
|
import { RetryPolicy } from './retry';
|
|
9
10
|
import { type ApiResponse } from './api-response';
|
|
10
11
|
import type { ApiRequest } from './api-request';
|
|
@@ -16,9 +17,16 @@ export declare class HttpClient {
|
|
|
16
17
|
private retryPolicy;
|
|
17
18
|
/** Override the target URL (used by quote client to hit quote server) */
|
|
18
19
|
private targetUrl;
|
|
20
|
+
/** non-null when auto-refresh is active */
|
|
21
|
+
private tokenManager;
|
|
19
22
|
constructor(config: ClientConfig, retryPolicy?: RetryPolicy, options?: {
|
|
20
23
|
useQuoteServerUrl?: boolean;
|
|
21
24
|
});
|
|
25
|
+
/**
|
|
26
|
+
* Stop the background token auto-refresh timer.
|
|
27
|
+
* Call this when the HttpClient is no longer needed to avoid timer leaks.
|
|
28
|
+
*/
|
|
29
|
+
close(): void;
|
|
22
30
|
/**
|
|
23
31
|
* Build common request parameters
|
|
24
32
|
*/
|
|
@@ -41,9 +49,32 @@ export declare class HttpClient {
|
|
|
41
49
|
*
|
|
42
50
|
* @param apiMethod - API method name (e.g. "market_state", "place_order")
|
|
43
51
|
* @param requestJson - Raw biz_content JSON string
|
|
52
|
+
* @param version - Optional API version override (default: "2.0")
|
|
44
53
|
* @returns Raw response JSON string, unparsed
|
|
45
54
|
*/
|
|
46
|
-
execute(apiMethod: string, requestJson: string): Promise<string>;
|
|
55
|
+
execute(apiMethod: string, requestJson: string, version?: string): Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* 调用 user_token_refresh 接口获取新 token,返回新 token 字符串。
|
|
58
|
+
* 此方法仅查询,不修改 config 中的 token。
|
|
59
|
+
*/
|
|
60
|
+
queryToken(): Promise<string>;
|
|
61
|
+
/**
|
|
62
|
+
* 刷新 token:调用接口获取新 token 后更新 config.token。
|
|
63
|
+
*
|
|
64
|
+
* @param tokenManager - 可选外部 TokenManager;若提供则调用 setToken() 写文件并触发回调。
|
|
65
|
+
* 若 NewHttpClient 已自动启动内部 TokenManager,其内存 token 也会同步更新。
|
|
66
|
+
*/
|
|
67
|
+
refreshToken(tokenManager?: TokenManager | null): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* 启动后台 token 自动刷新。
|
|
70
|
+
*
|
|
71
|
+
* @param tokenManager - 可为 null:SDK 内部自动创建一个仅内存的 TokenManager,
|
|
72
|
+
* 适合直接通过 token 在代码里设置、不使用文件的场景。
|
|
73
|
+
* @param options - 仅在 tokenManager 为 null 时生效,用于配置内部 TokenManager
|
|
74
|
+
* (refreshDuration / refreshInterval / tokenWriter / tokenLoader)。
|
|
75
|
+
* @returns 使用或创建的 TokenManager 实例
|
|
76
|
+
*/
|
|
77
|
+
startTokenAutoRefresh(tokenManager: TokenManager | null, options?: TokenManagerOptions): TokenManager;
|
|
47
78
|
/** Delay for the specified milliseconds */
|
|
48
79
|
private sleep;
|
|
49
80
|
/**
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared token management methods for TradeClient and QuoteClient.
|
|
3
|
+
* Both clients delegate to the underlying HttpClient; this module
|
|
4
|
+
* centralises the JSDoc so each client stays in sync automatically.
|
|
5
|
+
*/
|
|
6
|
+
import type { HttpClient } from './http-client';
|
|
7
|
+
import type { TokenManager } from '../config/token-manager';
|
|
8
|
+
/**
|
|
9
|
+
* Call the `user_token_refresh` API and return the new token string.
|
|
10
|
+
* Read-only: does NOT update the stored token.
|
|
11
|
+
* Use `refreshToken()` to also update the in-memory config and optionally persist.
|
|
12
|
+
*/
|
|
13
|
+
export declare function queryToken(httpClient: HttpClient): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Refresh the token: call the API, update the in-memory config token, and
|
|
16
|
+
* optionally persist via the provided TokenManager (file + writer callback).
|
|
17
|
+
*
|
|
18
|
+
* @param httpClient - The underlying HTTP client
|
|
19
|
+
* @param tokenManager - optional TokenManager for file persistence and writer callback
|
|
20
|
+
*/
|
|
21
|
+
export declare function refreshToken(httpClient: HttpClient, tokenManager?: TokenManager | null): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Start background token auto-refresh. Returns a TokenManager that can be
|
|
24
|
+
* used to stop the background task via `tm.stopAutoRefresh()`.
|
|
25
|
+
*
|
|
26
|
+
* @param httpClient - The underlying HTTP client
|
|
27
|
+
* @param refreshDurationSecs - Refresh threshold in seconds (minimum 30).
|
|
28
|
+
* When the token age exceeds this value the refresh is triggered.
|
|
29
|
+
* @param checkIntervalMs - How often to check whether a refresh is needed,
|
|
30
|
+
* in milliseconds. Defaults to 300 000 ms (5 minutes).
|
|
31
|
+
* @param tokenWriter - Optional callback invoked with the new token string
|
|
32
|
+
* after each successful refresh.
|
|
33
|
+
*/
|
|
34
|
+
export declare function startTokenAutoRefresh(httpClient: HttpClient, refreshDurationSecs: number, checkIntervalMs?: number, tokenWriter?: (token: string) => void): TokenManager;
|
|
@@ -1,14 +1,24 @@
|
|
|
1
|
+
/** Sandbox / QA tiger public key for response signature verification */
|
|
2
|
+
export declare const SANDBOX_TIGER_PUBLIC_KEY: string;
|
|
1
3
|
/** Client configuration interface */
|
|
2
4
|
export interface ClientConfig {
|
|
3
5
|
tigerId: string;
|
|
4
6
|
privateKey: string;
|
|
5
7
|
account: string;
|
|
8
|
+
/** Institution secret key for trade authentication (institution accounts only) */
|
|
9
|
+
secretKey?: string;
|
|
6
10
|
license?: string;
|
|
7
11
|
language: string;
|
|
8
12
|
timezone?: string;
|
|
9
13
|
timeout: number;
|
|
10
14
|
token?: string;
|
|
11
15
|
tokenRefreshDuration?: number;
|
|
16
|
+
/** 后台 token 检查间隔(毫秒),仅 tokenRefreshDuration > 0 时生效,默认 5 分钟 */
|
|
17
|
+
tokenCheckInterval?: number;
|
|
18
|
+
/** 自定义 token 加载函数,替代默认的文件加载 */
|
|
19
|
+
tokenLoader?: () => Promise<string> | string;
|
|
20
|
+
/** token 刷新写入后的可选回调 */
|
|
21
|
+
tokenWriter?: (token: string) => void;
|
|
12
22
|
serverUrl: string;
|
|
13
23
|
/** Quote server URL for quote-specific requests; falls back to serverUrl */
|
|
14
24
|
quoteServerUrl: string;
|
|
@@ -21,19 +31,30 @@ export interface ClientConfigOptions {
|
|
|
21
31
|
tigerId?: string;
|
|
22
32
|
privateKey?: string;
|
|
23
33
|
account?: string;
|
|
34
|
+
/** Institution secret key for trade authentication (institution accounts only) */
|
|
35
|
+
secretKey?: string;
|
|
24
36
|
license?: string;
|
|
25
37
|
language?: string;
|
|
26
38
|
timezone?: string;
|
|
27
39
|
timeout?: number;
|
|
28
40
|
token?: string;
|
|
29
41
|
tokenRefreshDuration?: number;
|
|
42
|
+
/** 后台 token 检查间隔(毫秒),仅 tokenRefreshDuration > 0 时生效,默认 5 分钟 */
|
|
43
|
+
tokenCheckInterval?: number;
|
|
44
|
+
/** 自定义 token 加载函数,替代默认的文件加载 */
|
|
45
|
+
tokenLoader?: () => Promise<string> | string;
|
|
46
|
+
/** token 刷新写入后的可选回调 */
|
|
47
|
+
tokenWriter?: (token: string) => void;
|
|
30
48
|
serverUrl?: string;
|
|
31
49
|
/** Explicit quote server URL; resolved dynamically if not set */
|
|
32
50
|
quoteServerUrl?: string;
|
|
33
51
|
/** Enable dynamic domain resolution (default: true) */
|
|
34
52
|
enableDynamicDomain?: boolean;
|
|
35
|
-
/** Explicit properties file path (synchronous read)
|
|
53
|
+
/** Explicit properties file path or directory (synchronous read).
|
|
54
|
+
* If a directory is given, appends 'tiger_openapi_config.properties' automatically. */
|
|
36
55
|
propertiesFilePath?: string;
|
|
56
|
+
/** Override Tiger public key (e.g. for sandbox/QA environments) */
|
|
57
|
+
tigerPublicKey?: string;
|
|
37
58
|
}
|
|
38
59
|
/**
|
|
39
60
|
* Load and parse a Java-style properties file.
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* 配置层导出
|
|
3
3
|
*/
|
|
4
4
|
export { parsePropertiesFile, parsePropertiesString } from './config-parser';
|
|
5
|
-
export { createClientConfig, loadPropertiesFile } from './client-config';
|
|
5
|
+
export { createClientConfig, loadPropertiesFile, SANDBOX_TIGER_PUBLIC_KEY } from './client-config';
|
|
6
6
|
export type { ClientConfig, ClientConfigOptions } from './client-config';
|
|
7
|
+
export { TokenManager } from './token-manager';
|
|
8
|
+
export type { TokenManagerOptions, RefreshFn } from './token-manager';
|
|
7
9
|
export { queryDomains, resolveDynamicServerUrl, resolveDynamicQuoteServerUrl } from './domain';
|
|
@@ -4,6 +4,10 @@ export interface TokenManagerOptions {
|
|
|
4
4
|
refreshInterval?: number;
|
|
5
5
|
/** Token 刷新阈值(秒),0 表示不刷新,最小 30 秒 */
|
|
6
6
|
refreshDuration?: number;
|
|
7
|
+
/** 自定义 token 加载函数,优先于文件加载 */
|
|
8
|
+
tokenLoader?: () => Promise<string> | string;
|
|
9
|
+
/** token 写入后的回调(SetToken 成功后触发,SyncToken 不触发) */
|
|
10
|
+
tokenWriter?: (token: string) => void;
|
|
7
11
|
}
|
|
8
12
|
/** Token 刷新函数类型 */
|
|
9
13
|
export type RefreshFn = () => Promise<string>;
|
|
@@ -13,16 +17,36 @@ export type RefreshFn = () => Promise<string>;
|
|
|
13
17
|
export declare class TokenManager {
|
|
14
18
|
private token;
|
|
15
19
|
private filePath;
|
|
20
|
+
/** 仅当显式传入 filePath 时才写文件(fileEnabled = true) */
|
|
21
|
+
private fileEnabled;
|
|
16
22
|
private refreshInterval;
|
|
17
23
|
private refreshDuration;
|
|
18
24
|
private timer;
|
|
25
|
+
private tokenLoader;
|
|
26
|
+
private tokenWriter;
|
|
19
27
|
constructor(options?: TokenManagerOptions);
|
|
20
|
-
/**
|
|
21
|
-
|
|
28
|
+
/**
|
|
29
|
+
* 从 properties 文件(或自定义 tokenLoader)加载 Token。
|
|
30
|
+
* 若设置了 tokenLoader,优先调用;否则从 properties 文件读取。
|
|
31
|
+
*/
|
|
32
|
+
loadToken(): Promise<string>;
|
|
33
|
+
/**
|
|
34
|
+
* 同步版文件加载(仅用于无 tokenLoader 时的兼容入口)。
|
|
35
|
+
* 建议优先使用 loadToken()(异步)。
|
|
36
|
+
*/
|
|
37
|
+
loadTokenSync(): string;
|
|
22
38
|
/** 获取当前 Token */
|
|
23
39
|
getToken(): string;
|
|
24
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* 设置 Token;若启用了文件持久化(显式传入 filePath),则同步写文件。
|
|
42
|
+
* 成功后触发 tokenWriter 回调(如有)。
|
|
43
|
+
*/
|
|
25
44
|
setToken(token: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* 仅更新内存中的 token,不写文件,不触发 tokenWriter 回调。
|
|
47
|
+
* 用于多个组件共享 token 时的内部同步。
|
|
48
|
+
*/
|
|
49
|
+
syncToken(token: string): void;
|
|
26
50
|
/** 将 Token 保存到 properties 文件 */
|
|
27
51
|
private saveTokenToFile;
|
|
28
52
|
/**
|
package/dist/types/index.d.ts
CHANGED
|
@@ -15,4 +15,25 @@
|
|
|
15
15
|
* @packageDocumentation
|
|
16
16
|
*/
|
|
17
17
|
/** SDK 版本号 */
|
|
18
|
-
export
|
|
18
|
+
export { SDK_VERSION as VERSION } from './version';
|
|
19
|
+
export { createClientConfig, loadPropertiesFile, SANDBOX_TIGER_PUBLIC_KEY } from './config';
|
|
20
|
+
export type { ClientConfig, ClientConfigOptions } from './config';
|
|
21
|
+
export { TokenManager } from './config';
|
|
22
|
+
export type { TokenManagerOptions, RefreshFn } from './config';
|
|
23
|
+
export { HttpClient } from './client';
|
|
24
|
+
export { TigerError, classifyErrorCode } from './client';
|
|
25
|
+
export type { ErrorCategory } from './client';
|
|
26
|
+
export { QuoteClient, parseOptionIdentifier } from './quote';
|
|
27
|
+
export { TradeClient } from './trade';
|
|
28
|
+
export { PushClient, ConnectionState, SubjectType } from './push';
|
|
29
|
+
export type { PushClientOptions } from './push';
|
|
30
|
+
export type { Order, OrderRequest, ContractLegRequest } from './model/order';
|
|
31
|
+
export { marketOrder, limitOrder, stopOrder, stopLimitOrder } from './model/order-helpers';
|
|
32
|
+
export { normalizeOrderStatus } from './model/order-status';
|
|
33
|
+
export type { Contract } from './model/contract';
|
|
34
|
+
export type { Position } from './model/position';
|
|
35
|
+
export type { Asset, AssetSegment, PrimeAsset, PreviewResult, PlaceOrderResult, OrderIdResult, Transaction, ManagedAccount, AnalyticsAsset, AggregateAssets, EstimateTradableQuantity, ForexOrderResult, SegmentFund, SegmentFundAvailableItem, SegmentFundHistoryItem, FundDetails, FundingHistoryItem, PositionTransferRecord, PositionTransferDetail, PositionTransferExternalRecord, OptionExerciseCheckResult, OptionExercisePositionPageResult, OptionExerciseRecordPageResult, } from './model/trade';
|
|
36
|
+
export type { OrdersRequest, GetOrderRequest, OrderTransactionsRequest, PositionsRequest, AssetsRequest, ManagedAccountsRequest, DerivativeContractsRequest, AnalyticsAssetRequest, AggregateAssetsRequest, EstimateTradableQuantityRequest, ForexOrderRequest, SegmentFundRequest, FundDetailsRequest, FundingHistoryRequest, PositionTransferRequest, PositionTransferRecordsRequest, PositionTransferDetailRequest, PositionTransferExternalRecordsRequest, OptionExerciseCheckRequest, OptionExercisePositionRequest, OptionExerciseSubmitRequest, OptionExerciseRecordsRequest, OptionExerciseCancelRequest, } from './model/trade-requests';
|
|
37
|
+
export type { MarketState, Brief, Kline, KlineItem, Timeline, TimelineItem, TradeTick, TradeTickItem, Depth, DepthLevel, OptionExpiration, OptionChain, OptionChainRow, OptionSymbol, OptionChainFilter, OptionChainFilterGreeks, Range, FutureExchange, FutureContractInfo, FutureQuote, FutureKline, FutureKlineItem, FutureDepth, FutureTradeTickItem, FutureTradingTime, FinancialDailyItem, FinancialReportItem, CorporateAction, CorporateSymbolChange, CorporateDelisting, CorporateIPO, CapitalFlow, CapitalFlowItem, CapitalDistribution, ScannerResult, ScannerResultItem, QuotePermission, SymbolName, TradeMeta, StockDetail, StockBroker, StockBrokerItem, ShortInterest, StockIndustry, IndustryItem, IndustryStock, WarrantBrief, WarrantFilterResult, FundContractInfo, FundQuote, FundHistoryQuote, QuoteOvernight, KlineQuota, MarketScannerTag, MarketScannerTags, OptionAnalysis, OptionLeg, OptionVolatilityPoint, ExchangeRate, FinancialCurrency, BrokerDetail, TradingCalendarItem, FutureMainContractHistory, } from './model/quote';
|
|
38
|
+
export type { BriefRequest, DepthQuoteRequest, TradeTickRequest, KlineRequest, KlineByPageRequest, TimelineRequest, FutureBriefRequest, FutureKlineRequest, FutureKlineByPageRequest, FutureTradeTicksRequest, FutureDepthRequest, FutureContractSingleRequest, FutureContinuousContractsRequest, FutureHistoryMainContractRequest, FutureTradingTimesRequest, AllFutureContractsRequest, OptionTradeTicksRequest, OptionTimelineRequest, OptionDepthRequest, OptionSymbolsRequest, OptionAnalysisRequest, OptionQueryItem, ShortInterestRequest, StockBrokerRequest, StockDetailsRequest, StockFundamentalRequest, StockIndustryRequest, StockDelayBriefsRequest, SymbolsRequest, TradeMetasRequest, TradeRankRequest, TimelineHistoryRequest, TradingCalendarRequest, KlineQuotaRequest, QuotePermissionRequest, QuoteOvernightRequest, IndustryListRequest, IndustryStocksRequest, FundSymbolsRequest, FundContractsRequest, FundQuoteRequest, FundHistoryQuoteRequest, WarrantBriefsRequest, WarrantFilterRequest, MarketScannerTagsRequest, FinancialCurrencyRequest, FinancialExchangeRateRequest, } from './model/quote-requests';
|
|
39
|
+
export { OrderStatus, SecurityType, OrderType, TimeInForce, Market, Currency, QuoteRight, SegmentType, OrderSortBy, CorporateActionType, IndustryLevel, SortDirection, OptionAnalysisPeriod, FinancialReportPeriod, Language, License, BarPeriod, orderStatusCode, } from './model/enums';
|
|
@@ -42,7 +42,19 @@ export declare enum OrderType {
|
|
|
42
42
|
AL = "AL",
|
|
43
43
|
TWAP = "TWAP",
|
|
44
44
|
VWAP = "VWAP",
|
|
45
|
-
OCA = "OCA"
|
|
45
|
+
OCA = "OCA",
|
|
46
|
+
ICEBERG = "ICEBERG"
|
|
47
|
+
}
|
|
48
|
+
/** 冰山单价格类型 */
|
|
49
|
+
export declare enum PriceType {
|
|
50
|
+
/** 限价 */
|
|
51
|
+
LIMIT_PRICE = "LIMIT_PRICE",
|
|
52
|
+
/** 卖一价 */
|
|
53
|
+
ASK_PRICE = "ASK_PRICE",
|
|
54
|
+
/** 买一价 */
|
|
55
|
+
BID_PRICE = "BID_PRICE",
|
|
56
|
+
/** 最新价 */
|
|
57
|
+
LATEST_PRICE = "LATEST_PRICE"
|
|
46
58
|
}
|
|
47
59
|
/**
|
|
48
60
|
* 订单状态枚举。对齐 Java SDK OrderStatus 定义。
|
|
@@ -103,6 +115,7 @@ export declare enum License {
|
|
|
103
115
|
export declare enum TimeInForce {
|
|
104
116
|
DAY = "DAY",
|
|
105
117
|
GTC = "GTC",
|
|
118
|
+
GTD = "GTD",
|
|
106
119
|
OPG = "OPG"
|
|
107
120
|
}
|
|
108
121
|
/** 订单排序字段 */
|
|
@@ -121,7 +134,10 @@ export declare enum SegmentType {
|
|
|
121
134
|
export declare enum CorporateActionType {
|
|
122
135
|
Split = "split",
|
|
123
136
|
Dividend = "dividend",
|
|
124
|
-
Earning = "earning"
|
|
137
|
+
Earning = "earning",
|
|
138
|
+
SymbolChange = "symbol_change",
|
|
139
|
+
Delisting = "delisting",
|
|
140
|
+
IPO = "ipo"
|
|
125
141
|
}
|
|
126
142
|
/** 行业级别 (1~4 级) */
|
|
127
143
|
export declare enum IndustryLevel {
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Order construction helpers.
|
|
3
3
|
* All helpers return an `OrderRequest` with sensible defaults.
|
|
4
4
|
*/
|
|
5
|
-
import type { OrderRequest, OrderLegRequest, AlgoParamsRequest } from './order';
|
|
5
|
+
import type { OrderRequest, OrderLegRequest, AlgoParamsRequest, ContractLegRequest } from './order';
|
|
6
|
+
import { PriceType } from './enums';
|
|
6
7
|
/** Market order */
|
|
7
8
|
export declare function marketOrder(account: string, symbol: string, secType: string, action: string, quantity: number): OrderRequest;
|
|
8
9
|
/** Limit order */
|
|
@@ -19,5 +20,55 @@ export declare function auctionLimitOrder(account: string, symbol: string, secTy
|
|
|
19
20
|
export declare function auctionMarketOrder(account: string, symbol: string, secType: string, action: string, quantity: number): OrderRequest;
|
|
20
21
|
/** Algo order (TWAP / VWAP) */
|
|
21
22
|
export declare function algoOrder(account: string, symbol: string, secType: string, action: string, quantity: number, limitPrice: number, algoType: string, params: AlgoParamsRequest): OrderRequest;
|
|
23
|
+
/**
|
|
24
|
+
* Iceberg order. `displaySize` is required; all other parameters are optional.
|
|
25
|
+
* Pass `priceType` as empty string to use the server default (LIMIT_PRICE).
|
|
26
|
+
* Pass `startTime` / `endTime` as 0 to omit the time window.
|
|
27
|
+
*/
|
|
28
|
+
export declare function icebergOrder(account: string, symbol: string, secType: string, action: string, quantity: number, limitPrice: number, displaySize: number, minDisplaySize?: number, checkIntervals?: number, priceType?: PriceType | string, startTime?: number, endTime?: number): OrderRequest;
|
|
22
29
|
/** Attached profit / loss leg */
|
|
23
30
|
export declare function orderLeg(legType: string, price: number, timeInForce: string): OrderLegRequest;
|
|
31
|
+
/**
|
|
32
|
+
* Market order by cash amount (instead of quantity).
|
|
33
|
+
* Server uses `isQuantityByAmount=true` + `amount` field.
|
|
34
|
+
*/
|
|
35
|
+
export declare function marketOrderByAmount(account: string, symbol: string, secType: string, action: string, amount: number): OrderRequest;
|
|
36
|
+
/**
|
|
37
|
+
* Limit order by cash amount (instead of quantity).
|
|
38
|
+
*/
|
|
39
|
+
export declare function limitOrderByAmount(account: string, symbol: string, secType: string, action: string, amount: number, limitPrice: number): OrderRequest;
|
|
40
|
+
/**
|
|
41
|
+
* Trailing stop order using a fixed price offset (auxPrice) instead of a percentage.
|
|
42
|
+
* Use `trailOrder()` for percentage-based trailing stops.
|
|
43
|
+
*/
|
|
44
|
+
export declare function trailOrderByPrice(account: string, symbol: string, secType: string, action: string, quantity: number, auxPrice: number): OrderRequest;
|
|
45
|
+
/**
|
|
46
|
+
* Limit order with attached profit/loss legs (bracket order).
|
|
47
|
+
* At most 2 legs are supported.
|
|
48
|
+
*
|
|
49
|
+
* @param orderLegs - Array of `OrderLegRequest` (use `orderLeg()` helper)
|
|
50
|
+
*/
|
|
51
|
+
export declare function limitOrderWithLegs(account: string, symbol: string, secType: string, action: string, quantity: number, limitPrice: number, orderLegs: OrderLegRequest[]): OrderRequest;
|
|
52
|
+
/**
|
|
53
|
+
* Multi-leg (combo/MLEG) order for options combos.
|
|
54
|
+
*
|
|
55
|
+
* @param contractLegs - Array of `ContractLegRequest` (use `contractLeg()` helper)
|
|
56
|
+
* @param comboType - e.g. `'MLEG'`
|
|
57
|
+
*/
|
|
58
|
+
export declare function comboOrder(account: string, action: string, quantity: number, orderType: string, contractLegs: ContractLegRequest[], comboType?: string, limitPrice?: number, auxPrice?: number, trailingPercent?: number): OrderRequest;
|
|
59
|
+
/**
|
|
60
|
+
* OCA (One-Cancels-All) order.
|
|
61
|
+
* Server expects `orderType: 'OCA'` and an `ocaOrders` list.
|
|
62
|
+
*
|
|
63
|
+
* @param ocaOrders - The contained orders (use any order helper to build each)
|
|
64
|
+
*/
|
|
65
|
+
export declare function ocaOrder(account: string, symbol: string, secType: string, action: string, quantity: number, ocaOrders: OrderRequest[]): OrderRequest;
|
|
66
|
+
/**
|
|
67
|
+
* Build a single leg for a multi-leg (MLEG / combo) order.
|
|
68
|
+
*
|
|
69
|
+
* @param symbol - Underlying symbol
|
|
70
|
+
* @param secType - Security type (e.g. `'OPT'`)
|
|
71
|
+
* @param action - `'BUY'` or `'SELL'`
|
|
72
|
+
* @param ratio - Number of contracts for this leg
|
|
73
|
+
*/
|
|
74
|
+
export declare function contractLeg(symbol: string, secType: string, action: string, ratio: number, expiry?: string, strike?: string, right?: string): ContractLegRequest;
|