tigeropen 0.4.0 → 0.5.7

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.
Files changed (116) hide show
  1. package/README.md +82 -2
  2. package/dist/cjs/auth/authentication.js +74 -0
  3. package/dist/cjs/auth/index.js +24 -0
  4. package/dist/cjs/auth/oauth2/client-registration.js +44 -0
  5. package/dist/cjs/auth/oauth2/device-authorization.js +40 -0
  6. package/dist/cjs/auth/oauth2/errors.js +64 -0
  7. package/dist/cjs/auth/oauth2/http-utils.js +112 -0
  8. package/dist/cjs/auth/oauth2/index.js +42 -0
  9. package/dist/cjs/auth/oauth2/loopback-receiver.js +215 -0
  10. package/dist/cjs/auth/oauth2/metadata.js +34 -0
  11. package/dist/cjs/auth/oauth2/oauth2-authentication.js +74 -0
  12. package/dist/cjs/auth/oauth2/session-manager.js +762 -0
  13. package/dist/cjs/auth/oauth2/token-store.js +252 -0
  14. package/dist/cjs/auth/oauth2/token.js +76 -0
  15. package/dist/cjs/client/api-response.js +28 -7
  16. package/dist/cjs/client/case-convert.js +4 -3
  17. package/dist/cjs/client/http-client.js +124 -8
  18. package/dist/cjs/client/token-methods.js +42 -0
  19. package/dist/cjs/config/client-config.js +115 -16
  20. package/dist/cjs/config/config-parser.js +19 -9
  21. package/dist/cjs/config/index.js +4 -1
  22. package/dist/cjs/config/token-manager.js +54 -4
  23. package/dist/cjs/index.js +53 -2
  24. package/dist/cjs/model/enums.js +18 -1
  25. package/dist/cjs/model/order-helpers.js +149 -0
  26. package/dist/cjs/push/index.js +1 -0
  27. package/dist/cjs/push/pb/Request.js +12 -1
  28. package/dist/cjs/push/proto-message.js +5 -1
  29. package/dist/cjs/push/push-client.js +69 -25
  30. package/dist/cjs/push/tick-util.js +172 -0
  31. package/dist/cjs/quote/quote-client.js +300 -70
  32. package/dist/cjs/trade/trade-client.js +186 -16
  33. package/dist/cjs/version.js +4 -0
  34. package/dist/esm/auth/authentication.js +68 -0
  35. package/dist/esm/auth/index.js +3 -0
  36. package/dist/esm/auth/oauth2/client-registration.js +40 -0
  37. package/dist/esm/auth/oauth2/device-authorization.js +36 -0
  38. package/dist/esm/auth/oauth2/errors.js +59 -0
  39. package/dist/esm/auth/oauth2/http-utils.js +105 -0
  40. package/dist/esm/auth/oauth2/index.js +11 -0
  41. package/dist/esm/auth/oauth2/loopback-receiver.js +178 -0
  42. package/dist/esm/auth/oauth2/metadata.js +30 -0
  43. package/dist/esm/auth/oauth2/oauth2-authentication.js +70 -0
  44. package/dist/esm/auth/oauth2/session-manager.js +725 -0
  45. package/dist/esm/auth/oauth2/token-store.js +214 -0
  46. package/dist/esm/auth/oauth2/token.js +71 -0
  47. package/dist/esm/client/api-request.js +1 -1
  48. package/dist/esm/client/api-response.js +29 -8
  49. package/dist/esm/client/case-convert.js +4 -3
  50. package/dist/esm/client/http-client.js +128 -12
  51. package/dist/esm/client/index.js +6 -6
  52. package/dist/esm/client/token-methods.js +37 -0
  53. package/dist/esm/config/client-config.js +118 -20
  54. package/dist/esm/config/config-parser.js +19 -9
  55. package/dist/esm/config/index.js +4 -3
  56. package/dist/esm/config/token-manager.js +55 -5
  57. package/dist/esm/index.js +15 -1
  58. package/dist/esm/logger/index.js +1 -1
  59. package/dist/esm/model/contract-helpers.js +1 -1
  60. package/dist/esm/model/enums.js +17 -0
  61. package/dist/esm/model/order-helpers.js +142 -1
  62. package/dist/esm/model/order-status.js +1 -1
  63. package/dist/esm/package.json +3 -0
  64. package/dist/esm/push/index.js +6 -5
  65. package/dist/esm/push/pb/PushData.js +11 -11
  66. package/dist/esm/push/pb/QuoteBasicData.js +1 -1
  67. package/dist/esm/push/pb/Request.js +12 -1
  68. package/dist/esm/push/pb/Response.js +1 -1
  69. package/dist/esm/push/pb/index.js +17 -17
  70. package/dist/esm/push/proto-message.js +8 -4
  71. package/dist/esm/push/push-client.js +76 -32
  72. package/dist/esm/push/tick-util.js +165 -0
  73. package/dist/esm/quote/index.js +1 -1
  74. package/dist/esm/quote/quote-client.js +269 -72
  75. package/dist/esm/signer/index.js +2 -2
  76. package/dist/esm/trade/index.js +1 -1
  77. package/dist/esm/trade/trade-client.js +156 -19
  78. package/dist/esm/version.js +1 -0
  79. package/dist/types/auth/authentication.d.ts +98 -0
  80. package/dist/types/auth/index.d.ts +4 -0
  81. package/dist/types/auth/oauth2/client-registration.d.ts +32 -0
  82. package/dist/types/auth/oauth2/device-authorization.d.ts +40 -0
  83. package/dist/types/auth/oauth2/errors.d.ts +46 -0
  84. package/dist/types/auth/oauth2/http-utils.d.ts +21 -0
  85. package/dist/types/auth/oauth2/index.d.ts +16 -0
  86. package/dist/types/auth/oauth2/loopback-receiver.d.ts +29 -0
  87. package/dist/types/auth/oauth2/metadata.d.ts +32 -0
  88. package/dist/types/auth/oauth2/oauth2-authentication.d.ts +31 -0
  89. package/dist/types/auth/oauth2/session-manager.d.ts +241 -0
  90. package/dist/types/auth/oauth2/token-store.d.ts +49 -0
  91. package/dist/types/auth/oauth2/token.d.ts +56 -0
  92. package/dist/types/client/api-response.d.ts +6 -4
  93. package/dist/types/client/case-convert.d.ts +3 -1
  94. package/dist/types/client/http-client.d.ts +32 -1
  95. package/dist/types/client/token-methods.d.ts +34 -0
  96. package/dist/types/config/client-config.d.ts +22 -1
  97. package/dist/types/config/index.d.ts +3 -1
  98. package/dist/types/config/token-manager.d.ts +27 -3
  99. package/dist/types/index.d.ts +22 -1
  100. package/dist/types/model/enums.d.ts +18 -2
  101. package/dist/types/model/order-helpers.d.ts +52 -1
  102. package/dist/types/model/order.d.ts +127 -10
  103. package/dist/types/model/quote-requests.d.ts +27 -15
  104. package/dist/types/model/quote.d.ts +151 -24
  105. package/dist/types/model/trade-requests.d.ts +123 -4
  106. package/dist/types/model/trade.d.ts +121 -17
  107. package/dist/types/push/callbacks.d.ts +3 -7
  108. package/dist/types/push/index.d.ts +2 -1
  109. package/dist/types/push/pb/Request.d.ts +1 -0
  110. package/dist/types/push/proto-message.d.ts +4 -1
  111. package/dist/types/push/push-client.d.ts +38 -3
  112. package/dist/types/push/tick-util.d.ts +30 -0
  113. package/dist/types/quote/quote-client.d.ts +101 -36
  114. package/dist/types/trade/trade-client.d.ts +69 -14
  115. package/dist/types/version.d.ts +1 -0
  116. package/package.json +9 -4
@@ -1,10 +1,58 @@
1
- import { createApiRequest } from '../client/api-request';
2
- import { unmarshalData } from '../client/api-response';
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';
9
+ import { createApiRequest } from '../client/api-request.js';
10
+ import { unmarshalData } from '../client/api-response.js';
11
+ import * as tokenMethods from '../client/token-methods.js';
12
+ import { getTradeCondByCode, isUsStockSymbol } from '../push/tick-util.js';
13
+ /**
14
+ * resolveOptionTimezone returns the timezone string to use for expiry conversion.
15
+ * Explicit tz takes precedence; otherwise infer from symbol (.HK suffix → Asia/Hong_Kong, else America/New_York).
16
+ */
17
+ function resolveOptionTimezone(tz, symbol) {
18
+ if (tz)
19
+ return tz;
20
+ return symbol.toUpperCase().endsWith('.HK') ? 'Asia/Hong_Kong' : 'America/New_York';
21
+ }
22
+ /**
23
+ * Convert a "YYYY-MM-DD" date string to the Unix timestamp (ms) of local midnight
24
+ * in the given IANA timezone.
25
+ *
26
+ * Strategy: use Intl.DateTimeFormat to determine what UTC time corresponds to
27
+ * local midnight in the target timezone, correctly handling DST.
28
+ */
29
+ function localMidnightMs(dateStr, timezone) {
30
+ const [year, month, day] = dateStr.split('-').map(Number);
31
+ // Use noon UTC as a safe anchor (avoids DST ambiguity right at midnight)
32
+ const noonUtc = new Date(Date.UTC(year, month - 1, day, 12, 0, 0));
33
+ // Determine what hour/minute/second UTC noon appears as in the target timezone
34
+ const timeParts = new Intl.DateTimeFormat('en-US', {
35
+ timeZone: timezone,
36
+ hour: '2-digit',
37
+ minute: '2-digit',
38
+ second: '2-digit',
39
+ hour12: false,
40
+ }).formatToParts(noonUtc);
41
+ const h = parseInt(timeParts.find(p => p.type === 'hour').value, 10);
42
+ const m = parseInt(timeParts.find(p => p.type === 'minute').value, 10);
43
+ const s = parseInt(timeParts.find(p => p.type === 'second').value, 10);
44
+ // UTC offset at noon = 12:00:00 UTC − local time shown for noon UTC
45
+ // Local midnight = noon UTC − 12h + offset = noon UTC − (h*3600+m*60+s)s
46
+ return noonUtc.getTime() - (h * 3600 + m * 60 + s) * 1000;
47
+ }
3
48
  /**
4
49
  * Parse an OCC-style option identifier like "AAPL 260619C00150000"
5
50
  * into its component parts.
51
+ *
52
+ * @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
53
+ * If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
6
54
  */
7
- export function parseOptionIdentifier(identifier) {
55
+ export function parseOptionIdentifier(identifier, timezone) {
8
56
  const trimmed = identifier.trim();
9
57
  const spaceIdx = trimmed.indexOf(' ');
10
58
  if (spaceIdx === -1) {
@@ -21,7 +69,11 @@ export function parseOptionIdentifier(identifier) {
21
69
  const yy = parseInt(datePart.substring(0, 2), 10);
22
70
  const mm = parseInt(datePart.substring(2, 4), 10);
23
71
  const dd = parseInt(datePart.substring(4, 6), 10);
24
- const expiryMs = Date.UTC(2000 + yy, mm - 1, dd);
72
+ const resolvedTz = resolveOptionTimezone(timezone, symbol);
73
+ const paddedYear = String(2000 + yy).padStart(4, '0');
74
+ const paddedMonth = String(mm).padStart(2, '0');
75
+ const paddedDay = String(dd).padStart(2, '0');
76
+ const expiryMs = localMidnightMs(`${paddedYear}-${paddedMonth}-${paddedDay}`, resolvedTz);
25
77
  const right = rightChar === 'C' ? 'CALL' : rightChar === 'P' ? 'PUT' : '';
26
78
  if (!right)
27
79
  throw new Error(`invalid right character: ${rightChar}`);
@@ -36,6 +88,29 @@ export class QuoteClient {
36
88
  constructor(httpClient) {
37
89
  this.httpClient = httpClient;
38
90
  }
91
+ /** Create a QuoteClient directly from a ClientConfig — no need to construct HttpClient manually. */
92
+ static fromConfig(config) {
93
+ return new QuoteClient(new HttpClient(config, undefined, { useQuoteServerUrl: true }));
94
+ }
95
+ // ── Token management ──────────────────────────────────────────────────────
96
+ /** Call the `user_token_refresh` API and return the new token. Read-only. */
97
+ async queryToken() {
98
+ return tokenMethods.queryToken(this.httpClient);
99
+ }
100
+ /** Refresh the token and update the in-memory config token. */
101
+ async refreshToken(tokenManager) {
102
+ return tokenMethods.refreshToken(this.httpClient, tokenManager);
103
+ }
104
+ /**
105
+ * Start background token auto-refresh. Returns a TokenManager to stop with `tm.stopAutoRefresh()`.
106
+ *
107
+ * @param refreshDurationSecs - Refresh threshold in seconds (minimum 30).
108
+ * @param checkIntervalMs - How often to check, in milliseconds (default 300 000 / 5 min).
109
+ * @param tokenWriter - Optional callback invoked after each successful refresh.
110
+ */
111
+ startTokenAutoRefresh(refreshDurationSecs, checkIntervalMs, tokenWriter) {
112
+ return tokenMethods.startTokenAutoRefresh(this.httpClient, refreshDurationSecs, checkIntervalMs, tokenWriter);
113
+ }
39
114
  async callInto(method, bizParams, version) {
40
115
  const request = createApiRequest(method, bizParams, version);
41
116
  const response = await this.httpClient.executeRequest(request);
@@ -63,49 +138,115 @@ export class QuoteClient {
63
138
  async getMarketState(market) {
64
139
  return this.callInto('market_state', { market });
65
140
  }
66
- /** Real-time stock briefs. wire: quote_real_time */
67
- async getBrief(req) {
141
+ /** Real-time stock quotes. wire: quote_real_time */
142
+ async getRealTimeQuote(req) {
68
143
  return this.callInto('quote_real_time', req);
69
144
  }
70
- async getKline(symbol, period) {
71
- return this.callInto('kline', { symbols: [symbol], period });
145
+ /** @deprecated Use getRealTimeQuote instead. */
146
+ async getBrief(req) {
147
+ return this.getRealTimeQuote(req);
148
+ }
149
+ async getKline(req) {
150
+ return this.callInto('kline', req);
72
151
  }
73
- async getTimeline(symbols) {
74
- return this.callInto('timeline', { symbols });
152
+ async getTimeline(symbolsOrRequest) {
153
+ const req = Array.isArray(symbolsOrRequest) ? { symbols: symbolsOrRequest } : symbolsOrRequest;
154
+ return this.callInto('timeline', req, req.secType === 'CC' ? '3.0' : undefined);
75
155
  }
76
156
  /** Tick-by-tick trades. wire: trade_tick */
77
157
  async getTradeTick(req) {
78
- return this.callInto('trade_tick', req);
158
+ const out = await this.callInto('trade_tick', req);
159
+ for (const tick of out) {
160
+ const isUs = isUsStockSymbol(tick.symbol);
161
+ for (const item of tick.items) {
162
+ if (item.cond && item.cond.length > 0) {
163
+ item.cond = getTradeCondByCode(isUs, item.cond[0]);
164
+ }
165
+ }
166
+ }
167
+ return out;
79
168
  }
80
169
  /** Depth snapshot. wire: quote_depth */
81
170
  async getQuoteDepth(req) {
82
171
  return this.callInto('quote_depth', req);
83
172
  }
84
173
  // === Options ===
85
- async getOptionExpiration(symbol) {
86
- return this.callInto('option_expiration', { symbols: [symbol] });
87
- }
88
- /** Option chain; `expiry` is "YYYY-MM-DD". */
89
- async getOptionChain(symbol, expiry) {
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');
174
+ async getOptionExpiration(symbols, market) {
175
+ const params = { symbols };
176
+ if (market)
177
+ params.market = market;
178
+ return this.callInto('option_expiration', params);
96
179
  }
97
- async getOptionBrief(identifiers) {
180
+ /**
181
+ * Option chain; each item is [symbol, "YYYY-MM-DD"].
182
+ *
183
+ * @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
184
+ * If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
185
+ * @param returnGreekValue - Whether to return Greeks (delta/gamma/theta/vega/rho).
186
+ * @param optionFilter - Optional filter for in-the-money status, IV range, open interest range, Greeks ranges.
187
+ */
188
+ async getOptionChain(items, timezone, returnGreekValue, optionFilter) {
189
+ const optionBasic = items.map(([symbol, expiry]) => {
190
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(expiry)) {
191
+ throw new Error(`invalid expiry date, expected YYYY-MM-DD: ${expiry}`);
192
+ }
193
+ const tz = resolveOptionTimezone(timezone, symbol);
194
+ const expiryMs = localMidnightMs(expiry, tz);
195
+ return { symbol, expiry: expiryMs };
196
+ });
197
+ const body = { option_basic: optionBasic };
198
+ if (returnGreekValue !== undefined)
199
+ body['return_greek_value'] = returnGreekValue;
200
+ if (optionFilter !== undefined)
201
+ body['option_filter'] = optionFilter;
202
+ return this.callInto('option_chain', body, '3.0');
203
+ }
204
+ /**
205
+ * Option K-line by OCC-style identifier.
206
+ *
207
+ * @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
208
+ * If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
209
+ * @param limit - Maximum number of bars to return.
210
+ * @param sortDir - Sort direction ('asc' or 'desc').
211
+ */
212
+ async getOptionKline(identifiers, period, beginTime = -1, endTime = -1, timezone, limit, sortDir) {
213
+ const resolvedBegin = beginTime === 0 ? -1 : beginTime;
214
+ const resolvedEnd = endTime === 0 ? -1 : endTime;
215
+ const optionQuery = identifiers.map((id) => {
216
+ const p = parseOptionIdentifier(id, timezone);
217
+ const entry = {
218
+ symbol: p.symbol,
219
+ expiry: p.expiryMs,
220
+ right: p.right,
221
+ strike: p.strike,
222
+ period,
223
+ begin_time: resolvedBegin,
224
+ end_time: resolvedEnd,
225
+ };
226
+ if (limit !== undefined && limit > 0)
227
+ entry['limit'] = limit;
228
+ if (sortDir !== undefined && sortDir !== '')
229
+ entry['sort_dir'] = sortDir;
230
+ return entry;
231
+ });
232
+ return this.callInto('option_kline', { option_query: optionQuery }, '2.0');
233
+ }
234
+ /**
235
+ * Real-time option quotes by OCC-style identifier.
236
+ *
237
+ * @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
238
+ * If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
239
+ */
240
+ async getOptionQuote(identifiers, timezone) {
98
241
  const optionBasic = identifiers.map((id) => {
99
- const p = parseOptionIdentifier(id);
242
+ const p = parseOptionIdentifier(id, timezone);
100
243
  return { symbol: p.symbol, expiry: p.expiryMs, right: p.right, strike: p.strike };
101
244
  });
102
245
  return this.callInto('option_brief', { option_basic: optionBasic }, '2.0');
103
246
  }
104
- async getOptionKline(identifier, period) {
105
- const p = parseOptionIdentifier(identifier);
106
- return this.callInto('option_kline', {
107
- option_query: [{ symbol: p.symbol, expiry: p.expiryMs, right: p.right, strike: p.strike, period }],
108
- }, '2.0');
247
+ /** @deprecated Use getOptionQuote instead. */
248
+ async getOptionBrief(identifiers) {
249
+ return this.getOptionQuote(identifiers);
109
250
  }
110
251
  // === Futures ===
111
252
  async getFutureExchange() {
@@ -118,15 +259,6 @@ export class QuoteClient {
118
259
  async getFutureRealTimeQuote(req) {
119
260
  return this.callInto('future_real_time_quote', req);
120
261
  }
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
262
  // === Fundamentals ===
131
263
  async getFinancialDaily(req) {
132
264
  return this.callInto('financial_daily', req);
@@ -176,20 +308,16 @@ export class QuoteClient {
176
308
  async getStockDetails(req) {
177
309
  return this.callIntoItems('stock_detail', req);
178
310
  }
179
- /** Delayed stock briefs. wire: quote_delay */
180
- async getStockDelayBriefs(req) {
311
+ /** Delayed stock quotes. wire: quote_delay */
312
+ async getDelayedQuote(req) {
181
313
  return this.callInto('quote_delay', req);
182
314
  }
183
- /** K-line bars (full request). wire: kline */
184
- async getBars(req) {
185
- return this.callInto('kline', req);
315
+ /** @deprecated Use getDelayedQuote instead. */
316
+ async getStockDelayBriefs(req) {
317
+ return this.getDelayedQuote(req);
186
318
  }
187
- /**
188
- * Client-side paginated K-line fetch — loops over getBars until TotalSize
189
- * bars are collected. Items are returned oldest-first, matching
190
- * Python/Go get_bars_by_page behaviour.
191
- */
192
- async getBarsByPage(req) {
319
+ /** Client-side paginated K-line fetch. Loops until totalSize bars are collected, oldest-first. */
320
+ async getKlineByPage(req) {
193
321
  const pageSize = req.pageSize && req.pageSize > 0 ? req.pageSize : 200;
194
322
  const totalSize = req.totalSize && req.totalSize > 0 ? req.totalSize : 1000;
195
323
  let beginTime = req.beginTime ?? -1;
@@ -202,6 +330,7 @@ export class QuoteClient {
202
330
  while (acc.length < totalSize) {
203
331
  const sub = {
204
332
  symbols: req.symbol ? [req.symbol] : undefined,
333
+ secType: req.secType,
205
334
  period: req.period,
206
335
  right: req.right,
207
336
  beginTime,
@@ -218,7 +347,6 @@ export class QuoteClient {
218
347
  acc.push(...items);
219
348
  if (items.length < pageSize)
220
349
  break;
221
- // next page endTime = oldest bar time - 1
222
350
  let oldest = items[0].time;
223
351
  for (const it of items) {
224
352
  if (it.time < oldest)
@@ -253,7 +381,7 @@ export class QuoteClient {
253
381
  async getStockIndustry(req) {
254
382
  return this.callInto('stock_industry', req);
255
383
  }
256
- /** Quote permission detail. wire: get_quote_permission */
384
+ /** Market data permission entries. wire: get_quote_permission */
257
385
  async getQuotePermission(req) {
258
386
  return this.callInto('get_quote_permission', req);
259
387
  }
@@ -264,13 +392,16 @@ export class QuoteClient {
264
392
  // ==========================================================================
265
393
  // Batch 4: option / future extensions
266
394
  // ==========================================================================
267
- /** Option K-line. wire: option_kline (v2.0) */
268
- async getOptionBars(req) {
269
- return this.callInto('option_kline', req, '2.0');
270
- }
271
- /** Option tick trades. wire: option_trade_tick */
395
+ /** Option tick trades. wire: option_trade_tick
396
+ *
397
+ * Server expects `biz_content` as a top-level JSON array (matches Java's
398
+ * `BatchApiModel` and Python's `MultipleContractParams.to_openapi_dict`).
399
+ * We unwrap the request here so the array is emitted directly instead of
400
+ * `{"contracts": [...]}`. Sending it as an object triggers
401
+ * `biz param error(failed to parse parameters in 'biz_content')`.
402
+ */
272
403
  async getOptionTradeTicks(req) {
273
- return this.callInto('option_trade_tick', req);
404
+ return this.callInto('option_trade_tick', req.contracts ?? []);
274
405
  }
275
406
  /** Option intraday timeline. wire: option_timeline */
276
407
  async getOptionTimeline(req) {
@@ -308,20 +439,24 @@ export class QuoteClient {
308
439
  async getFutureHistoryMainContract(req) {
309
440
  return this.callInto('future_main_contract', req);
310
441
  }
311
- /**
312
- * Futures K-line (full request with index pagination). wire: future_kline
313
- * begin_time / end_time default to -1 when unset (server requires them present).
314
- */
315
- async getFutureBars(req) {
442
+ /** Futures K-line. wire: future_kline
443
+ * beginTime / endTime default to -1 when unset (server requires them present).
444
+ * Server expects `contract_codes` (plural) — normalize singular `contractCode`
445
+ * to the plural form so callers can pass either shape. */
446
+ async getFutureKline(req) {
447
+ const contractCodes = req.contractCodes
448
+ ?? (req.contractCode ? [req.contractCode] : undefined);
449
+ const { contractCode: _drop, ...rest } = req;
316
450
  const body = {
317
- ...req,
451
+ ...rest,
452
+ ...(contractCodes ? { contractCodes } : {}),
318
453
  beginTime: req.beginTime ?? -1,
319
454
  endTime: req.endTime ?? -1,
320
455
  };
321
456
  return this.callInto('future_kline', body);
322
457
  }
323
458
  /** Client-side paginated futures K-line fetch. */
324
- async getFutureBarsByPage(req) {
459
+ async getFutureKlineByPage(req) {
325
460
  const pageSize = req.pageSize && req.pageSize > 0 ? req.pageSize : 200;
326
461
  const totalSize = req.totalSize && req.totalSize > 0 ? req.totalSize : 1000;
327
462
  let beginTime = req.beginTime ?? -1;
@@ -332,8 +467,9 @@ export class QuoteClient {
332
467
  endTime = -1;
333
468
  const acc = [];
334
469
  while (acc.length < totalSize) {
470
+ // Server rejects singular `contract_code` — send the plural form.
335
471
  const sub = {
336
- contractCode: req.contractCode,
472
+ contractCodes: req.contractCode ? [req.contractCode] : undefined,
337
473
  period: req.period,
338
474
  beginTime,
339
475
  endTime,
@@ -357,9 +493,21 @@ export class QuoteClient {
357
493
  }
358
494
  return acc;
359
495
  }
360
- /** Futures tick trades. wire: future_tick (API v3.0) */
496
+ /** Futures tick trades. wire: future_tick (API v3.0)
497
+ * Server returns {contractCode, items:[...]}; unwrap items and backfill contractCode.
498
+ * endIndex defaults to 30 when not set (consistent with Python/Go SDK). */
361
499
  async getFutureTradeTicks(req) {
362
- return this.callInto('future_tick', req, '3.0');
500
+ if (!req.endIndex)
501
+ req.endIndex = 30;
502
+ const wrap = await this.callInto('future_tick', req, '3.0');
503
+ const items = wrap?.items ?? [];
504
+ if (wrap?.contractCode) {
505
+ for (const item of items) {
506
+ if (!item.contractCode)
507
+ item.contractCode = wrap.contractCode;
508
+ }
509
+ }
510
+ return items;
363
511
  }
364
512
  /** Futures depth. wire: future_depth */
365
513
  async getFutureDepth(req) {
@@ -388,17 +536,42 @@ export class QuoteClient {
388
536
  async getFundHistoryQuote(req) {
389
537
  return this.callInto('fund_history_quote', req);
390
538
  }
391
- /** Warrant briefs. wire: warrant_briefs */
392
- async getWarrantBriefs(req) {
539
+ /** Real-time warrant quotes. wire: warrant_briefs */
540
+ async getWarrantQuote(req) {
393
541
  return this.callInto('warrant_briefs', req);
394
542
  }
543
+ /** @deprecated Use getWarrantQuote instead. */
544
+ async getWarrantBriefs(req) {
545
+ return this.getWarrantQuote(req);
546
+ }
395
547
  /** Warrant filter (paged). wire: warrant_filter */
396
548
  async getWarrantFilter(req) {
397
549
  return this.callInto('warrant_filter', req);
398
550
  }
399
- /** Industry list. wire: industry_list */
400
- async getIndustryList(req) {
401
- return this.callInto('industry_list', req);
551
+ /** Industry list. wire: industry_list
552
+ *
553
+ * `industryLevel` is required by the server — omitting it returns
554
+ * `industry level error, all supported is: [GSECTOR, GGROUP, GIND, GSUBIND]`.
555
+ * Defaults to `GGROUP` when unset, matching Python SDK's
556
+ * `IndustryLevel.GGROUP` default.
557
+ *
558
+ * Wire fields differ from other endpoints (see `IndustryItem`): server sends
559
+ * `nameCN` / `nameEN` / `industryLevel`. This method hydrates the
560
+ * backwards-compat `name` (from `nameEN || nameCN`) and mirrors
561
+ * `industryLevel` to `level` so existing callers keep working.
562
+ */
563
+ async getIndustryList(req = {}) {
564
+ const payload = { industryLevel: 'GGROUP', ...req };
565
+ const items = await this.callInto('industry_list', payload);
566
+ if (!Array.isArray(items))
567
+ return [];
568
+ for (const it of items) {
569
+ if (it.name === undefined)
570
+ it.name = it.nameEN || it.nameCN;
571
+ if (it.level === undefined)
572
+ it.level = it.industryLevel;
573
+ }
574
+ return items;
402
575
  }
403
576
  /** Stocks inside an industry. wire: industry_stock_list */
404
577
  async getIndustryStocks(req) {
@@ -428,6 +601,30 @@ export class QuoteClient {
428
601
  return [];
429
602
  return Object.values(grouped).flat();
430
603
  }
604
+ /** Corporate symbol change (flattened). wire: corporate_action (action_type=symbol_change) */
605
+ async getCorporateSymbolChange(req) {
606
+ const body = { ...req, actionType: 'symbol_change' };
607
+ const grouped = await this.callInto('corporate_action', body);
608
+ if (!grouped || typeof grouped !== 'object')
609
+ return [];
610
+ return Object.values(grouped).flat();
611
+ }
612
+ /** Corporate delisting (flattened). wire: corporate_action (action_type=delisting) */
613
+ async getCorporateDelisting(req) {
614
+ const body = { ...req, actionType: 'delisting' };
615
+ const grouped = await this.callInto('corporate_action', body);
616
+ if (!grouped || typeof grouped !== 'object')
617
+ return [];
618
+ return Object.values(grouped).flat();
619
+ }
620
+ /** Corporate IPO (flattened). wire: corporate_action (action_type=ipo) */
621
+ async getCorporateIPO(req) {
622
+ const body = { ...req, actionType: 'ipo' };
623
+ const grouped = await this.callInto('corporate_action', body);
624
+ if (!grouped || typeof grouped !== 'object')
625
+ return [];
626
+ return Object.values(grouped).flat();
627
+ }
431
628
  /** Financial currency per symbol. wire: financial_currency */
432
629
  async getFinancialCurrency(req) {
433
630
  return this.callInto('financial_currency', req);
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * 认证层(RSA Signer)统一导出
3
3
  */
4
- export { loadPrivateKey, signWithRSA, verifyWithRSA } from './signer';
5
- export { getSignContent } from './sign-content';
4
+ export { loadPrivateKey, signWithRSA, verifyWithRSA } from './signer.js';
5
+ export { getSignContent } from './sign-content.js';
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * 交易模块导出
3
3
  */
4
- export { TradeClient } from './trade-client';
4
+ export { TradeClient } from './trade-client.js';