tigeropen 0.5.7 → 0.5.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.
Files changed (77) hide show
  1. package/README.md +159 -0
  2. package/dist/cjs/client/api-response.js +6 -5
  3. package/dist/cjs/index.js +4 -2
  4. package/dist/cjs/model/news-requests.js +9 -0
  5. package/dist/cjs/model/news.js +8 -0
  6. package/dist/cjs/news/index.js +8 -0
  7. package/dist/cjs/news/news-client.js +84 -0
  8. package/dist/cjs/push/pb/QuoteBasicData.js +37 -1
  9. package/dist/cjs/push/pb/QuoteData.js +37 -1
  10. package/dist/cjs/quote/quote-client.js +4 -1
  11. package/dist/cjs/trade/trade-client.js +26 -4
  12. package/dist/cjs/version.js +1 -1
  13. package/dist/esm/client/api-response.js +6 -5
  14. package/dist/esm/index.js +2 -1
  15. package/dist/esm/model/news-requests.js +8 -0
  16. package/dist/esm/model/news.js +7 -0
  17. package/dist/esm/news/index.js +4 -0
  18. package/dist/esm/news/news-client.js +80 -0
  19. package/dist/esm/push/pb/QuoteBasicData.js +37 -1
  20. package/dist/esm/push/pb/QuoteData.js +37 -1
  21. package/dist/esm/quote/quote-client.js +4 -1
  22. package/dist/esm/trade/trade-client.js +26 -4
  23. package/dist/esm/version.js +1 -1
  24. package/dist/types/index.d.ts +8 -4
  25. package/dist/types/model/contract.d.ts +8 -0
  26. package/dist/types/model/news-requests.d.ts +39 -0
  27. package/dist/types/model/news.d.ts +38 -0
  28. package/dist/types/model/order.d.ts +2 -0
  29. package/dist/types/model/quote.d.ts +16 -0
  30. package/dist/types/model/trade-requests.d.ts +20 -1
  31. package/dist/types/news/index.d.ts +5 -0
  32. package/dist/types/news/news-client.d.ts +60 -0
  33. package/dist/types/push/pb/QuoteBasicData.d.ts +14 -5
  34. package/dist/types/push/pb/QuoteData.d.ts +14 -5
  35. package/dist/types/quote/quote-client.d.ts +2 -1
  36. package/dist/types/trade/trade-client.d.ts +10 -2
  37. package/dist/types/version.d.ts +1 -1
  38. package/package.json +2 -3
  39. package/dist/cjs/auth/authentication.js +0 -74
  40. package/dist/cjs/auth/index.js +0 -24
  41. package/dist/cjs/auth/oauth2/client-registration.js +0 -44
  42. package/dist/cjs/auth/oauth2/device-authorization.js +0 -40
  43. package/dist/cjs/auth/oauth2/errors.js +0 -64
  44. package/dist/cjs/auth/oauth2/http-utils.js +0 -112
  45. package/dist/cjs/auth/oauth2/index.js +0 -42
  46. package/dist/cjs/auth/oauth2/loopback-receiver.js +0 -215
  47. package/dist/cjs/auth/oauth2/metadata.js +0 -34
  48. package/dist/cjs/auth/oauth2/oauth2-authentication.js +0 -74
  49. package/dist/cjs/auth/oauth2/session-manager.js +0 -762
  50. package/dist/cjs/auth/oauth2/token-store.js +0 -252
  51. package/dist/cjs/auth/oauth2/token.js +0 -76
  52. package/dist/esm/auth/authentication.js +0 -68
  53. package/dist/esm/auth/index.js +0 -3
  54. package/dist/esm/auth/oauth2/client-registration.js +0 -40
  55. package/dist/esm/auth/oauth2/device-authorization.js +0 -36
  56. package/dist/esm/auth/oauth2/errors.js +0 -59
  57. package/dist/esm/auth/oauth2/http-utils.js +0 -105
  58. package/dist/esm/auth/oauth2/index.js +0 -11
  59. package/dist/esm/auth/oauth2/loopback-receiver.js +0 -178
  60. package/dist/esm/auth/oauth2/metadata.js +0 -30
  61. package/dist/esm/auth/oauth2/oauth2-authentication.js +0 -70
  62. package/dist/esm/auth/oauth2/session-manager.js +0 -725
  63. package/dist/esm/auth/oauth2/token-store.js +0 -214
  64. package/dist/esm/auth/oauth2/token.js +0 -71
  65. package/dist/types/auth/authentication.d.ts +0 -98
  66. package/dist/types/auth/index.d.ts +0 -4
  67. package/dist/types/auth/oauth2/client-registration.d.ts +0 -32
  68. package/dist/types/auth/oauth2/device-authorization.d.ts +0 -40
  69. package/dist/types/auth/oauth2/errors.d.ts +0 -46
  70. package/dist/types/auth/oauth2/http-utils.d.ts +0 -21
  71. package/dist/types/auth/oauth2/index.d.ts +0 -16
  72. package/dist/types/auth/oauth2/loopback-receiver.d.ts +0 -29
  73. package/dist/types/auth/oauth2/metadata.d.ts +0 -32
  74. package/dist/types/auth/oauth2/oauth2-authentication.d.ts +0 -31
  75. package/dist/types/auth/oauth2/session-manager.d.ts +0 -241
  76. package/dist/types/auth/oauth2/token-store.d.ts +0 -49
  77. package/dist/types/auth/oauth2/token.d.ts +0 -56
package/README.md CHANGED
@@ -8,6 +8,7 @@ TypeScript SDK for Tiger Brokers OpenAPI — market data, trading, account manag
8
8
  ## Features
9
9
 
10
10
  - Market data queries (quotes, klines, depth, options, futures)
11
+ - News queries for a single stock and market highlights
11
12
  - Order placement, modification, cancellation, and account queries
12
13
  - Real-time push via TCP + TLS + Protobuf (quotes, trades, account events)
13
14
  - RSA request signing and Tiger public key response verification
@@ -167,6 +168,19 @@ const exchanges = await qc.futureExchange();
167
168
 
168
169
  ## Trading
169
170
 
171
+ Use `getContractV3` to query one trading contract with API version 3.0. Options require the underlying symbol, expiry, strike, and right. The result is a single contract or `undefined` when absent. `orderCapabilities` is available when returned by the account's trading service. The legacy `getContract(symbol, secType)` keeps its API 2.0 list response.
172
+
173
+ ```typescript
174
+ import { TradeClient, type ContractRequest } from '@tigeropenapi/tigeropen';
175
+
176
+ const trade = TradeClient.fromConfig(config, config.account, config.secretKey);
177
+ const request: ContractRequest = {
178
+ symbol: 'AAPL', secType: 'OPT', expiry: '20270115', strike: 200, right: 'CALL',
179
+ };
180
+ const contract = await trade.getContractV3(request);
181
+ console.log(contract?.orderCapabilities);
182
+ ```
183
+
170
184
  ```typescript
171
185
  import { HttpClient } from '@tigeropenapi/tigeropen/client/http-client';
172
186
  import { TradeClient } from '@tigeropenapi/tigeropen/trade/trade-client';
@@ -207,6 +221,77 @@ const positions = await tc.positions();
207
221
  const assets = await tc.assets();
208
222
  ```
209
223
 
224
+ ## News
225
+
226
+ The SDK exposes two news query APIs. Both are routed to the **main gateway** (never the quote server):
227
+
228
+ | API | method | Description |
229
+ |-----|--------|-------------|
230
+ | Stock news | `news_stock_list` | News list for a single symbol, paged by `pageCount` / `pageSize` |
231
+ | Market highlights | `news_highlight_list` | Market highlights, paged by the `lastId` cursor |
232
+
233
+ ```typescript
234
+ import { createClientConfig } from '@tigeropenapi/tigeropen';
235
+ import { NewsClient } from '@tigeropenapi/tigeropen';
236
+
237
+ const config = createClientConfig();
238
+ const nc = NewsClient.fromConfig(config); // main-gateway routing
239
+
240
+ // Stock news for a single symbol
241
+ const page = await nc.getStockNews({ symbol: 'AAPL', lang: 'zh_CN', pageCount: 1, pageSize: 20 });
242
+ for (const item of page.items) {
243
+ console.log(item.title, '—', item.url);
244
+ }
245
+
246
+ // Market highlights (first page starts from the newest)
247
+ const highlights = await nc.getMarketNews({ lang: 'zh_CN' });
248
+ // Next page: pass the id of the last item back as lastId
249
+ const lastId = highlights.items[highlights.items.length - 1]?.id;
250
+ const nextPage = await nc.getMarketNews({ lastId });
251
+ ```
252
+
253
+ ### Stock News
254
+
255
+ Parameters:
256
+
257
+ | Parameter | Required | Description |
258
+ |-----------|:--------:|-------------|
259
+ | `symbol` | Yes | Stock symbol. **Single symbol only** (batch queries are not supported) |
260
+ | `lang` | No | `zh_CN` / `zh_TW` / `en_US` |
261
+ | `pageCount` | No | Page number, default 1, must be >= 1 |
262
+ | `pageSize` | No | Page size, default 20, range 1–50 |
263
+
264
+ ### Market Highlights
265
+
266
+ Parameters:
267
+
268
+ | Parameter | Required | Description |
269
+ |-----------|:--------:|-------------|
270
+ | `lang` | No | Same as above |
271
+ | `lastId` | No | Cursor. Omit to start from the newest; pass the `id` of the last item of the current page to get the next page. This is the only pagination path (the API has no `pageCount` / `pageSize`) |
272
+
273
+ ### Response Structure
274
+
275
+ Both APIs return the same `NewsPage` shape:
276
+
277
+ | Field | Type | Description |
278
+ |-------|------|-------------|
279
+ | `items` | `NewsItem[]` | News items on the current page (empty items is a successful response) |
280
+ | `pageCount` | number | Current page number (always 1 for market highlights) |
281
+ | `pageSize` | number | Page size |
282
+ | `totalPage` | number | Total number of pages |
283
+ | `totalSize` | number | Total number of items |
284
+
285
+ `NewsItem`:
286
+
287
+ | Field | Type | Description |
288
+ |-------|------|-------------|
289
+ | `id` | string | News ID (also the `lastId` cursor source for highlights) |
290
+ | `title` | string | Title |
291
+ | `summary` | string | Summary |
292
+ | `pubTimestamp` | number | Publish timestamp in seconds |
293
+ | `url` | string | Link to the original article |
294
+
210
295
  ## Generic Execute
211
296
 
212
297
  For APIs not yet wrapped by the SDK, use `HttpClient.execute` directly:
@@ -305,6 +390,7 @@ openapi-typescript-sdk/
305
390
  │ ├── model/ # Data models and order helpers
306
391
  │ ├── quote/ # Quote client (market data)
307
392
  │ ├── trade/ # Trade client (orders, positions, assets)
393
+ │ ├── news/ # News client (stock news, market highlights)
308
394
  │ ├── push/ # TCP+TLS push client (Protobuf)
309
395
  │ ├── logger/ # Logger
310
396
  │ └── index.ts # Public exports
@@ -345,6 +431,7 @@ const { createClientConfig } = require('@tigeropenapi/tigeropen');
345
431
  ## 功能特性
346
432
 
347
433
  - 行情查询(报价、K 线、深度、期权、期货)
434
+ - 资讯查询(个股新闻、市场要闻)
348
435
  - 订单操作(下单、改单、撤单)和账户查询
349
436
  - 实时推送:TCP + TLS + Protobuf(行情、成交、账户事件)
350
437
  - RSA 请求签名和老虎公钥响应验签
@@ -597,6 +684,77 @@ const positions = await tc.positions();
597
684
  const assets = await tc.assets();
598
685
  ```
599
686
 
687
+ ## 资讯查询
688
+
689
+ SDK 提供两个资讯查询接口,均路由到**主网关**(不走行情域名):
690
+
691
+ | 接口 | method | 说明 |
692
+ |------|--------|------|
693
+ | 个股新闻 | `news_stock_list` | 查询单只股票的资讯列表,按 `pageCount` / `pageSize` 翻页 |
694
+ | 市场要闻 | `news_highlight_list` | 查询市场要闻列表,按 `lastId` 游标翻页 |
695
+
696
+ ```typescript
697
+ import { createClientConfig } from '@tigeropenapi/tigeropen';
698
+ import { NewsClient } from '@tigeropenapi/tigeropen';
699
+
700
+ const config = createClientConfig();
701
+ const nc = NewsClient.fromConfig(config); // 主网关路由
702
+
703
+ // 个股新闻(单标的)
704
+ const page = await nc.getStockNews({ symbol: 'AAPL', lang: 'zh_CN', pageCount: 1, pageSize: 20 });
705
+ for (const item of page.items) {
706
+ console.log(item.title, '—', item.url);
707
+ }
708
+
709
+ // 市场要闻(不传 lastId 从最新开始)
710
+ const highlights = await nc.getMarketNews({ lang: 'zh_CN' });
711
+ // 下一页:把本页最后一条的 id 作为 lastId 传回
712
+ const lastId = highlights.items[highlights.items.length - 1]?.id;
713
+ const nextPage = await nc.getMarketNews({ lastId });
714
+ ```
715
+
716
+ ### 个股新闻
717
+
718
+ 参数说明:
719
+
720
+ | 参数 | 必填 | 说明 |
721
+ |------|:----:|------|
722
+ | `symbol` | 是 | 股票代码,**仅支持单只**(该接口不支持批量查询) |
723
+ | `lang` | 否 | 语言枚举:`zh_CN` / `zh_TW` / `en_US` |
724
+ | `pageCount` | 否 | 页码,默认 1,取值 >= 1 |
725
+ | `pageSize` | 否 | 每页条数,默认 20,取值 1–50 |
726
+
727
+ ### 市场要闻
728
+
729
+ 参数说明:
730
+
731
+ | 参数 | 必填 | 说明 |
732
+ |------|:----:|------|
733
+ | `lang` | 否 | 同上 |
734
+ | `lastId` | 否 | 游标。不传从最新开始;下一页传本页 `items` 最后一条的 `id`。这是唯一的翻页方式(该接口无 `pageCount` / `pageSize`) |
735
+
736
+ ### 响应结构
737
+
738
+ 两个接口返回同一 `NewsPage` 结构:
739
+
740
+ | 字段 | 类型 | 说明 |
741
+ |------|------|------|
742
+ | `items` | `NewsItem[]` | 当前页资讯列表(空 items 属正常成功返回) |
743
+ | `pageCount` | number | 当前页码(要闻接口恒为 1) |
744
+ | `pageSize` | number | 每页条数 |
745
+ | `totalPage` | number | 总页数 |
746
+ | `totalSize` | number | 总条数 |
747
+
748
+ `NewsItem`:
749
+
750
+ | 字段 | 类型 | 说明 |
751
+ |------|------|------|
752
+ | `id` | string | 资讯 ID(同时是要闻 `lastId` 游标的取值来源) |
753
+ | `title` | string | 标题 |
754
+ | `summary` | string | 摘要 |
755
+ | `pubTimestamp` | number | 发布时间戳(秒级) |
756
+ | `url` | string | 原文链接 |
757
+
600
758
  ## 通用执行
601
759
 
602
760
  对于 SDK 尚未封装的 API,可直接使用 `HttpClient.execute`:
@@ -694,6 +852,7 @@ openapi-typescript-sdk/
694
852
  │ ├── model/ # 数据模型和订单辅助函数
695
853
  │ ├── quote/ # 行情客户端
696
854
  │ ├── trade/ # 交易客户端(订单、持仓、资产)
855
+ │ ├── news/ # 资讯客户端(个股新闻、市场要闻)
697
856
  │ ├── push/ # TCP+TLS 推送客户端(Protobuf)
698
857
  │ ├── logger/ # 日志
699
858
  │ └── index.ts # 公共导出
@@ -7,10 +7,9 @@ exports.unmarshalData = unmarshalData;
7
7
  */
8
8
  const errors_1 = require("./errors");
9
9
  /**
10
- * Replaces bare int64 values (≥17 digits, not part of a float) with quoted
11
- * strings so they survive JSON.parse without precision loss.
12
- * 17+ digits are guaranteed to exceed Number.MAX_SAFE_INTEGER (≈9.007e15),
13
- * so 16-digit microsecond timestamps remain as numbers.
10
+ * Quotes bare integers outside Number's safe range before JSON.parse.
11
+ * Values are checked by range, including 16-digit order IDs; safe integers
12
+ * such as microsecond timestamps remain numbers. Floats are left unchanged.
14
13
  */
15
14
  function patchLargeIntegers(text) {
16
15
  const strings = [];
@@ -21,7 +20,9 @@ function patchLargeIntegers(text) {
21
20
  // Match bare integers preceded by a JSON structural character or line start,
22
21
  // not followed by decimal point or exponent (avoids matching float components).
23
22
  // The `m` flag makes `^` match line-start for multi-line JSON.
24
- const patched = masked.replace(/([:,\[{]|^)\s*(-?\d{17,})(?![.\deE])/gm, (full, prefix, num) => {
23
+ const patched = masked.replace(/([:,\[{]|^)\s*(-?\d{16,})(?![.\deE])/gm, (full, prefix, num) => {
24
+ if (Number.isSafeInteger(Number(num)))
25
+ return full;
25
26
  return prefix + '"' + num + '"';
26
27
  });
27
28
  return patched.replace(/\x01(\d+)\x01/g, (_, i) => strings[parseInt(i, 10)]);
package/dist/cjs/index.js CHANGED
@@ -10,13 +10,13 @@
10
10
  * - 配置层(config):ClientConfig、ConfigParser
11
11
  * - 认证层(signer):RSA 签名
12
12
  * - 传输层(client):HttpClient、重试策略
13
- * - 业务层(quote/trade):QuoteClient、TradeClient
13
+ * - 业务层(quote/trade/news):QuoteClient、TradeClient、NewsClient
14
14
  * - 推送层(push):PushClient
15
15
  *
16
16
  * @packageDocumentation
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
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.SANDBOX_TIGER_PUBLIC_KEY = exports.loadPropertiesFile = exports.createClientConfig = exports.VERSION = void 0;
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.NewsClient = exports.TradeClient = exports.parseOptionIdentifier = exports.QuoteClient = exports.classifyErrorCode = exports.TigerError = exports.HttpClient = exports.TokenManager = exports.SANDBOX_TIGER_PUBLIC_KEY = exports.loadPropertiesFile = exports.createClientConfig = exports.VERSION = void 0;
20
20
  /** SDK 版本号 */
21
21
  var version_1 = require("./version");
22
22
  Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_1.SDK_VERSION; } });
@@ -39,6 +39,8 @@ Object.defineProperty(exports, "QuoteClient", { enumerable: true, get: function
39
39
  Object.defineProperty(exports, "parseOptionIdentifier", { enumerable: true, get: function () { return quote_1.parseOptionIdentifier; } });
40
40
  var trade_1 = require("./trade");
41
41
  Object.defineProperty(exports, "TradeClient", { enumerable: true, get: function () { return trade_1.TradeClient; } });
42
+ var news_1 = require("./news");
43
+ Object.defineProperty(exports, "NewsClient", { enumerable: true, get: function () { return news_1.NewsClient; } });
42
44
  var push_1 = require("./push");
43
45
  Object.defineProperty(exports, "PushClient", { enumerable: true, get: function () { return push_1.PushClient; } });
44
46
  Object.defineProperty(exports, "ConnectionState", { enumerable: true, get: function () { return push_1.ConnectionState; } });
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * 资讯请求参数模型(wire: news_stock_list / news_highlight_list)。
4
+ *
5
+ * TypeScript 侧使用 camelCase,序列化时由 createApiRequest 自动转为
6
+ * snake_case(契约决策 #13:入参 snake_case)。可选字段不传时不出现在
7
+ * biz_content 中,由服务端取缺省值。
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * 资讯数据模型(news_stock_list / news_highlight_list 共用)。
4
+ *
5
+ * 服务端响应出参为 camelCase(契约决策 #13),与 TypeScript 字段名一致,
6
+ * 响应侧无需命名转换。
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NewsClient = void 0;
4
+ /**
5
+ * 资讯模块导出
6
+ */
7
+ var news_client_1 = require("./news-client");
8
+ Object.defineProperty(exports, "NewsClient", { enumerable: true, get: function () { return news_client_1.NewsClient; } });
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NewsClient = void 0;
4
+ /**
5
+ * NewsClient — 资讯客户端(news_stock_list / news_highlight_list)。
6
+ *
7
+ * 路由约定(对齐 Java SDK 的 MethodType.NEWS):
8
+ * 资讯接口走主网关(config.serverUrl,与交易域同一路由),**不走行情域名**
9
+ * (config.quoteServerUrl)。本 SDK 的路由在 HttpClient 构造期决定——
10
+ * QuoteClient 以 useQuoteServerUrl 指向行情域名,其余客户端(TradeClient、
11
+ * NewsClient)默认指向主网关——因此 NewsClient 永远不传 useQuoteServerUrl。
12
+ *
13
+ * 请求参数 TypeScript 侧 camelCase,自动转为 wire snake_case;响应出参为
14
+ * camelCase,无需转换。
15
+ */
16
+ const http_client_1 = require("../client/http-client");
17
+ const api_request_1 = require("../client/api-request");
18
+ const api_response_1 = require("../client/api-response");
19
+ /** 资讯客户端:个股新闻列表与市场要闻列表。 */
20
+ class NewsClient {
21
+ constructor(httpClient, options) {
22
+ this.httpClient = httpClient;
23
+ this.defaultLang = options?.lang || undefined;
24
+ }
25
+ /**
26
+ * 从 ClientConfig 直接创建 NewsClient——主网关路由,默认语言取
27
+ * config.language。
28
+ */
29
+ static fromConfig(config) {
30
+ // 资讯走主网关:不传 useQuoteServerUrl(对照 QuoteClient 的构造方式)。
31
+ return new NewsClient(new http_client_1.HttpClient(config), { lang: config.language });
32
+ }
33
+ /**
34
+ * 查询个股新闻列表(wire: news_stock_list)。
35
+ *
36
+ * @param req - symbol 必填(单标的,该接口不支持批量查询);
37
+ * pageCount / pageSize 可选(缺省服务端默认 1 / 20);
38
+ * lang 可选('zh_CN' / 'zh_TW' / 'en_US')
39
+ * @returns 分页信封 NewsPage;空列表属正常成功返回
40
+ */
41
+ async getStockNews(req) {
42
+ const page = await this.callInto('news_stock_list', {
43
+ symbol: req.symbol,
44
+ pageCount: req.pageCount,
45
+ pageSize: req.pageSize,
46
+ lang: this.resolveLang(req.lang),
47
+ });
48
+ return page ?? { items: [] };
49
+ }
50
+ /**
51
+ * 查询市场要闻列表(wire: news_highlight_list)。
52
+ *
53
+ * 翻页只走 lastId 游标:把上一页 items 最后一条的 id 作为 lastId 传入
54
+ * 即取下一页;不传从最新开始。本接口无 page_count / page_size,响应
55
+ * pageCount 恒为 1。
56
+ *
57
+ * @param req - 全部字段可选,不传即从最新开始
58
+ * @returns 分页信封 NewsPage;空列表属正常成功返回
59
+ */
60
+ async getMarketNews(req) {
61
+ const body = {};
62
+ if (req?.lastId !== undefined) {
63
+ body['lastId'] = req.lastId;
64
+ }
65
+ const lang = this.resolveLang(req?.lang);
66
+ if (lang !== undefined) {
67
+ body['lang'] = lang;
68
+ }
69
+ const page = await this.callInto('news_highlight_list', body);
70
+ return page ?? { items: [] };
71
+ }
72
+ /**
73
+ * 解析生效的 lang:显式传值原样透传,缺省回退客户端默认语言。
74
+ */
75
+ resolveLang(lang) {
76
+ return lang !== undefined ? lang : this.defaultLang;
77
+ }
78
+ async callInto(method, bizParams) {
79
+ const request = (0, api_request_1.createApiRequest)(method, bizParams);
80
+ const response = await this.httpClient.executeRequest(request);
81
+ return (0, api_response_1.unmarshalData)(response.data);
82
+ }
83
+ }
84
+ exports.NewsClient = NewsClient;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.11.6
4
+ // protoc-gen-ts_proto v2.11.8
5
5
  // protoc v5.28.3
6
6
  // source: QuoteBasicData.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -35,6 +35,9 @@ function createBaseQuoteBasicData() {
35
35
  minTick: undefined,
36
36
  mi: undefined,
37
37
  volumeDecimal: undefined,
38
+ cumVolume: undefined,
39
+ cumAmount: undefined,
40
+ session: undefined,
38
41
  };
39
42
  }
40
43
  exports.QuoteBasicData = {
@@ -108,6 +111,15 @@ exports.QuoteBasicData = {
108
111
  if (message.volumeDecimal !== undefined) {
109
112
  writer.uint32(233).double(message.volumeDecimal);
110
113
  }
114
+ if (message.cumVolume !== undefined) {
115
+ writer.uint32(240).sint64(message.cumVolume);
116
+ }
117
+ if (message.cumAmount !== undefined) {
118
+ writer.uint32(249).double(message.cumAmount);
119
+ }
120
+ if (message.session !== undefined) {
121
+ writer.uint32(258).string(message.session);
122
+ }
111
123
  return writer;
112
124
  },
113
125
  decode(input, length) {
@@ -278,6 +290,27 @@ exports.QuoteBasicData = {
278
290
  message.volumeDecimal = reader.double();
279
291
  continue;
280
292
  }
293
+ case 30: {
294
+ if (tag !== 240) {
295
+ break;
296
+ }
297
+ message.cumVolume = longToNumber(reader.sint64());
298
+ continue;
299
+ }
300
+ case 31: {
301
+ if (tag !== 249) {
302
+ break;
303
+ }
304
+ message.cumAmount = reader.double();
305
+ continue;
306
+ }
307
+ case 32: {
308
+ if (tag !== 258) {
309
+ break;
310
+ }
311
+ message.session = reader.string();
312
+ continue;
313
+ }
281
314
  }
282
315
  if ((tag & 7) === 4 || tag === 0) {
283
316
  break;
@@ -314,6 +347,9 @@ exports.QuoteBasicData = {
314
347
  message.minTick = object.minTick ?? undefined;
315
348
  message.mi = (object.mi !== undefined && object.mi !== null) ? QuoteData_1.QuoteData_Minute.fromPartial(object.mi) : undefined;
316
349
  message.volumeDecimal = object.volumeDecimal ?? undefined;
350
+ message.cumVolume = object.cumVolume ?? undefined;
351
+ message.cumAmount = object.cumAmount ?? undefined;
352
+ message.session = object.session ?? undefined;
317
353
  return message;
318
354
  },
319
355
  };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.11.6
4
+ // protoc-gen-ts_proto v2.11.8
5
5
  // protoc v5.28.3
6
6
  // source: QuoteData.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -40,6 +40,9 @@ function createBaseQuoteData() {
40
40
  minTick: undefined,
41
41
  mi: undefined,
42
42
  volumeDecimal: undefined,
43
+ cumVolume: undefined,
44
+ cumAmount: undefined,
45
+ session: undefined,
43
46
  };
44
47
  }
45
48
  exports.QuoteData = {
@@ -131,6 +134,15 @@ exports.QuoteData = {
131
134
  if (message.volumeDecimal !== undefined) {
132
135
  writer.uint32(233).double(message.volumeDecimal);
133
136
  }
137
+ if (message.cumVolume !== undefined) {
138
+ writer.uint32(240).sint64(message.cumVolume);
139
+ }
140
+ if (message.cumAmount !== undefined) {
141
+ writer.uint32(249).double(message.cumAmount);
142
+ }
143
+ if (message.session !== undefined) {
144
+ writer.uint32(258).string(message.session);
145
+ }
134
146
  return writer;
135
147
  },
136
148
  decode(input, length) {
@@ -343,6 +355,27 @@ exports.QuoteData = {
343
355
  message.volumeDecimal = reader.double();
344
356
  continue;
345
357
  }
358
+ case 30: {
359
+ if (tag !== 240) {
360
+ break;
361
+ }
362
+ message.cumVolume = longToNumber(reader.sint64());
363
+ continue;
364
+ }
365
+ case 31: {
366
+ if (tag !== 249) {
367
+ break;
368
+ }
369
+ message.cumAmount = reader.double();
370
+ continue;
371
+ }
372
+ case 32: {
373
+ if (tag !== 258) {
374
+ break;
375
+ }
376
+ message.session = reader.string();
377
+ continue;
378
+ }
346
379
  }
347
380
  if ((tag & 7) === 4 || tag === 0) {
348
381
  break;
@@ -385,6 +418,9 @@ exports.QuoteData = {
385
418
  message.minTick = object.minTick ?? undefined;
386
419
  message.mi = (object.mi !== undefined && object.mi !== null) ? exports.QuoteData_Minute.fromPartial(object.mi) : undefined;
387
420
  message.volumeDecimal = object.volumeDecimal ?? undefined;
421
+ message.cumVolume = object.cumVolume ?? undefined;
422
+ message.cumAmount = object.cumAmount ?? undefined;
423
+ message.session = object.session ?? undefined;
388
424
  return message;
389
425
  },
390
426
  };
@@ -245,8 +245,9 @@ class QuoteClient {
245
245
  * If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
246
246
  * @param limit - Maximum number of bars to return.
247
247
  * @param sortDir - Sort direction ('asc' or 'desc').
248
+ * @param withHourTrading - Include GTH/CURB minute bars; omitted preserves the server default.
248
249
  */
249
- async getOptionKline(identifiers, period, beginTime = -1, endTime = -1, timezone, limit, sortDir) {
250
+ async getOptionKline(identifiers, period, beginTime = -1, endTime = -1, timezone, limit, sortDir, withHourTrading) {
250
251
  const resolvedBegin = beginTime === 0 ? -1 : beginTime;
251
252
  const resolvedEnd = endTime === 0 ? -1 : endTime;
252
253
  const optionQuery = identifiers.map((id) => {
@@ -264,6 +265,8 @@ class QuoteClient {
264
265
  entry['limit'] = limit;
265
266
  if (sortDir !== undefined && sortDir !== '')
266
267
  entry['sort_dir'] = sortDir;
268
+ if (withHourTrading !== undefined)
269
+ entry['with_hour_trading'] = withHourTrading;
267
270
  return entry;
268
271
  });
269
272
  return this.callInto('option_kline', { option_query: optionQuery }, '2.0');
@@ -103,7 +103,7 @@ class TradeClient {
103
103
  startTokenAutoRefresh(refreshDurationSecs, checkIntervalMs, tokenWriter) {
104
104
  return tokenMethods.startTokenAutoRefresh(this.httpClient, refreshDurationSecs, checkIntervalMs, tokenWriter);
105
105
  }
106
- async callInto(method, bizParams) {
106
+ async callInto(method, bizParams, version) {
107
107
  // Inject secretKey into every request when available (institution accounts require it).
108
108
  // Individual methods that already set secretKey will not be overwritten (|| not &&).
109
109
  let params = bizParams;
@@ -113,7 +113,7 @@ class TradeClient {
113
113
  params = { ...p, secretKey: this.secretKey };
114
114
  }
115
115
  }
116
- const request = (0, api_request_1.createApiRequest)(method, params);
116
+ const request = (0, api_request_1.createApiRequest)(method, params, version);
117
117
  const response = await this.httpClient.executeRequest(request);
118
118
  return (0, api_response_1.unmarshalData)(response.data);
119
119
  }
@@ -125,11 +125,21 @@ class TradeClient {
125
125
  return wrap?.items ?? [];
126
126
  }
127
127
  // === Contracts ===
128
+ /** Legacy API 2.0 query. Use getContractV3 for account-specific option order capabilities. */
128
129
  async getContract(symbol, secType) {
129
130
  return this.callIntoItems('contract', {
130
131
  account: this.account, symbol, secType,
131
132
  });
132
133
  }
134
+ /**
135
+ * Query one trading contract with API version 3.0.
136
+ * Returns a single object, or undefined when no contract is returned.
137
+ * Order capabilities are available when supplied by the account's trading service.
138
+ */
139
+ async getContractV3(req) {
140
+ const contract = await this.callInto('contract', withAccount(req, this.account), '3.0');
141
+ return contract ?? undefined;
142
+ }
133
143
  async getContracts(symbols, secType) {
134
144
  return this.callIntoItems('contracts', {
135
145
  account: this.account, symbols, secType,
@@ -235,11 +245,23 @@ class TradeClient {
235
245
  }
236
246
  /**
237
247
  * Get a single order by ID (v0.4.0 new).
238
- * Returns `undefined` if no match.
248
+ * Wire method: `orders` with `id` / `order_id` parameters.
249
+ * Returns `undefined` if no match or the result contains multiple orders.
239
250
  */
240
251
  async getOrder(req) {
241
252
  const merged = withAccount(req, this.account);
242
- const out = await this.callInto('order_no', merged);
253
+ const data = await this.callInto('orders', merged);
254
+ let out;
255
+ if (Array.isArray(data)) {
256
+ out = data.length === 1 ? data[0] : undefined;
257
+ }
258
+ else if (data && typeof data === 'object' && 'items' in data) {
259
+ const items = data.items;
260
+ out = Array.isArray(items) && items.length === 1 ? items[0] : undefined;
261
+ }
262
+ else {
263
+ out = data;
264
+ }
243
265
  if (!out || (!out.id && !out.orderId))
244
266
  return undefined;
245
267
  normalizeOrderInPlace(out);
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = '0.5.7';
4
+ exports.SDK_VERSION = '0.5.9';
@@ -3,10 +3,9 @@
3
3
  */
4
4
  import { TigerError } from './errors.js';
5
5
  /**
6
- * Replaces bare int64 values (≥17 digits, not part of a float) with quoted
7
- * strings so they survive JSON.parse without precision loss.
8
- * 17+ digits are guaranteed to exceed Number.MAX_SAFE_INTEGER (≈9.007e15),
9
- * so 16-digit microsecond timestamps remain as numbers.
6
+ * Quotes bare integers outside Number's safe range before JSON.parse.
7
+ * Values are checked by range, including 16-digit order IDs; safe integers
8
+ * such as microsecond timestamps remain numbers. Floats are left unchanged.
10
9
  */
11
10
  function patchLargeIntegers(text) {
12
11
  const strings = [];
@@ -17,7 +16,9 @@ function patchLargeIntegers(text) {
17
16
  // Match bare integers preceded by a JSON structural character or line start,
18
17
  // not followed by decimal point or exponent (avoids matching float components).
19
18
  // The `m` flag makes `^` match line-start for multi-line JSON.
20
- const patched = masked.replace(/([:,\[{]|^)\s*(-?\d{17,})(?![.\deE])/gm, (full, prefix, num) => {
19
+ const patched = masked.replace(/([:,\[{]|^)\s*(-?\d{16,})(?![.\deE])/gm, (full, prefix, num) => {
20
+ if (Number.isSafeInteger(Number(num)))
21
+ return full;
21
22
  return prefix + '"' + num + '"';
22
23
  });
23
24
  return patched.replace(/\x01(\d+)\x01/g, (_, i) => strings[parseInt(i, 10)]);
package/dist/esm/index.js CHANGED
@@ -9,7 +9,7 @@
9
9
  * - 配置层(config):ClientConfig、ConfigParser
10
10
  * - 认证层(signer):RSA 签名
11
11
  * - 传输层(client):HttpClient、重试策略
12
- * - 业务层(quote/trade):QuoteClient、TradeClient
12
+ * - 业务层(quote/trade/news):QuoteClient、TradeClient、NewsClient
13
13
  * - 推送层(push):PushClient
14
14
  *
15
15
  * @packageDocumentation
@@ -25,6 +25,7 @@ export { TigerError, classifyErrorCode } from './client/index.js';
25
25
  // Clients
26
26
  export { QuoteClient, parseOptionIdentifier } from './quote/index.js';
27
27
  export { TradeClient } from './trade/index.js';
28
+ export { NewsClient } from './news/index.js';
28
29
  export { PushClient, ConnectionState, SubjectType } from './push/index.js';
29
30
  export { marketOrder, limitOrder, stopOrder, stopLimitOrder } from './model/order-helpers.js';
30
31
  export { normalizeOrderStatus } from './model/order-status.js';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 资讯请求参数模型(wire: news_stock_list / news_highlight_list)。
3
+ *
4
+ * TypeScript 侧使用 camelCase,序列化时由 createApiRequest 自动转为
5
+ * snake_case(契约决策 #13:入参 snake_case)。可选字段不传时不出现在
6
+ * biz_content 中,由服务端取缺省值。
7
+ */
8
+ export {};