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,14 +1,95 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.QuoteClient = void 0;
4
37
  exports.parseOptionIdentifier = parseOptionIdentifier;
38
+ /**
39
+ * QuoteClient — market-data client.
40
+ *
41
+ * All methods return strongly-typed responses from the `model` package.
42
+ * Request parameters are written in camelCase in TypeScript and are
43
+ * converted to snake_case on the wire automatically.
44
+ */
45
+ const http_client_1 = require("../client/http-client");
5
46
  const api_request_1 = require("../client/api-request");
6
47
  const api_response_1 = require("../client/api-response");
48
+ const tokenMethods = __importStar(require("../client/token-methods"));
49
+ const tick_util_1 = require("../push/tick-util");
50
+ /**
51
+ * resolveOptionTimezone returns the timezone string to use for expiry conversion.
52
+ * Explicit tz takes precedence; otherwise infer from symbol (.HK suffix → Asia/Hong_Kong, else America/New_York).
53
+ */
54
+ function resolveOptionTimezone(tz, symbol) {
55
+ if (tz)
56
+ return tz;
57
+ return symbol.toUpperCase().endsWith('.HK') ? 'Asia/Hong_Kong' : 'America/New_York';
58
+ }
59
+ /**
60
+ * Convert a "YYYY-MM-DD" date string to the Unix timestamp (ms) of local midnight
61
+ * in the given IANA timezone.
62
+ *
63
+ * Strategy: use Intl.DateTimeFormat to determine what UTC time corresponds to
64
+ * local midnight in the target timezone, correctly handling DST.
65
+ */
66
+ function localMidnightMs(dateStr, timezone) {
67
+ const [year, month, day] = dateStr.split('-').map(Number);
68
+ // Use noon UTC as a safe anchor (avoids DST ambiguity right at midnight)
69
+ const noonUtc = new Date(Date.UTC(year, month - 1, day, 12, 0, 0));
70
+ // Determine what hour/minute/second UTC noon appears as in the target timezone
71
+ const timeParts = new Intl.DateTimeFormat('en-US', {
72
+ timeZone: timezone,
73
+ hour: '2-digit',
74
+ minute: '2-digit',
75
+ second: '2-digit',
76
+ hour12: false,
77
+ }).formatToParts(noonUtc);
78
+ const h = parseInt(timeParts.find(p => p.type === 'hour').value, 10);
79
+ const m = parseInt(timeParts.find(p => p.type === 'minute').value, 10);
80
+ const s = parseInt(timeParts.find(p => p.type === 'second').value, 10);
81
+ // UTC offset at noon = 12:00:00 UTC − local time shown for noon UTC
82
+ // Local midnight = noon UTC − 12h + offset = noon UTC − (h*3600+m*60+s)s
83
+ return noonUtc.getTime() - (h * 3600 + m * 60 + s) * 1000;
84
+ }
7
85
  /**
8
86
  * Parse an OCC-style option identifier like "AAPL 260619C00150000"
9
87
  * into its component parts.
88
+ *
89
+ * @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
90
+ * If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
10
91
  */
11
- function parseOptionIdentifier(identifier) {
92
+ function parseOptionIdentifier(identifier, timezone) {
12
93
  const trimmed = identifier.trim();
13
94
  const spaceIdx = trimmed.indexOf(' ');
14
95
  if (spaceIdx === -1) {
@@ -25,7 +106,11 @@ function parseOptionIdentifier(identifier) {
25
106
  const yy = parseInt(datePart.substring(0, 2), 10);
26
107
  const mm = parseInt(datePart.substring(2, 4), 10);
27
108
  const dd = parseInt(datePart.substring(4, 6), 10);
28
- const expiryMs = Date.UTC(2000 + yy, mm - 1, dd);
109
+ const resolvedTz = resolveOptionTimezone(timezone, symbol);
110
+ const paddedYear = String(2000 + yy).padStart(4, '0');
111
+ const paddedMonth = String(mm).padStart(2, '0');
112
+ const paddedDay = String(dd).padStart(2, '0');
113
+ const expiryMs = localMidnightMs(`${paddedYear}-${paddedMonth}-${paddedDay}`, resolvedTz);
29
114
  const right = rightChar === 'C' ? 'CALL' : rightChar === 'P' ? 'PUT' : '';
30
115
  if (!right)
31
116
  throw new Error(`invalid right character: ${rightChar}`);
@@ -40,6 +125,29 @@ class QuoteClient {
40
125
  constructor(httpClient) {
41
126
  this.httpClient = httpClient;
42
127
  }
128
+ /** Create a QuoteClient directly from a ClientConfig — no need to construct HttpClient manually. */
129
+ static fromConfig(config) {
130
+ return new QuoteClient(new http_client_1.HttpClient(config, undefined, { useQuoteServerUrl: true }));
131
+ }
132
+ // ── Token management ──────────────────────────────────────────────────────
133
+ /** Call the `user_token_refresh` API and return the new token. Read-only. */
134
+ async queryToken() {
135
+ return tokenMethods.queryToken(this.httpClient);
136
+ }
137
+ /** Refresh the token and update the in-memory config token. */
138
+ async refreshToken(tokenManager) {
139
+ return tokenMethods.refreshToken(this.httpClient, tokenManager);
140
+ }
141
+ /**
142
+ * Start background token auto-refresh. Returns a TokenManager to stop with `tm.stopAutoRefresh()`.
143
+ *
144
+ * @param refreshDurationSecs - Refresh threshold in seconds (minimum 30).
145
+ * @param checkIntervalMs - How often to check, in milliseconds (default 300 000 / 5 min).
146
+ * @param tokenWriter - Optional callback invoked after each successful refresh.
147
+ */
148
+ startTokenAutoRefresh(refreshDurationSecs, checkIntervalMs, tokenWriter) {
149
+ return tokenMethods.startTokenAutoRefresh(this.httpClient, refreshDurationSecs, checkIntervalMs, tokenWriter);
150
+ }
43
151
  async callInto(method, bizParams, version) {
44
152
  const request = (0, api_request_1.createApiRequest)(method, bizParams, version);
45
153
  const response = await this.httpClient.executeRequest(request);
@@ -67,49 +175,115 @@ class QuoteClient {
67
175
  async getMarketState(market) {
68
176
  return this.callInto('market_state', { market });
69
177
  }
70
- /** Real-time stock briefs. wire: quote_real_time */
71
- async getBrief(req) {
178
+ /** Real-time stock quotes. wire: quote_real_time */
179
+ async getRealTimeQuote(req) {
72
180
  return this.callInto('quote_real_time', req);
73
181
  }
74
- async getKline(symbol, period) {
75
- return this.callInto('kline', { symbols: [symbol], period });
182
+ /** @deprecated Use getRealTimeQuote instead. */
183
+ async getBrief(req) {
184
+ return this.getRealTimeQuote(req);
185
+ }
186
+ async getKline(req) {
187
+ return this.callInto('kline', req);
76
188
  }
77
- async getTimeline(symbols) {
78
- return this.callInto('timeline', { symbols });
189
+ async getTimeline(symbolsOrRequest) {
190
+ const req = Array.isArray(symbolsOrRequest) ? { symbols: symbolsOrRequest } : symbolsOrRequest;
191
+ return this.callInto('timeline', req, req.secType === 'CC' ? '3.0' : undefined);
79
192
  }
80
193
  /** Tick-by-tick trades. wire: trade_tick */
81
194
  async getTradeTick(req) {
82
- return this.callInto('trade_tick', req);
195
+ const out = await this.callInto('trade_tick', req);
196
+ for (const tick of out) {
197
+ const isUs = (0, tick_util_1.isUsStockSymbol)(tick.symbol);
198
+ for (const item of tick.items) {
199
+ if (item.cond && item.cond.length > 0) {
200
+ item.cond = (0, tick_util_1.getTradeCondByCode)(isUs, item.cond[0]);
201
+ }
202
+ }
203
+ }
204
+ return out;
83
205
  }
84
206
  /** Depth snapshot. wire: quote_depth */
85
207
  async getQuoteDepth(req) {
86
208
  return this.callInto('quote_depth', req);
87
209
  }
88
210
  // === Options ===
89
- async getOptionExpiration(symbol) {
90
- return this.callInto('option_expiration', { symbols: [symbol] });
91
- }
92
- /** Option chain; `expiry` is "YYYY-MM-DD". */
93
- async getOptionChain(symbol, expiry) {
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');
211
+ async getOptionExpiration(symbols, market) {
212
+ const params = { symbols };
213
+ if (market)
214
+ params.market = market;
215
+ return this.callInto('option_expiration', params);
100
216
  }
101
- async getOptionBrief(identifiers) {
217
+ /**
218
+ * Option chain; each item is [symbol, "YYYY-MM-DD"].
219
+ *
220
+ * @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
221
+ * If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
222
+ * @param returnGreekValue - Whether to return Greeks (delta/gamma/theta/vega/rho).
223
+ * @param optionFilter - Optional filter for in-the-money status, IV range, open interest range, Greeks ranges.
224
+ */
225
+ async getOptionChain(items, timezone, returnGreekValue, optionFilter) {
226
+ const optionBasic = items.map(([symbol, expiry]) => {
227
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(expiry)) {
228
+ throw new Error(`invalid expiry date, expected YYYY-MM-DD: ${expiry}`);
229
+ }
230
+ const tz = resolveOptionTimezone(timezone, symbol);
231
+ const expiryMs = localMidnightMs(expiry, tz);
232
+ return { symbol, expiry: expiryMs };
233
+ });
234
+ const body = { option_basic: optionBasic };
235
+ if (returnGreekValue !== undefined)
236
+ body['return_greek_value'] = returnGreekValue;
237
+ if (optionFilter !== undefined)
238
+ body['option_filter'] = optionFilter;
239
+ return this.callInto('option_chain', body, '3.0');
240
+ }
241
+ /**
242
+ * Option K-line by OCC-style identifier.
243
+ *
244
+ * @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
245
+ * If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
246
+ * @param limit - Maximum number of bars to return.
247
+ * @param sortDir - Sort direction ('asc' or 'desc').
248
+ */
249
+ async getOptionKline(identifiers, period, beginTime = -1, endTime = -1, timezone, limit, sortDir) {
250
+ const resolvedBegin = beginTime === 0 ? -1 : beginTime;
251
+ const resolvedEnd = endTime === 0 ? -1 : endTime;
252
+ const optionQuery = identifiers.map((id) => {
253
+ const p = parseOptionIdentifier(id, timezone);
254
+ const entry = {
255
+ symbol: p.symbol,
256
+ expiry: p.expiryMs,
257
+ right: p.right,
258
+ strike: p.strike,
259
+ period,
260
+ begin_time: resolvedBegin,
261
+ end_time: resolvedEnd,
262
+ };
263
+ if (limit !== undefined && limit > 0)
264
+ entry['limit'] = limit;
265
+ if (sortDir !== undefined && sortDir !== '')
266
+ entry['sort_dir'] = sortDir;
267
+ return entry;
268
+ });
269
+ return this.callInto('option_kline', { option_query: optionQuery }, '2.0');
270
+ }
271
+ /**
272
+ * Real-time option quotes by OCC-style identifier.
273
+ *
274
+ * @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
275
+ * If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
276
+ */
277
+ async getOptionQuote(identifiers, timezone) {
102
278
  const optionBasic = identifiers.map((id) => {
103
- const p = parseOptionIdentifier(id);
279
+ const p = parseOptionIdentifier(id, timezone);
104
280
  return { symbol: p.symbol, expiry: p.expiryMs, right: p.right, strike: p.strike };
105
281
  });
106
282
  return this.callInto('option_brief', { option_basic: optionBasic }, '2.0');
107
283
  }
108
- async getOptionKline(identifier, period) {
109
- const p = parseOptionIdentifier(identifier);
110
- return this.callInto('option_kline', {
111
- option_query: [{ symbol: p.symbol, expiry: p.expiryMs, right: p.right, strike: p.strike, period }],
112
- }, '2.0');
284
+ /** @deprecated Use getOptionQuote instead. */
285
+ async getOptionBrief(identifiers) {
286
+ return this.getOptionQuote(identifiers);
113
287
  }
114
288
  // === Futures ===
115
289
  async getFutureExchange() {
@@ -122,15 +296,6 @@ class QuoteClient {
122
296
  async getFutureRealTimeQuote(req) {
123
297
  return this.callInto('future_real_time_quote', req);
124
298
  }
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
299
  // === Fundamentals ===
135
300
  async getFinancialDaily(req) {
136
301
  return this.callInto('financial_daily', req);
@@ -180,20 +345,16 @@ class QuoteClient {
180
345
  async getStockDetails(req) {
181
346
  return this.callIntoItems('stock_detail', req);
182
347
  }
183
- /** Delayed stock briefs. wire: quote_delay */
184
- async getStockDelayBriefs(req) {
348
+ /** Delayed stock quotes. wire: quote_delay */
349
+ async getDelayedQuote(req) {
185
350
  return this.callInto('quote_delay', req);
186
351
  }
187
- /** K-line bars (full request). wire: kline */
188
- async getBars(req) {
189
- return this.callInto('kline', req);
352
+ /** @deprecated Use getDelayedQuote instead. */
353
+ async getStockDelayBriefs(req) {
354
+ return this.getDelayedQuote(req);
190
355
  }
191
- /**
192
- * Client-side paginated K-line fetch — loops over getBars until TotalSize
193
- * bars are collected. Items are returned oldest-first, matching
194
- * Python/Go get_bars_by_page behaviour.
195
- */
196
- async getBarsByPage(req) {
356
+ /** Client-side paginated K-line fetch. Loops until totalSize bars are collected, oldest-first. */
357
+ async getKlineByPage(req) {
197
358
  const pageSize = req.pageSize && req.pageSize > 0 ? req.pageSize : 200;
198
359
  const totalSize = req.totalSize && req.totalSize > 0 ? req.totalSize : 1000;
199
360
  let beginTime = req.beginTime ?? -1;
@@ -206,6 +367,7 @@ class QuoteClient {
206
367
  while (acc.length < totalSize) {
207
368
  const sub = {
208
369
  symbols: req.symbol ? [req.symbol] : undefined,
370
+ secType: req.secType,
209
371
  period: req.period,
210
372
  right: req.right,
211
373
  beginTime,
@@ -222,7 +384,6 @@ class QuoteClient {
222
384
  acc.push(...items);
223
385
  if (items.length < pageSize)
224
386
  break;
225
- // next page endTime = oldest bar time - 1
226
387
  let oldest = items[0].time;
227
388
  for (const it of items) {
228
389
  if (it.time < oldest)
@@ -257,7 +418,7 @@ class QuoteClient {
257
418
  async getStockIndustry(req) {
258
419
  return this.callInto('stock_industry', req);
259
420
  }
260
- /** Quote permission detail. wire: get_quote_permission */
421
+ /** Market data permission entries. wire: get_quote_permission */
261
422
  async getQuotePermission(req) {
262
423
  return this.callInto('get_quote_permission', req);
263
424
  }
@@ -268,13 +429,16 @@ class QuoteClient {
268
429
  // ==========================================================================
269
430
  // Batch 4: option / future extensions
270
431
  // ==========================================================================
271
- /** Option K-line. wire: option_kline (v2.0) */
272
- async getOptionBars(req) {
273
- return this.callInto('option_kline', req, '2.0');
274
- }
275
- /** Option tick trades. wire: option_trade_tick */
432
+ /** Option tick trades. wire: option_trade_tick
433
+ *
434
+ * Server expects `biz_content` as a top-level JSON array (matches Java's
435
+ * `BatchApiModel` and Python's `MultipleContractParams.to_openapi_dict`).
436
+ * We unwrap the request here so the array is emitted directly instead of
437
+ * `{"contracts": [...]}`. Sending it as an object triggers
438
+ * `biz param error(failed to parse parameters in 'biz_content')`.
439
+ */
276
440
  async getOptionTradeTicks(req) {
277
- return this.callInto('option_trade_tick', req);
441
+ return this.callInto('option_trade_tick', req.contracts ?? []);
278
442
  }
279
443
  /** Option intraday timeline. wire: option_timeline */
280
444
  async getOptionTimeline(req) {
@@ -312,20 +476,24 @@ class QuoteClient {
312
476
  async getFutureHistoryMainContract(req) {
313
477
  return this.callInto('future_main_contract', req);
314
478
  }
315
- /**
316
- * Futures K-line (full request with index pagination). wire: future_kline
317
- * begin_time / end_time default to -1 when unset (server requires them present).
318
- */
319
- async getFutureBars(req) {
479
+ /** Futures K-line. wire: future_kline
480
+ * beginTime / endTime default to -1 when unset (server requires them present).
481
+ * Server expects `contract_codes` (plural) — normalize singular `contractCode`
482
+ * to the plural form so callers can pass either shape. */
483
+ async getFutureKline(req) {
484
+ const contractCodes = req.contractCodes
485
+ ?? (req.contractCode ? [req.contractCode] : undefined);
486
+ const { contractCode: _drop, ...rest } = req;
320
487
  const body = {
321
- ...req,
488
+ ...rest,
489
+ ...(contractCodes ? { contractCodes } : {}),
322
490
  beginTime: req.beginTime ?? -1,
323
491
  endTime: req.endTime ?? -1,
324
492
  };
325
493
  return this.callInto('future_kline', body);
326
494
  }
327
495
  /** Client-side paginated futures K-line fetch. */
328
- async getFutureBarsByPage(req) {
496
+ async getFutureKlineByPage(req) {
329
497
  const pageSize = req.pageSize && req.pageSize > 0 ? req.pageSize : 200;
330
498
  const totalSize = req.totalSize && req.totalSize > 0 ? req.totalSize : 1000;
331
499
  let beginTime = req.beginTime ?? -1;
@@ -336,8 +504,9 @@ class QuoteClient {
336
504
  endTime = -1;
337
505
  const acc = [];
338
506
  while (acc.length < totalSize) {
507
+ // Server rejects singular `contract_code` — send the plural form.
339
508
  const sub = {
340
- contractCode: req.contractCode,
509
+ contractCodes: req.contractCode ? [req.contractCode] : undefined,
341
510
  period: req.period,
342
511
  beginTime,
343
512
  endTime,
@@ -361,9 +530,21 @@ class QuoteClient {
361
530
  }
362
531
  return acc;
363
532
  }
364
- /** Futures tick trades. wire: future_tick (API v3.0) */
533
+ /** Futures tick trades. wire: future_tick (API v3.0)
534
+ * Server returns {contractCode, items:[...]}; unwrap items and backfill contractCode.
535
+ * endIndex defaults to 30 when not set (consistent with Python/Go SDK). */
365
536
  async getFutureTradeTicks(req) {
366
- return this.callInto('future_tick', req, '3.0');
537
+ if (!req.endIndex)
538
+ req.endIndex = 30;
539
+ const wrap = await this.callInto('future_tick', req, '3.0');
540
+ const items = wrap?.items ?? [];
541
+ if (wrap?.contractCode) {
542
+ for (const item of items) {
543
+ if (!item.contractCode)
544
+ item.contractCode = wrap.contractCode;
545
+ }
546
+ }
547
+ return items;
367
548
  }
368
549
  /** Futures depth. wire: future_depth */
369
550
  async getFutureDepth(req) {
@@ -392,17 +573,42 @@ class QuoteClient {
392
573
  async getFundHistoryQuote(req) {
393
574
  return this.callInto('fund_history_quote', req);
394
575
  }
395
- /** Warrant briefs. wire: warrant_briefs */
396
- async getWarrantBriefs(req) {
576
+ /** Real-time warrant quotes. wire: warrant_briefs */
577
+ async getWarrantQuote(req) {
397
578
  return this.callInto('warrant_briefs', req);
398
579
  }
580
+ /** @deprecated Use getWarrantQuote instead. */
581
+ async getWarrantBriefs(req) {
582
+ return this.getWarrantQuote(req);
583
+ }
399
584
  /** Warrant filter (paged). wire: warrant_filter */
400
585
  async getWarrantFilter(req) {
401
586
  return this.callInto('warrant_filter', req);
402
587
  }
403
- /** Industry list. wire: industry_list */
404
- async getIndustryList(req) {
405
- return this.callInto('industry_list', req);
588
+ /** Industry list. wire: industry_list
589
+ *
590
+ * `industryLevel` is required by the server — omitting it returns
591
+ * `industry level error, all supported is: [GSECTOR, GGROUP, GIND, GSUBIND]`.
592
+ * Defaults to `GGROUP` when unset, matching Python SDK's
593
+ * `IndustryLevel.GGROUP` default.
594
+ *
595
+ * Wire fields differ from other endpoints (see `IndustryItem`): server sends
596
+ * `nameCN` / `nameEN` / `industryLevel`. This method hydrates the
597
+ * backwards-compat `name` (from `nameEN || nameCN`) and mirrors
598
+ * `industryLevel` to `level` so existing callers keep working.
599
+ */
600
+ async getIndustryList(req = {}) {
601
+ const payload = { industryLevel: 'GGROUP', ...req };
602
+ const items = await this.callInto('industry_list', payload);
603
+ if (!Array.isArray(items))
604
+ return [];
605
+ for (const it of items) {
606
+ if (it.name === undefined)
607
+ it.name = it.nameEN || it.nameCN;
608
+ if (it.level === undefined)
609
+ it.level = it.industryLevel;
610
+ }
611
+ return items;
406
612
  }
407
613
  /** Stocks inside an industry. wire: industry_stock_list */
408
614
  async getIndustryStocks(req) {
@@ -432,6 +638,30 @@ class QuoteClient {
432
638
  return [];
433
639
  return Object.values(grouped).flat();
434
640
  }
641
+ /** Corporate symbol change (flattened). wire: corporate_action (action_type=symbol_change) */
642
+ async getCorporateSymbolChange(req) {
643
+ const body = { ...req, actionType: 'symbol_change' };
644
+ const grouped = await this.callInto('corporate_action', body);
645
+ if (!grouped || typeof grouped !== 'object')
646
+ return [];
647
+ return Object.values(grouped).flat();
648
+ }
649
+ /** Corporate delisting (flattened). wire: corporate_action (action_type=delisting) */
650
+ async getCorporateDelisting(req) {
651
+ const body = { ...req, actionType: 'delisting' };
652
+ const grouped = await this.callInto('corporate_action', body);
653
+ if (!grouped || typeof grouped !== 'object')
654
+ return [];
655
+ return Object.values(grouped).flat();
656
+ }
657
+ /** Corporate IPO (flattened). wire: corporate_action (action_type=ipo) */
658
+ async getCorporateIPO(req) {
659
+ const body = { ...req, actionType: 'ipo' };
660
+ const grouped = await this.callInto('corporate_action', body);
661
+ if (!grouped || typeof grouped !== 'object')
662
+ return [];
663
+ return Object.values(grouped).flat();
664
+ }
435
665
  /** Financial currency per symbol. wire: financial_currency */
436
666
  async getFinancialCurrency(req) {
437
667
  return this.callInto('financial_currency', req);