@tigeropenapi/tigeropen 0.4.7 → 0.4.9
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/dist/cjs/client/http-client.js +2 -3
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/push/push-client.js +2 -1
- package/dist/cjs/quote/quote-client.js +137 -57
- package/dist/cjs/trade/trade-client.js +14 -0
- package/dist/cjs/version.js +4 -0
- package/dist/esm/client/http-client.js +1 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/push/push-client.js +2 -1
- package/dist/esm/quote/quote-client.js +137 -57
- package/dist/esm/trade/trade-client.js +14 -0
- package/dist/esm/version.js +1 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/model/quote-requests.d.ts +6 -13
- package/dist/types/quote/quote-client.d.ts +49 -30
- package/dist/types/trade/trade-client.d.ts +4 -1
- package/dist/types/version.d.ts +1 -0
- package/package.json +1 -1
|
@@ -7,10 +7,9 @@ const signer_1 = require("../signer/signer");
|
|
|
7
7
|
const errors_1 = require("./errors");
|
|
8
8
|
const retry_1 = require("./retry");
|
|
9
9
|
const api_response_1 = require("./api-response");
|
|
10
|
-
|
|
11
|
-
const SDK_VERSION = '0.4.0';
|
|
10
|
+
const version_1 = require("../version");
|
|
12
11
|
/** User-Agent 字符串 */
|
|
13
|
-
const USER_AGENT = `openapi-typescript-sdk-${SDK_VERSION}`;
|
|
12
|
+
const USER_AGENT = `openapi-typescript-sdk-${version_1.SDK_VERSION}`;
|
|
14
13
|
/** 默认字符集 */
|
|
15
14
|
const DEFAULT_CHARSET = 'UTF-8';
|
|
16
15
|
/** 默认签名类型 */
|
package/dist/cjs/index.js
CHANGED
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.orderStatusCode = exports.BarPeriod = exports.License = exports.Language = exports.FinancialReportPeriod = exports.OptionAnalysisPeriod = exports.SortDirection = exports.IndustryLevel = exports.CorporateActionType = exports.OrderSortBy = exports.SegmentType = exports.QuoteRight = exports.Currency = exports.Market = exports.TimeInForce = exports.OrderType = exports.SecurityType = exports.OrderStatus = exports.normalizeOrderStatus = exports.stopLimitOrder = exports.stopOrder = exports.limitOrder = exports.marketOrder = exports.SubjectType = exports.ConnectionState = exports.PushClient = exports.TradeClient = exports.parseOptionIdentifier = exports.QuoteClient = exports.classifyErrorCode = exports.TigerError = exports.HttpClient = exports.TokenManager = exports.loadPropertiesFile = exports.createClientConfig = exports.VERSION = void 0;
|
|
20
20
|
/** SDK 版本号 */
|
|
21
|
-
|
|
21
|
+
var version_1 = require("./version");
|
|
22
|
+
Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_1.SDK_VERSION; } });
|
|
22
23
|
// Config
|
|
23
24
|
var config_1 = require("./config");
|
|
24
25
|
Object.defineProperty(exports, "createClientConfig", { enumerable: true, get: function () { return config_1.createClientConfig; } });
|
|
@@ -64,8 +64,9 @@ const DEFAULT_RECONNECT_INTERVAL = 5000;
|
|
|
64
64
|
const MAX_RECONNECT_INTERVAL = 60000;
|
|
65
65
|
/** Default connect timeout (ms) */
|
|
66
66
|
const DEFAULT_CONNECT_TIMEOUT = 30000;
|
|
67
|
+
const version_1 = require("../version");
|
|
67
68
|
/** SDK version identifier */
|
|
68
|
-
const SDK_VERSION =
|
|
69
|
+
const SDK_VERSION = `typescript/${version_1.SDK_VERSION}`;
|
|
69
70
|
/** Protocol version */
|
|
70
71
|
const ACCEPT_VERSION = '1.0';
|
|
71
72
|
/** Default send heartbeat interval (ms) */
|
|
@@ -2,13 +2,59 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QuoteClient = void 0;
|
|
4
4
|
exports.parseOptionIdentifier = parseOptionIdentifier;
|
|
5
|
+
/**
|
|
6
|
+
* QuoteClient — market-data client.
|
|
7
|
+
*
|
|
8
|
+
* All methods return strongly-typed responses from the `model` package.
|
|
9
|
+
* Request parameters are written in camelCase in TypeScript and are
|
|
10
|
+
* converted to snake_case on the wire automatically.
|
|
11
|
+
*/
|
|
12
|
+
const http_client_1 = require("../client/http-client");
|
|
5
13
|
const api_request_1 = require("../client/api-request");
|
|
6
14
|
const api_response_1 = require("../client/api-response");
|
|
15
|
+
/**
|
|
16
|
+
* resolveOptionTimezone returns the timezone string to use for expiry conversion.
|
|
17
|
+
* Explicit tz takes precedence; otherwise infer from symbol (.HK suffix → Asia/Hong_Kong, else America/New_York).
|
|
18
|
+
*/
|
|
19
|
+
function resolveOptionTimezone(tz, symbol) {
|
|
20
|
+
if (tz)
|
|
21
|
+
return tz;
|
|
22
|
+
return symbol.toUpperCase().endsWith('.HK') ? 'Asia/Hong_Kong' : 'America/New_York';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Convert a "YYYY-MM-DD" date string to the Unix timestamp (ms) of local midnight
|
|
26
|
+
* in the given IANA timezone.
|
|
27
|
+
*
|
|
28
|
+
* Strategy: use Intl.DateTimeFormat to determine what UTC time corresponds to
|
|
29
|
+
* local midnight in the target timezone, correctly handling DST.
|
|
30
|
+
*/
|
|
31
|
+
function localMidnightMs(dateStr, timezone) {
|
|
32
|
+
const [year, month, day] = dateStr.split('-').map(Number);
|
|
33
|
+
// Use noon UTC as a safe anchor (avoids DST ambiguity right at midnight)
|
|
34
|
+
const noonUtc = new Date(Date.UTC(year, month - 1, day, 12, 0, 0));
|
|
35
|
+
// Determine what hour/minute/second UTC noon appears as in the target timezone
|
|
36
|
+
const timeParts = new Intl.DateTimeFormat('en-US', {
|
|
37
|
+
timeZone: timezone,
|
|
38
|
+
hour: '2-digit',
|
|
39
|
+
minute: '2-digit',
|
|
40
|
+
second: '2-digit',
|
|
41
|
+
hour12: false,
|
|
42
|
+
}).formatToParts(noonUtc);
|
|
43
|
+
const h = parseInt(timeParts.find(p => p.type === 'hour').value, 10);
|
|
44
|
+
const m = parseInt(timeParts.find(p => p.type === 'minute').value, 10);
|
|
45
|
+
const s = parseInt(timeParts.find(p => p.type === 'second').value, 10);
|
|
46
|
+
// UTC offset at noon = 12:00:00 UTC − local time shown for noon UTC
|
|
47
|
+
// Local midnight = noon UTC − 12h + offset = noon UTC − (h*3600+m*60+s)s
|
|
48
|
+
return noonUtc.getTime() - (h * 3600 + m * 60 + s) * 1000;
|
|
49
|
+
}
|
|
7
50
|
/**
|
|
8
51
|
* Parse an OCC-style option identifier like "AAPL 260619C00150000"
|
|
9
52
|
* into its component parts.
|
|
53
|
+
*
|
|
54
|
+
* @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
|
|
55
|
+
* If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
|
|
10
56
|
*/
|
|
11
|
-
function parseOptionIdentifier(identifier) {
|
|
57
|
+
function parseOptionIdentifier(identifier, timezone) {
|
|
12
58
|
const trimmed = identifier.trim();
|
|
13
59
|
const spaceIdx = trimmed.indexOf(' ');
|
|
14
60
|
if (spaceIdx === -1) {
|
|
@@ -25,7 +71,11 @@ function parseOptionIdentifier(identifier) {
|
|
|
25
71
|
const yy = parseInt(datePart.substring(0, 2), 10);
|
|
26
72
|
const mm = parseInt(datePart.substring(2, 4), 10);
|
|
27
73
|
const dd = parseInt(datePart.substring(4, 6), 10);
|
|
28
|
-
const
|
|
74
|
+
const resolvedTz = resolveOptionTimezone(timezone, symbol);
|
|
75
|
+
const paddedYear = String(2000 + yy).padStart(4, '0');
|
|
76
|
+
const paddedMonth = String(mm).padStart(2, '0');
|
|
77
|
+
const paddedDay = String(dd).padStart(2, '0');
|
|
78
|
+
const expiryMs = localMidnightMs(`${paddedYear}-${paddedMonth}-${paddedDay}`, resolvedTz);
|
|
29
79
|
const right = rightChar === 'C' ? 'CALL' : rightChar === 'P' ? 'PUT' : '';
|
|
30
80
|
if (!right)
|
|
31
81
|
throw new Error(`invalid right character: ${rightChar}`);
|
|
@@ -40,6 +90,10 @@ class QuoteClient {
|
|
|
40
90
|
constructor(httpClient) {
|
|
41
91
|
this.httpClient = httpClient;
|
|
42
92
|
}
|
|
93
|
+
/** Create a QuoteClient directly from a ClientConfig — no need to construct HttpClient manually. */
|
|
94
|
+
static fromConfig(config) {
|
|
95
|
+
return new QuoteClient(new http_client_1.HttpClient(config, undefined, { useQuoteServerUrl: true }));
|
|
96
|
+
}
|
|
43
97
|
async callInto(method, bizParams, version) {
|
|
44
98
|
const request = (0, api_request_1.createApiRequest)(method, bizParams, version);
|
|
45
99
|
const response = await this.httpClient.executeRequest(request);
|
|
@@ -67,12 +121,16 @@ class QuoteClient {
|
|
|
67
121
|
async getMarketState(market) {
|
|
68
122
|
return this.callInto('market_state', { market });
|
|
69
123
|
}
|
|
70
|
-
/** Real-time stock
|
|
71
|
-
async
|
|
124
|
+
/** Real-time stock quotes. wire: quote_real_time */
|
|
125
|
+
async getRealTimeQuote(req) {
|
|
72
126
|
return this.callInto('quote_real_time', req);
|
|
73
127
|
}
|
|
74
|
-
|
|
75
|
-
|
|
128
|
+
/** @deprecated Use getRealTimeQuote instead. */
|
|
129
|
+
async getBrief(req) {
|
|
130
|
+
return this.getRealTimeQuote(req);
|
|
131
|
+
}
|
|
132
|
+
async getKline(req) {
|
|
133
|
+
return this.callInto('kline', req);
|
|
76
134
|
}
|
|
77
135
|
async getTimeline(symbols) {
|
|
78
136
|
return this.callInto('timeline', { symbols });
|
|
@@ -86,30 +144,68 @@ class QuoteClient {
|
|
|
86
144
|
return this.callInto('quote_depth', req);
|
|
87
145
|
}
|
|
88
146
|
// === Options ===
|
|
89
|
-
async getOptionExpiration(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const d = new Date(expiry + 'T00:00:00Z');
|
|
95
|
-
const expiryMs = d.getTime();
|
|
96
|
-
if (Number.isNaN(expiryMs)) {
|
|
97
|
-
throw new Error(`invalid expiry date, expected YYYY-MM-DD: ${expiry}`);
|
|
98
|
-
}
|
|
99
|
-
return this.callInto('option_chain', { option_basic: [{ symbol, expiry: expiryMs }] }, '3.0');
|
|
147
|
+
async getOptionExpiration(symbols, market) {
|
|
148
|
+
const params = { symbols };
|
|
149
|
+
if (market)
|
|
150
|
+
params.market = market;
|
|
151
|
+
return this.callInto('option_expiration', params);
|
|
100
152
|
}
|
|
101
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Option chain; each item is [symbol, "YYYY-MM-DD"].
|
|
155
|
+
*
|
|
156
|
+
* @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
|
|
157
|
+
* If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
|
|
158
|
+
*/
|
|
159
|
+
async getOptionChain(items, timezone) {
|
|
160
|
+
const optionBasic = items.map(([symbol, expiry]) => {
|
|
161
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(expiry)) {
|
|
162
|
+
throw new Error(`invalid expiry date, expected YYYY-MM-DD: ${expiry}`);
|
|
163
|
+
}
|
|
164
|
+
const tz = resolveOptionTimezone(timezone, symbol);
|
|
165
|
+
const expiryMs = localMidnightMs(expiry, tz);
|
|
166
|
+
return { symbol, expiry: expiryMs };
|
|
167
|
+
});
|
|
168
|
+
return this.callInto('option_chain', { option_basic: optionBasic }, '3.0');
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Real-time option quotes by OCC-style identifier.
|
|
172
|
+
*
|
|
173
|
+
* @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
|
|
174
|
+
* If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
|
|
175
|
+
*/
|
|
176
|
+
async getOptionQuote(identifiers, timezone) {
|
|
102
177
|
const optionBasic = identifiers.map((id) => {
|
|
103
|
-
const p = parseOptionIdentifier(id);
|
|
178
|
+
const p = parseOptionIdentifier(id, timezone);
|
|
104
179
|
return { symbol: p.symbol, expiry: p.expiryMs, right: p.right, strike: p.strike };
|
|
105
180
|
});
|
|
106
181
|
return this.callInto('option_brief', { option_basic: optionBasic }, '2.0');
|
|
107
182
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return this.
|
|
111
|
-
|
|
112
|
-
|
|
183
|
+
/** @deprecated Use getOptionQuote instead. */
|
|
184
|
+
async getOptionBrief(identifiers) {
|
|
185
|
+
return this.getOptionQuote(identifiers);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Option K-line by OCC-style identifier.
|
|
189
|
+
*
|
|
190
|
+
* @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
|
|
191
|
+
* If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
|
|
192
|
+
*/
|
|
193
|
+
async getOptionKline(identifiers, period, beginTime = -1, endTime = -1, timezone) {
|
|
194
|
+
const resolvedBegin = beginTime === 0 ? -1 : beginTime;
|
|
195
|
+
const resolvedEnd = endTime === 0 ? -1 : endTime;
|
|
196
|
+
const optionQuery = identifiers.map((id) => {
|
|
197
|
+
const p = parseOptionIdentifier(id, timezone);
|
|
198
|
+
return {
|
|
199
|
+
symbol: p.symbol,
|
|
200
|
+
expiry: p.expiryMs,
|
|
201
|
+
right: p.right,
|
|
202
|
+
strike: p.strike,
|
|
203
|
+
period,
|
|
204
|
+
begin_time: resolvedBegin,
|
|
205
|
+
end_time: resolvedEnd,
|
|
206
|
+
};
|
|
207
|
+
});
|
|
208
|
+
return this.callInto('option_kline', { option_query: optionQuery }, '2.0');
|
|
113
209
|
}
|
|
114
210
|
// === Futures ===
|
|
115
211
|
async getFutureExchange() {
|
|
@@ -122,15 +218,6 @@ class QuoteClient {
|
|
|
122
218
|
async getFutureRealTimeQuote(req) {
|
|
123
219
|
return this.callInto('future_real_time_quote', req);
|
|
124
220
|
}
|
|
125
|
-
/** Futures K-line; use -1 for unbounded beginTime / endTime. */
|
|
126
|
-
async getFutureKline(req) {
|
|
127
|
-
const body = {
|
|
128
|
-
...req,
|
|
129
|
-
beginTime: req.beginTime ?? -1,
|
|
130
|
-
endTime: req.endTime ?? -1,
|
|
131
|
-
};
|
|
132
|
-
return this.callInto('future_kline', body);
|
|
133
|
-
}
|
|
134
221
|
// === Fundamentals ===
|
|
135
222
|
async getFinancialDaily(req) {
|
|
136
223
|
return this.callInto('financial_daily', req);
|
|
@@ -180,20 +267,16 @@ class QuoteClient {
|
|
|
180
267
|
async getStockDetails(req) {
|
|
181
268
|
return this.callIntoItems('stock_detail', req);
|
|
182
269
|
}
|
|
183
|
-
/** Delayed stock
|
|
184
|
-
async
|
|
270
|
+
/** Delayed stock quotes. wire: quote_delay */
|
|
271
|
+
async getDelayedQuote(req) {
|
|
185
272
|
return this.callInto('quote_delay', req);
|
|
186
273
|
}
|
|
187
|
-
/**
|
|
188
|
-
async
|
|
189
|
-
return this.
|
|
274
|
+
/** @deprecated Use getDelayedQuote instead. */
|
|
275
|
+
async getStockDelayBriefs(req) {
|
|
276
|
+
return this.getDelayedQuote(req);
|
|
190
277
|
}
|
|
191
|
-
/**
|
|
192
|
-
|
|
193
|
-
* bars are collected. Items are returned oldest-first, matching
|
|
194
|
-
* Python/Go get_bars_by_page behaviour.
|
|
195
|
-
*/
|
|
196
|
-
async getBarsByPage(req) {
|
|
278
|
+
/** Client-side paginated K-line fetch. Loops until totalSize bars are collected, oldest-first. */
|
|
279
|
+
async getKlineByPage(req) {
|
|
197
280
|
const pageSize = req.pageSize && req.pageSize > 0 ? req.pageSize : 200;
|
|
198
281
|
const totalSize = req.totalSize && req.totalSize > 0 ? req.totalSize : 1000;
|
|
199
282
|
let beginTime = req.beginTime ?? -1;
|
|
@@ -222,7 +305,6 @@ class QuoteClient {
|
|
|
222
305
|
acc.push(...items);
|
|
223
306
|
if (items.length < pageSize)
|
|
224
307
|
break;
|
|
225
|
-
// next page endTime = oldest bar time - 1
|
|
226
308
|
let oldest = items[0].time;
|
|
227
309
|
for (const it of items) {
|
|
228
310
|
if (it.time < oldest)
|
|
@@ -268,10 +350,6 @@ class QuoteClient {
|
|
|
268
350
|
// ==========================================================================
|
|
269
351
|
// Batch 4: option / future extensions
|
|
270
352
|
// ==========================================================================
|
|
271
|
-
/** Option K-line. wire: option_kline (v2.0) */
|
|
272
|
-
async getOptionBars(req) {
|
|
273
|
-
return this.callInto('option_kline', req, '2.0');
|
|
274
|
-
}
|
|
275
353
|
/** Option tick trades. wire: option_trade_tick */
|
|
276
354
|
async getOptionTradeTicks(req) {
|
|
277
355
|
return this.callInto('option_trade_tick', req);
|
|
@@ -312,11 +390,9 @@ class QuoteClient {
|
|
|
312
390
|
async getFutureHistoryMainContract(req) {
|
|
313
391
|
return this.callInto('future_main_contract', req);
|
|
314
392
|
}
|
|
315
|
-
/**
|
|
316
|
-
*
|
|
317
|
-
|
|
318
|
-
*/
|
|
319
|
-
async getFutureBars(req) {
|
|
393
|
+
/** Futures K-line. wire: future_kline
|
|
394
|
+
* beginTime / endTime default to -1 when unset (server requires them present). */
|
|
395
|
+
async getFutureKline(req) {
|
|
320
396
|
const body = {
|
|
321
397
|
...req,
|
|
322
398
|
beginTime: req.beginTime ?? -1,
|
|
@@ -325,7 +401,7 @@ class QuoteClient {
|
|
|
325
401
|
return this.callInto('future_kline', body);
|
|
326
402
|
}
|
|
327
403
|
/** Client-side paginated futures K-line fetch. */
|
|
328
|
-
async
|
|
404
|
+
async getFutureKlineByPage(req) {
|
|
329
405
|
const pageSize = req.pageSize && req.pageSize > 0 ? req.pageSize : 200;
|
|
330
406
|
const totalSize = req.totalSize && req.totalSize > 0 ? req.totalSize : 1000;
|
|
331
407
|
let beginTime = req.beginTime ?? -1;
|
|
@@ -404,10 +480,14 @@ class QuoteClient {
|
|
|
404
480
|
async getFundHistoryQuote(req) {
|
|
405
481
|
return this.callInto('fund_history_quote', req);
|
|
406
482
|
}
|
|
407
|
-
/**
|
|
408
|
-
async
|
|
483
|
+
/** Real-time warrant quotes. wire: warrant_briefs */
|
|
484
|
+
async getWarrantQuote(req) {
|
|
409
485
|
return this.callInto('warrant_briefs', req);
|
|
410
486
|
}
|
|
487
|
+
/** @deprecated Use getWarrantQuote instead. */
|
|
488
|
+
async getWarrantBriefs(req) {
|
|
489
|
+
return this.getWarrantQuote(req);
|
|
490
|
+
}
|
|
411
491
|
/** Warrant filter (paged). wire: warrant_filter */
|
|
412
492
|
async getWarrantFilter(req) {
|
|
413
493
|
return this.callInto('warrant_filter', req);
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TradeClient = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* TradeClient — trading client.
|
|
6
|
+
*
|
|
7
|
+
* All methods return strongly-typed responses; request parameters are
|
|
8
|
+
* written in camelCase in TypeScript and converted to snake_case on the wire.
|
|
9
|
+
*
|
|
10
|
+
* v0.4.0: 所有查询类方法改为 Request 对象签名(OrdersRequest 等),补齐 17
|
|
11
|
+
* 个新方法(账户管理 / 资产分析 / 资金调拨 / 持仓划转等)。
|
|
12
|
+
*/
|
|
13
|
+
const http_client_1 = require("../client/http-client");
|
|
4
14
|
const api_request_1 = require("../client/api-request");
|
|
5
15
|
const api_response_1 = require("../client/api-response");
|
|
6
16
|
const order_status_1 = require("../model/order-status");
|
|
@@ -30,6 +40,10 @@ class TradeClient {
|
|
|
30
40
|
this.account = account;
|
|
31
41
|
this.secretKey = secretKey;
|
|
32
42
|
}
|
|
43
|
+
/** Create a TradeClient directly from a ClientConfig — no need to construct HttpClient manually. */
|
|
44
|
+
static fromConfig(config, account, secretKey) {
|
|
45
|
+
return new TradeClient(new http_client_1.HttpClient(config), account, secretKey);
|
|
46
|
+
}
|
|
33
47
|
async callInto(method, bizParams) {
|
|
34
48
|
const request = (0, api_request_1.createApiRequest)(method, bizParams);
|
|
35
49
|
const response = await this.httpClient.executeRequest(request);
|
|
@@ -4,8 +4,7 @@ import { signWithRSA, verifyWithRSA } from '../signer/signer.js';
|
|
|
4
4
|
import { TigerError } from './errors.js';
|
|
5
5
|
import { defaultRetryPolicy } from './retry.js';
|
|
6
6
|
import { parseApiResponse, unmarshalData } from './api-response.js';
|
|
7
|
-
|
|
8
|
-
const SDK_VERSION = '0.4.0';
|
|
7
|
+
import { SDK_VERSION } from '../version.js';
|
|
9
8
|
/** User-Agent 字符串 */
|
|
10
9
|
const USER_AGENT = `openapi-typescript-sdk-${SDK_VERSION}`;
|
|
11
10
|
/** 默认字符集 */
|
package/dist/esm/index.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* @packageDocumentation
|
|
16
16
|
*/
|
|
17
17
|
/** SDK 版本号 */
|
|
18
|
-
export
|
|
18
|
+
export { SDK_VERSION as VERSION } from './version.js';
|
|
19
19
|
// Config
|
|
20
20
|
export { createClientConfig, loadPropertiesFile } from './config/index.js';
|
|
21
21
|
export { TokenManager } from './config/index.js';
|
|
@@ -28,8 +28,9 @@ const DEFAULT_RECONNECT_INTERVAL = 5000;
|
|
|
28
28
|
const MAX_RECONNECT_INTERVAL = 60000;
|
|
29
29
|
/** Default connect timeout (ms) */
|
|
30
30
|
const DEFAULT_CONNECT_TIMEOUT = 30000;
|
|
31
|
+
import { SDK_VERSION as _SDK_VERSION } from '../version.js';
|
|
31
32
|
/** SDK version identifier */
|
|
32
|
-
const SDK_VERSION =
|
|
33
|
+
const SDK_VERSION = `typescript/${_SDK_VERSION}`;
|
|
33
34
|
/** Protocol version */
|
|
34
35
|
const ACCEPT_VERSION = '1.0';
|
|
35
36
|
/** Default send heartbeat interval (ms) */
|
|
@@ -1,10 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QuoteClient — market-data client.
|
|
3
|
+
*
|
|
4
|
+
* All methods return strongly-typed responses from the `model` package.
|
|
5
|
+
* Request parameters are written in camelCase in TypeScript and are
|
|
6
|
+
* converted to snake_case on the wire automatically.
|
|
7
|
+
*/
|
|
8
|
+
import { HttpClient } from '../client/http-client.js';
|
|
1
9
|
import { createApiRequest } from '../client/api-request.js';
|
|
2
10
|
import { unmarshalData } from '../client/api-response.js';
|
|
11
|
+
/**
|
|
12
|
+
* resolveOptionTimezone returns the timezone string to use for expiry conversion.
|
|
13
|
+
* Explicit tz takes precedence; otherwise infer from symbol (.HK suffix → Asia/Hong_Kong, else America/New_York).
|
|
14
|
+
*/
|
|
15
|
+
function resolveOptionTimezone(tz, symbol) {
|
|
16
|
+
if (tz)
|
|
17
|
+
return tz;
|
|
18
|
+
return symbol.toUpperCase().endsWith('.HK') ? 'Asia/Hong_Kong' : 'America/New_York';
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Convert a "YYYY-MM-DD" date string to the Unix timestamp (ms) of local midnight
|
|
22
|
+
* in the given IANA timezone.
|
|
23
|
+
*
|
|
24
|
+
* Strategy: use Intl.DateTimeFormat to determine what UTC time corresponds to
|
|
25
|
+
* local midnight in the target timezone, correctly handling DST.
|
|
26
|
+
*/
|
|
27
|
+
function localMidnightMs(dateStr, timezone) {
|
|
28
|
+
const [year, month, day] = dateStr.split('-').map(Number);
|
|
29
|
+
// Use noon UTC as a safe anchor (avoids DST ambiguity right at midnight)
|
|
30
|
+
const noonUtc = new Date(Date.UTC(year, month - 1, day, 12, 0, 0));
|
|
31
|
+
// Determine what hour/minute/second UTC noon appears as in the target timezone
|
|
32
|
+
const timeParts = new Intl.DateTimeFormat('en-US', {
|
|
33
|
+
timeZone: timezone,
|
|
34
|
+
hour: '2-digit',
|
|
35
|
+
minute: '2-digit',
|
|
36
|
+
second: '2-digit',
|
|
37
|
+
hour12: false,
|
|
38
|
+
}).formatToParts(noonUtc);
|
|
39
|
+
const h = parseInt(timeParts.find(p => p.type === 'hour').value, 10);
|
|
40
|
+
const m = parseInt(timeParts.find(p => p.type === 'minute').value, 10);
|
|
41
|
+
const s = parseInt(timeParts.find(p => p.type === 'second').value, 10);
|
|
42
|
+
// UTC offset at noon = 12:00:00 UTC − local time shown for noon UTC
|
|
43
|
+
// Local midnight = noon UTC − 12h + offset = noon UTC − (h*3600+m*60+s)s
|
|
44
|
+
return noonUtc.getTime() - (h * 3600 + m * 60 + s) * 1000;
|
|
45
|
+
}
|
|
3
46
|
/**
|
|
4
47
|
* Parse an OCC-style option identifier like "AAPL 260619C00150000"
|
|
5
48
|
* into its component parts.
|
|
49
|
+
*
|
|
50
|
+
* @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
|
|
51
|
+
* If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
|
|
6
52
|
*/
|
|
7
|
-
export function parseOptionIdentifier(identifier) {
|
|
53
|
+
export function parseOptionIdentifier(identifier, timezone) {
|
|
8
54
|
const trimmed = identifier.trim();
|
|
9
55
|
const spaceIdx = trimmed.indexOf(' ');
|
|
10
56
|
if (spaceIdx === -1) {
|
|
@@ -21,7 +67,11 @@ export function parseOptionIdentifier(identifier) {
|
|
|
21
67
|
const yy = parseInt(datePart.substring(0, 2), 10);
|
|
22
68
|
const mm = parseInt(datePart.substring(2, 4), 10);
|
|
23
69
|
const dd = parseInt(datePart.substring(4, 6), 10);
|
|
24
|
-
const
|
|
70
|
+
const resolvedTz = resolveOptionTimezone(timezone, symbol);
|
|
71
|
+
const paddedYear = String(2000 + yy).padStart(4, '0');
|
|
72
|
+
const paddedMonth = String(mm).padStart(2, '0');
|
|
73
|
+
const paddedDay = String(dd).padStart(2, '0');
|
|
74
|
+
const expiryMs = localMidnightMs(`${paddedYear}-${paddedMonth}-${paddedDay}`, resolvedTz);
|
|
25
75
|
const right = rightChar === 'C' ? 'CALL' : rightChar === 'P' ? 'PUT' : '';
|
|
26
76
|
if (!right)
|
|
27
77
|
throw new Error(`invalid right character: ${rightChar}`);
|
|
@@ -36,6 +86,10 @@ export class QuoteClient {
|
|
|
36
86
|
constructor(httpClient) {
|
|
37
87
|
this.httpClient = httpClient;
|
|
38
88
|
}
|
|
89
|
+
/** Create a QuoteClient directly from a ClientConfig — no need to construct HttpClient manually. */
|
|
90
|
+
static fromConfig(config) {
|
|
91
|
+
return new QuoteClient(new HttpClient(config, undefined, { useQuoteServerUrl: true }));
|
|
92
|
+
}
|
|
39
93
|
async callInto(method, bizParams, version) {
|
|
40
94
|
const request = createApiRequest(method, bizParams, version);
|
|
41
95
|
const response = await this.httpClient.executeRequest(request);
|
|
@@ -63,12 +117,16 @@ export class QuoteClient {
|
|
|
63
117
|
async getMarketState(market) {
|
|
64
118
|
return this.callInto('market_state', { market });
|
|
65
119
|
}
|
|
66
|
-
/** Real-time stock
|
|
67
|
-
async
|
|
120
|
+
/** Real-time stock quotes. wire: quote_real_time */
|
|
121
|
+
async getRealTimeQuote(req) {
|
|
68
122
|
return this.callInto('quote_real_time', req);
|
|
69
123
|
}
|
|
70
|
-
|
|
71
|
-
|
|
124
|
+
/** @deprecated Use getRealTimeQuote instead. */
|
|
125
|
+
async getBrief(req) {
|
|
126
|
+
return this.getRealTimeQuote(req);
|
|
127
|
+
}
|
|
128
|
+
async getKline(req) {
|
|
129
|
+
return this.callInto('kline', req);
|
|
72
130
|
}
|
|
73
131
|
async getTimeline(symbols) {
|
|
74
132
|
return this.callInto('timeline', { symbols });
|
|
@@ -82,30 +140,68 @@ export class QuoteClient {
|
|
|
82
140
|
return this.callInto('quote_depth', req);
|
|
83
141
|
}
|
|
84
142
|
// === Options ===
|
|
85
|
-
async getOptionExpiration(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const d = new Date(expiry + 'T00:00:00Z');
|
|
91
|
-
const expiryMs = d.getTime();
|
|
92
|
-
if (Number.isNaN(expiryMs)) {
|
|
93
|
-
throw new Error(`invalid expiry date, expected YYYY-MM-DD: ${expiry}`);
|
|
94
|
-
}
|
|
95
|
-
return this.callInto('option_chain', { option_basic: [{ symbol, expiry: expiryMs }] }, '3.0');
|
|
143
|
+
async getOptionExpiration(symbols, market) {
|
|
144
|
+
const params = { symbols };
|
|
145
|
+
if (market)
|
|
146
|
+
params.market = market;
|
|
147
|
+
return this.callInto('option_expiration', params);
|
|
96
148
|
}
|
|
97
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Option chain; each item is [symbol, "YYYY-MM-DD"].
|
|
151
|
+
*
|
|
152
|
+
* @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
|
|
153
|
+
* If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
|
|
154
|
+
*/
|
|
155
|
+
async getOptionChain(items, timezone) {
|
|
156
|
+
const optionBasic = items.map(([symbol, expiry]) => {
|
|
157
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(expiry)) {
|
|
158
|
+
throw new Error(`invalid expiry date, expected YYYY-MM-DD: ${expiry}`);
|
|
159
|
+
}
|
|
160
|
+
const tz = resolveOptionTimezone(timezone, symbol);
|
|
161
|
+
const expiryMs = localMidnightMs(expiry, tz);
|
|
162
|
+
return { symbol, expiry: expiryMs };
|
|
163
|
+
});
|
|
164
|
+
return this.callInto('option_chain', { option_basic: optionBasic }, '3.0');
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Real-time option quotes by OCC-style identifier.
|
|
168
|
+
*
|
|
169
|
+
* @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
|
|
170
|
+
* If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
|
|
171
|
+
*/
|
|
172
|
+
async getOptionQuote(identifiers, timezone) {
|
|
98
173
|
const optionBasic = identifiers.map((id) => {
|
|
99
|
-
const p = parseOptionIdentifier(id);
|
|
174
|
+
const p = parseOptionIdentifier(id, timezone);
|
|
100
175
|
return { symbol: p.symbol, expiry: p.expiryMs, right: p.right, strike: p.strike };
|
|
101
176
|
});
|
|
102
177
|
return this.callInto('option_brief', { option_basic: optionBasic }, '2.0');
|
|
103
178
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return this.
|
|
107
|
-
|
|
108
|
-
|
|
179
|
+
/** @deprecated Use getOptionQuote instead. */
|
|
180
|
+
async getOptionBrief(identifiers) {
|
|
181
|
+
return this.getOptionQuote(identifiers);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Option K-line by OCC-style identifier.
|
|
185
|
+
*
|
|
186
|
+
* @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
|
|
187
|
+
* If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
|
|
188
|
+
*/
|
|
189
|
+
async getOptionKline(identifiers, period, beginTime = -1, endTime = -1, timezone) {
|
|
190
|
+
const resolvedBegin = beginTime === 0 ? -1 : beginTime;
|
|
191
|
+
const resolvedEnd = endTime === 0 ? -1 : endTime;
|
|
192
|
+
const optionQuery = identifiers.map((id) => {
|
|
193
|
+
const p = parseOptionIdentifier(id, timezone);
|
|
194
|
+
return {
|
|
195
|
+
symbol: p.symbol,
|
|
196
|
+
expiry: p.expiryMs,
|
|
197
|
+
right: p.right,
|
|
198
|
+
strike: p.strike,
|
|
199
|
+
period,
|
|
200
|
+
begin_time: resolvedBegin,
|
|
201
|
+
end_time: resolvedEnd,
|
|
202
|
+
};
|
|
203
|
+
});
|
|
204
|
+
return this.callInto('option_kline', { option_query: optionQuery }, '2.0');
|
|
109
205
|
}
|
|
110
206
|
// === Futures ===
|
|
111
207
|
async getFutureExchange() {
|
|
@@ -118,15 +214,6 @@ export class QuoteClient {
|
|
|
118
214
|
async getFutureRealTimeQuote(req) {
|
|
119
215
|
return this.callInto('future_real_time_quote', req);
|
|
120
216
|
}
|
|
121
|
-
/** Futures K-line; use -1 for unbounded beginTime / endTime. */
|
|
122
|
-
async getFutureKline(req) {
|
|
123
|
-
const body = {
|
|
124
|
-
...req,
|
|
125
|
-
beginTime: req.beginTime ?? -1,
|
|
126
|
-
endTime: req.endTime ?? -1,
|
|
127
|
-
};
|
|
128
|
-
return this.callInto('future_kline', body);
|
|
129
|
-
}
|
|
130
217
|
// === Fundamentals ===
|
|
131
218
|
async getFinancialDaily(req) {
|
|
132
219
|
return this.callInto('financial_daily', req);
|
|
@@ -176,20 +263,16 @@ export class QuoteClient {
|
|
|
176
263
|
async getStockDetails(req) {
|
|
177
264
|
return this.callIntoItems('stock_detail', req);
|
|
178
265
|
}
|
|
179
|
-
/** Delayed stock
|
|
180
|
-
async
|
|
266
|
+
/** Delayed stock quotes. wire: quote_delay */
|
|
267
|
+
async getDelayedQuote(req) {
|
|
181
268
|
return this.callInto('quote_delay', req);
|
|
182
269
|
}
|
|
183
|
-
/**
|
|
184
|
-
async
|
|
185
|
-
return this.
|
|
270
|
+
/** @deprecated Use getDelayedQuote instead. */
|
|
271
|
+
async getStockDelayBriefs(req) {
|
|
272
|
+
return this.getDelayedQuote(req);
|
|
186
273
|
}
|
|
187
|
-
/**
|
|
188
|
-
|
|
189
|
-
* bars are collected. Items are returned oldest-first, matching
|
|
190
|
-
* Python/Go get_bars_by_page behaviour.
|
|
191
|
-
*/
|
|
192
|
-
async getBarsByPage(req) {
|
|
274
|
+
/** Client-side paginated K-line fetch. Loops until totalSize bars are collected, oldest-first. */
|
|
275
|
+
async getKlineByPage(req) {
|
|
193
276
|
const pageSize = req.pageSize && req.pageSize > 0 ? req.pageSize : 200;
|
|
194
277
|
const totalSize = req.totalSize && req.totalSize > 0 ? req.totalSize : 1000;
|
|
195
278
|
let beginTime = req.beginTime ?? -1;
|
|
@@ -218,7 +301,6 @@ export class QuoteClient {
|
|
|
218
301
|
acc.push(...items);
|
|
219
302
|
if (items.length < pageSize)
|
|
220
303
|
break;
|
|
221
|
-
// next page endTime = oldest bar time - 1
|
|
222
304
|
let oldest = items[0].time;
|
|
223
305
|
for (const it of items) {
|
|
224
306
|
if (it.time < oldest)
|
|
@@ -264,10 +346,6 @@ export class QuoteClient {
|
|
|
264
346
|
// ==========================================================================
|
|
265
347
|
// Batch 4: option / future extensions
|
|
266
348
|
// ==========================================================================
|
|
267
|
-
/** Option K-line. wire: option_kline (v2.0) */
|
|
268
|
-
async getOptionBars(req) {
|
|
269
|
-
return this.callInto('option_kline', req, '2.0');
|
|
270
|
-
}
|
|
271
349
|
/** Option tick trades. wire: option_trade_tick */
|
|
272
350
|
async getOptionTradeTicks(req) {
|
|
273
351
|
return this.callInto('option_trade_tick', req);
|
|
@@ -308,11 +386,9 @@ export class QuoteClient {
|
|
|
308
386
|
async getFutureHistoryMainContract(req) {
|
|
309
387
|
return this.callInto('future_main_contract', req);
|
|
310
388
|
}
|
|
311
|
-
/**
|
|
312
|
-
*
|
|
313
|
-
|
|
314
|
-
*/
|
|
315
|
-
async getFutureBars(req) {
|
|
389
|
+
/** Futures K-line. wire: future_kline
|
|
390
|
+
* beginTime / endTime default to -1 when unset (server requires them present). */
|
|
391
|
+
async getFutureKline(req) {
|
|
316
392
|
const body = {
|
|
317
393
|
...req,
|
|
318
394
|
beginTime: req.beginTime ?? -1,
|
|
@@ -321,7 +397,7 @@ export class QuoteClient {
|
|
|
321
397
|
return this.callInto('future_kline', body);
|
|
322
398
|
}
|
|
323
399
|
/** Client-side paginated futures K-line fetch. */
|
|
324
|
-
async
|
|
400
|
+
async getFutureKlineByPage(req) {
|
|
325
401
|
const pageSize = req.pageSize && req.pageSize > 0 ? req.pageSize : 200;
|
|
326
402
|
const totalSize = req.totalSize && req.totalSize > 0 ? req.totalSize : 1000;
|
|
327
403
|
let beginTime = req.beginTime ?? -1;
|
|
@@ -400,10 +476,14 @@ export class QuoteClient {
|
|
|
400
476
|
async getFundHistoryQuote(req) {
|
|
401
477
|
return this.callInto('fund_history_quote', req);
|
|
402
478
|
}
|
|
403
|
-
/**
|
|
404
|
-
async
|
|
479
|
+
/** Real-time warrant quotes. wire: warrant_briefs */
|
|
480
|
+
async getWarrantQuote(req) {
|
|
405
481
|
return this.callInto('warrant_briefs', req);
|
|
406
482
|
}
|
|
483
|
+
/** @deprecated Use getWarrantQuote instead. */
|
|
484
|
+
async getWarrantBriefs(req) {
|
|
485
|
+
return this.getWarrantQuote(req);
|
|
486
|
+
}
|
|
407
487
|
/** Warrant filter (paged). wire: warrant_filter */
|
|
408
488
|
async getWarrantFilter(req) {
|
|
409
489
|
return this.callInto('warrant_filter', req);
|
|
@@ -1,3 +1,13 @@
|
|
|
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';
|
|
1
11
|
import { createApiRequest } from '../client/api-request.js';
|
|
2
12
|
import { unmarshalData } from '../client/api-response.js';
|
|
3
13
|
import { normalizeOrderStatus } from '../model/order-status.js';
|
|
@@ -27,6 +37,10 @@ export class TradeClient {
|
|
|
27
37
|
this.account = account;
|
|
28
38
|
this.secretKey = secretKey;
|
|
29
39
|
}
|
|
40
|
+
/** Create a TradeClient directly from a ClientConfig — no need to construct HttpClient manually. */
|
|
41
|
+
static fromConfig(config, account, secretKey) {
|
|
42
|
+
return new TradeClient(new HttpClient(config), account, secretKey);
|
|
43
|
+
}
|
|
30
44
|
async callInto(method, bizParams) {
|
|
31
45
|
const request = createApiRequest(method, bizParams);
|
|
32
46
|
const response = await this.httpClient.executeRequest(request);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SDK_VERSION = '0.4.8';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* @packageDocumentation
|
|
16
16
|
*/
|
|
17
17
|
/** SDK 版本号 */
|
|
18
|
-
export
|
|
18
|
+
export { SDK_VERSION as VERSION } from './version';
|
|
19
19
|
export { createClientConfig, loadPropertiesFile } from './config';
|
|
20
20
|
export type { ClientConfig, ClientConfigOptions } from './config';
|
|
21
21
|
export { TokenManager } from './config';
|
|
@@ -35,5 +35,5 @@ export type { Position } from './model/position';
|
|
|
35
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
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
37
|
export type { MarketState, Brief, Kline, KlineItem, Timeline, TimelineItem, TradeTick, TradeTickItem, Depth, DepthLevel, OptionExpiration, OptionChain, OptionChainRow, OptionSymbol, FutureExchange, FutureContractInfo, FutureQuote, FutureKline, FutureKlineItem, FutureDepth, FutureTradeTickItem, FutureTradingTime, FinancialDailyItem, FinancialReportItem, CorporateAction, 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,
|
|
38
|
+
export type { BriefRequest, DepthQuoteRequest, TradeTickRequest, KlineRequest, KlineByPageRequest, 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
39
|
export { OrderStatus, SecurityType, OrderType, TimeInForce, Market, Currency, QuoteRight, SegmentType, OrderSortBy, CorporateActionType, IndustryLevel, SortDirection, OptionAnalysisPeriod, FinancialReportPeriod, Language, License, BarPeriod, orderStatusCode, } from './model/enums';
|
|
@@ -58,11 +58,10 @@ export interface StockDelayBriefsRequest {
|
|
|
58
58
|
secType?: string;
|
|
59
59
|
lang?: string;
|
|
60
60
|
}
|
|
61
|
-
/**
|
|
62
|
-
* K-line bars (full options). wire: kline
|
|
61
|
+
/** K-line request. wire: kline
|
|
63
62
|
* BeginTime/EndTime (ms) and BeginIndex/EndIndex are mutually exclusive.
|
|
64
63
|
*/
|
|
65
|
-
export interface
|
|
64
|
+
export interface KlineRequest {
|
|
66
65
|
symbols?: string[];
|
|
67
66
|
period?: string;
|
|
68
67
|
right?: string;
|
|
@@ -79,7 +78,7 @@ export interface BarsRequest {
|
|
|
79
78
|
lang?: string;
|
|
80
79
|
}
|
|
81
80
|
/** K-line client-side pagination wrapper. */
|
|
82
|
-
export interface
|
|
81
|
+
export interface KlineByPageRequest {
|
|
83
82
|
symbol?: string;
|
|
84
83
|
period?: string;
|
|
85
84
|
beginTime?: number;
|
|
@@ -155,12 +154,6 @@ export interface OptionQueryItem {
|
|
|
155
154
|
endIndex?: number;
|
|
156
155
|
pageToken?: string;
|
|
157
156
|
}
|
|
158
|
-
/** Option K-line. wire: option_kline (v2.0) */
|
|
159
|
-
export interface OptionBarsRequest {
|
|
160
|
-
optionQuery?: OptionQueryItem[];
|
|
161
|
-
market?: string;
|
|
162
|
-
lang?: string;
|
|
163
|
-
}
|
|
164
157
|
/** Option tick trades. wire: option_trade_tick */
|
|
165
158
|
export interface OptionTradeTicksRequest {
|
|
166
159
|
contracts?: OptionQueryItem[];
|
|
@@ -215,8 +208,8 @@ export interface FutureHistoryMainContractRequest {
|
|
|
215
208
|
endTime?: number;
|
|
216
209
|
lang?: string;
|
|
217
210
|
}
|
|
218
|
-
/** Futures K-line
|
|
219
|
-
export interface
|
|
211
|
+
/** Futures K-line request. wire: future_kline */
|
|
212
|
+
export interface FutureKlineRequest {
|
|
220
213
|
contractCodes?: string[];
|
|
221
214
|
contractCode?: string;
|
|
222
215
|
period?: string;
|
|
@@ -229,7 +222,7 @@ export interface FutureBarsRequest {
|
|
|
229
222
|
lang?: string;
|
|
230
223
|
}
|
|
231
224
|
/** Futures K-line client-side pagination wrapper. */
|
|
232
|
-
export interface
|
|
225
|
+
export interface FutureKlineByPageRequest {
|
|
233
226
|
contractCode?: string;
|
|
234
227
|
period?: string;
|
|
235
228
|
beginTime?: number;
|
|
@@ -5,14 +5,18 @@
|
|
|
5
5
|
* Request parameters are written in camelCase in TypeScript and are
|
|
6
6
|
* converted to snake_case on the wire automatically.
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
8
|
+
import { HttpClient } from '../client/http-client';
|
|
9
|
+
import type { ClientConfig } from '../config/client-config';
|
|
10
|
+
import type { MarketState, Brief, Kline, KlineItem, Timeline, TradeTick, Depth, OptionExpiration, OptionChain, FutureExchange, FutureContractInfo, FutureQuote, FutureKline, FutureKlineItem, FinancialDailyItem, FinancialReportItem, CorporateAction, CapitalFlow, CapitalDistribution, ScannerResult, QuotePermission, MarketScannerRequest, SymbolName, TradeMeta, StockDetail, StockBroker, StockIndustry, TradeRankItem, ShortInterest, KlineQuota, OptionAnalysis, OptionSymbol, FutureMainContractHistory, FutureTradingTime, FutureTradeTickItem, FutureDepth, WarrantBrief, WarrantFilterResult, IndustryItem, IndustryStock, TradingCalendarItem, ExchangeRate, FinancialCurrency, QuoteOvernight, MarketScannerTags, FundContractInfo, FundQuote, FundHistoryQuote, FinancialDailyRequest, FinancialReportRequest, CorporateActionRequest } from '../model/quote';
|
|
11
|
+
import type { BriefRequest, DepthQuoteRequest, TradeTickRequest, FutureBriefRequest, SymbolsRequest, TradeMetasRequest, StockDetailsRequest, StockDelayBriefsRequest, KlineRequest, KlineByPageRequest, TimelineHistoryRequest, TradeRankRequest, ShortInterestRequest, StockBrokerRequest, StockFundamentalRequest, StockIndustryRequest, KlineQuotaRequest, QuotePermissionRequest, OptionTradeTicksRequest, OptionTimelineRequest, OptionDepthRequest, OptionSymbolsRequest, OptionAnalysisRequest, FutureContractSingleRequest, AllFutureContractsRequest, FutureContinuousContractsRequest, FutureHistoryMainContractRequest, FutureKlineRequest, FutureKlineByPageRequest, FutureTradeTicksRequest, FutureDepthRequest, FutureTradingTimesRequest, FundSymbolsRequest, FundContractsRequest, FundQuoteRequest, FundHistoryQuoteRequest, WarrantBriefsRequest, WarrantFilterRequest, IndustryListRequest, IndustryStocksRequest, TradingCalendarRequest, FinancialExchangeRateRequest, FinancialCurrencyRequest, MarketScannerTagsRequest, QuoteOvernightRequest } from '../model/quote-requests';
|
|
11
12
|
/**
|
|
12
13
|
* Parse an OCC-style option identifier like "AAPL 260619C00150000"
|
|
13
14
|
* into its component parts.
|
|
15
|
+
*
|
|
16
|
+
* @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
|
|
17
|
+
* If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
|
|
14
18
|
*/
|
|
15
|
-
export declare function parseOptionIdentifier(identifier: string): {
|
|
19
|
+
export declare function parseOptionIdentifier(identifier: string, timezone?: string): {
|
|
16
20
|
symbol: string;
|
|
17
21
|
expiryMs: number;
|
|
18
22
|
right: string;
|
|
@@ -22,6 +26,8 @@ export declare function parseOptionIdentifier(identifier: string): {
|
|
|
22
26
|
export declare class QuoteClient {
|
|
23
27
|
private httpClient;
|
|
24
28
|
constructor(httpClient: HttpClient);
|
|
29
|
+
/** Create a QuoteClient directly from a ClientConfig — no need to construct HttpClient manually. */
|
|
30
|
+
static fromConfig(config: ClientConfig): QuoteClient;
|
|
25
31
|
private callInto;
|
|
26
32
|
/**
|
|
27
33
|
* Some endpoints return either a list or a single object depending on the
|
|
@@ -32,25 +38,44 @@ export declare class QuoteClient {
|
|
|
32
38
|
/** Unwrap server {"items":[...]} envelope. */
|
|
33
39
|
private callIntoItems;
|
|
34
40
|
getMarketState(market: string): Promise<MarketState[]>;
|
|
35
|
-
/** Real-time stock
|
|
41
|
+
/** Real-time stock quotes. wire: quote_real_time */
|
|
42
|
+
getRealTimeQuote(req: BriefRequest): Promise<Brief[]>;
|
|
43
|
+
/** @deprecated Use getRealTimeQuote instead. */
|
|
36
44
|
getBrief(req: BriefRequest): Promise<Brief[]>;
|
|
37
|
-
getKline(
|
|
45
|
+
getKline(req: KlineRequest): Promise<Kline[]>;
|
|
38
46
|
getTimeline(symbols: string[]): Promise<Timeline[]>;
|
|
39
47
|
/** Tick-by-tick trades. wire: trade_tick */
|
|
40
48
|
getTradeTick(req: TradeTickRequest): Promise<TradeTick[]>;
|
|
41
49
|
/** Depth snapshot. wire: quote_depth */
|
|
42
50
|
getQuoteDepth(req: DepthQuoteRequest): Promise<Depth[]>;
|
|
43
|
-
getOptionExpiration(
|
|
44
|
-
/**
|
|
45
|
-
|
|
51
|
+
getOptionExpiration(symbols: string[], market?: string): Promise<OptionExpiration[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Option chain; each item is [symbol, "YYYY-MM-DD"].
|
|
54
|
+
*
|
|
55
|
+
* @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
|
|
56
|
+
* If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
|
|
57
|
+
*/
|
|
58
|
+
getOptionChain(items: Array<[string, string]>, timezone?: string): Promise<OptionChain[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Real-time option quotes by OCC-style identifier.
|
|
61
|
+
*
|
|
62
|
+
* @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
|
|
63
|
+
* If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
|
|
64
|
+
*/
|
|
65
|
+
getOptionQuote(identifiers: string[], timezone?: string): Promise<Brief[]>;
|
|
66
|
+
/** @deprecated Use getOptionQuote instead. */
|
|
46
67
|
getOptionBrief(identifiers: string[]): Promise<Brief[]>;
|
|
47
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Option K-line by OCC-style identifier.
|
|
70
|
+
*
|
|
71
|
+
* @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
|
|
72
|
+
* If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
|
|
73
|
+
*/
|
|
74
|
+
getOptionKline(identifiers: string[], period: string, beginTime?: number, endTime?: number, timezone?: string): Promise<Kline[]>;
|
|
48
75
|
getFutureExchange(): Promise<FutureExchange[]>;
|
|
49
76
|
getFutureContracts(exchange: string): Promise<FutureContractInfo[]>;
|
|
50
77
|
/** Real-time futures quotes. wire: future_real_time_quote */
|
|
51
78
|
getFutureRealTimeQuote(req: FutureBriefRequest): Promise<FutureQuote[]>;
|
|
52
|
-
/** Futures K-line; use -1 for unbounded beginTime / endTime. */
|
|
53
|
-
getFutureKline(req: FutureKlineRequest): Promise<FutureKline[]>;
|
|
54
79
|
getFinancialDaily(req: FinancialDailyRequest): Promise<FinancialDailyItem[]>;
|
|
55
80
|
getFinancialReport(req: FinancialReportRequest): Promise<FinancialReportItem[]>;
|
|
56
81
|
/**
|
|
@@ -69,16 +94,12 @@ export declare class QuoteClient {
|
|
|
69
94
|
getTradeMetas(req: TradeMetasRequest): Promise<TradeMeta[]>;
|
|
70
95
|
/** Stock details. wire: stock_detail. Server returns {items:[...]}. */
|
|
71
96
|
getStockDetails(req: StockDetailsRequest): Promise<StockDetail[]>;
|
|
72
|
-
/** Delayed stock
|
|
97
|
+
/** Delayed stock quotes. wire: quote_delay */
|
|
98
|
+
getDelayedQuote(req: StockDelayBriefsRequest): Promise<Brief[]>;
|
|
99
|
+
/** @deprecated Use getDelayedQuote instead. */
|
|
73
100
|
getStockDelayBriefs(req: StockDelayBriefsRequest): Promise<Brief[]>;
|
|
74
|
-
/** K-line bars
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Client-side paginated K-line fetch — loops over getBars until TotalSize
|
|
78
|
-
* bars are collected. Items are returned oldest-first, matching
|
|
79
|
-
* Python/Go get_bars_by_page behaviour.
|
|
80
|
-
*/
|
|
81
|
-
getBarsByPage(req: BarsByPageRequest): Promise<KlineItem[]>;
|
|
101
|
+
/** Client-side paginated K-line fetch. Loops until totalSize bars are collected, oldest-first. */
|
|
102
|
+
getKlineByPage(req: KlineByPageRequest): Promise<KlineItem[]>;
|
|
82
103
|
/** Historical intraday timeline. wire: history_timeline */
|
|
83
104
|
getTimelineHistory(req: TimelineHistoryRequest): Promise<Timeline[]>;
|
|
84
105
|
/** Trade rank (top movers / volume). wire: trade_rank */
|
|
@@ -95,8 +116,6 @@ export declare class QuoteClient {
|
|
|
95
116
|
getQuotePermission(req: QuotePermissionRequest): Promise<QuotePermission[]>;
|
|
96
117
|
/** K-line quota usage. wire: kline_quota */
|
|
97
118
|
getKlineQuota(req: KlineQuotaRequest): Promise<KlineQuota[]>;
|
|
98
|
-
/** Option K-line. wire: option_kline (v2.0) */
|
|
99
|
-
getOptionBars(req: OptionBarsRequest): Promise<Kline[]>;
|
|
100
119
|
/** Option tick trades. wire: option_trade_tick */
|
|
101
120
|
getOptionTradeTicks(req: OptionTradeTicksRequest): Promise<TradeTick[]>;
|
|
102
121
|
/** Option intraday timeline. wire: option_timeline */
|
|
@@ -117,13 +136,11 @@ export declare class QuoteClient {
|
|
|
117
136
|
getFutureContinuousContracts(req: FutureContinuousContractsRequest): Promise<FutureContractInfo[]>;
|
|
118
137
|
/** Historical main contracts. wire: future_main_contract */
|
|
119
138
|
getFutureHistoryMainContract(req: FutureHistoryMainContractRequest): Promise<FutureMainContractHistory[]>;
|
|
120
|
-
/**
|
|
121
|
-
*
|
|
122
|
-
|
|
123
|
-
*/
|
|
124
|
-
getFutureBars(req: FutureBarsRequest): Promise<FutureKline[]>;
|
|
139
|
+
/** Futures K-line. wire: future_kline
|
|
140
|
+
* beginTime / endTime default to -1 when unset (server requires them present). */
|
|
141
|
+
getFutureKline(req: FutureKlineRequest): Promise<FutureKline[]>;
|
|
125
142
|
/** Client-side paginated futures K-line fetch. */
|
|
126
|
-
|
|
143
|
+
getFutureKlineByPage(req: FutureKlineByPageRequest): Promise<FutureKlineItem[]>;
|
|
127
144
|
/** Futures tick trades. wire: future_tick (API v3.0)
|
|
128
145
|
* Server returns {contractCode, items:[...]}; unwrap items and backfill contractCode.
|
|
129
146
|
* endIndex defaults to 30 when not set (consistent with Python/Go SDK). */
|
|
@@ -140,7 +157,9 @@ export declare class QuoteClient {
|
|
|
140
157
|
getFundQuote(req: FundQuoteRequest): Promise<FundQuote[]>;
|
|
141
158
|
/** Fund historical NAV. wire: fund_history_quote */
|
|
142
159
|
getFundHistoryQuote(req: FundHistoryQuoteRequest): Promise<FundHistoryQuote[]>;
|
|
143
|
-
/**
|
|
160
|
+
/** Real-time warrant quotes. wire: warrant_briefs */
|
|
161
|
+
getWarrantQuote(req: WarrantBriefsRequest): Promise<WarrantBrief[]>;
|
|
162
|
+
/** @deprecated Use getWarrantQuote instead. */
|
|
144
163
|
getWarrantBriefs(req: WarrantBriefsRequest): Promise<WarrantBrief[]>;
|
|
145
164
|
/** Warrant filter (paged). wire: warrant_filter */
|
|
146
165
|
getWarrantFilter(req: WarrantFilterRequest): Promise<WarrantFilterResult | undefined>;
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* v0.4.0: 所有查询类方法改为 Request 对象签名(OrdersRequest 等),补齐 17
|
|
8
8
|
* 个新方法(账户管理 / 资产分析 / 资金调拨 / 持仓划转等)。
|
|
9
9
|
*/
|
|
10
|
-
import
|
|
10
|
+
import { HttpClient } from '../client/http-client';
|
|
11
|
+
import type { ClientConfig } from '../config/client-config';
|
|
11
12
|
import type { OrderRequest, Order } from '../model/order';
|
|
12
13
|
import type { Contract } from '../model/contract';
|
|
13
14
|
import type { Position } from '../model/position';
|
|
@@ -19,6 +20,8 @@ export declare class TradeClient {
|
|
|
19
20
|
private account;
|
|
20
21
|
private secretKey?;
|
|
21
22
|
constructor(httpClient: HttpClient, account: string, secretKey?: string);
|
|
23
|
+
/** Create a TradeClient directly from a ClientConfig — no need to construct HttpClient manually. */
|
|
24
|
+
static fromConfig(config: ClientConfig, account: string, secretKey?: string): TradeClient;
|
|
22
25
|
private callInto;
|
|
23
26
|
/** Strip `{items: [...]}` envelope used by most trade read endpoints. */
|
|
24
27
|
private callIntoItems;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SDK_VERSION = "0.4.8";
|
package/package.json
CHANGED