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
@@ -5,14 +5,19 @@
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 type { HttpClient } from '../client/http-client';
9
- import type { MarketState, Brief, Kline, KlineItem, Timeline, TradeTick, Depth, OptionExpiration, OptionChain, FutureExchange, FutureContractInfo, FutureQuote, FutureKline, FutureKlineItem, FinancialDailyItem, FinancialReportItem, CorporateAction, CapitalFlow, CapitalDistribution, ScannerResult, QuotePermission, FinancialDailyRequest, FinancialReportRequest, CorporateActionRequest, FutureKlineRequest, 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 } from '../model/quote';
10
- import type { BriefRequest, DepthQuoteRequest, TradeTickRequest, FutureBriefRequest, SymbolsRequest, TradeMetasRequest, StockDetailsRequest, StockDelayBriefsRequest, BarsRequest, BarsByPageRequest, TimelineHistoryRequest, TradeRankRequest, ShortInterestRequest, StockBrokerRequest, StockFundamentalRequest, StockIndustryRequest, KlineQuotaRequest, QuotePermissionRequest, OptionBarsRequest, OptionTradeTicksRequest, OptionTimelineRequest, OptionDepthRequest, OptionSymbolsRequest, OptionAnalysisRequest, FutureContractSingleRequest, AllFutureContractsRequest, FutureContinuousContractsRequest, FutureHistoryMainContractRequest, FutureBarsRequest, FutureBarsByPageRequest, FutureTradeTicksRequest, FutureDepthRequest, FutureTradingTimesRequest, FundSymbolsRequest, FundContractsRequest, FundQuoteRequest, FundHistoryQuoteRequest, WarrantBriefsRequest, WarrantFilterRequest, IndustryListRequest, IndustryStocksRequest, TradingCalendarRequest, FinancialExchangeRateRequest, FinancialCurrencyRequest, MarketScannerTagsRequest, QuoteOvernightRequest } from '../model/quote-requests';
8
+ import { HttpClient } from '../client/http-client';
9
+ import type { ClientConfig } from '../config/client-config';
10
+ import type { TokenManager } from '../config/token-manager';
11
+ import type { MarketState, Brief, Kline, KlineItem, Timeline, TradeTick, Depth, OptionExpiration, OptionChain, OptionChainFilter, FutureExchange, FutureContractInfo, FutureQuote, FutureKline, FutureKlineItem, FinancialDailyItem, FinancialReportItem, CorporateAction, CorporateSymbolChange, CorporateDelisting, CorporateIPO, 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, MarketScannerTagGroup, FundContractInfo, FundQuote, FundHistoryQuote, FinancialDailyRequest, FinancialReportRequest, CorporateActionRequest } from '../model/quote';
12
+ import type { BriefRequest, DepthQuoteRequest, TradeTickRequest, FutureBriefRequest, SymbolsRequest, TradeMetasRequest, StockDetailsRequest, StockDelayBriefsRequest, KlineRequest, KlineByPageRequest, TimelineRequest, 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
13
  /**
12
14
  * Parse an OCC-style option identifier like "AAPL 260619C00150000"
13
15
  * into its component parts.
16
+ *
17
+ * @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
18
+ * If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
14
19
  */
15
- export declare function parseOptionIdentifier(identifier: string): {
20
+ export declare function parseOptionIdentifier(identifier: string, timezone?: string): {
16
21
  symbol: string;
17
22
  expiryMs: number;
18
23
  right: string;
@@ -22,6 +27,20 @@ export declare function parseOptionIdentifier(identifier: string): {
22
27
  export declare class QuoteClient {
23
28
  private httpClient;
24
29
  constructor(httpClient: HttpClient);
30
+ /** Create a QuoteClient directly from a ClientConfig — no need to construct HttpClient manually. */
31
+ static fromConfig(config: ClientConfig): QuoteClient;
32
+ /** Call the `user_token_refresh` API and return the new token. Read-only. */
33
+ queryToken(): Promise<string>;
34
+ /** Refresh the token and update the in-memory config token. */
35
+ refreshToken(tokenManager?: TokenManager | null): Promise<void>;
36
+ /**
37
+ * Start background token auto-refresh. Returns a TokenManager to stop with `tm.stopAutoRefresh()`.
38
+ *
39
+ * @param refreshDurationSecs - Refresh threshold in seconds (minimum 30).
40
+ * @param checkIntervalMs - How often to check, in milliseconds (default 300 000 / 5 min).
41
+ * @param tokenWriter - Optional callback invoked after each successful refresh.
42
+ */
43
+ startTokenAutoRefresh(refreshDurationSecs: number, checkIntervalMs?: number, tokenWriter?: (token: string) => void): TokenManager;
25
44
  private callInto;
26
45
  /**
27
46
  * Some endpoints return either a list or a single object depending on the
@@ -32,25 +51,49 @@ export declare class QuoteClient {
32
51
  /** Unwrap server {"items":[...]} envelope. */
33
52
  private callIntoItems;
34
53
  getMarketState(market: string): Promise<MarketState[]>;
35
- /** Real-time stock briefs. wire: quote_real_time */
54
+ /** Real-time stock quotes. wire: quote_real_time */
55
+ getRealTimeQuote(req: BriefRequest): Promise<Brief[]>;
56
+ /** @deprecated Use getRealTimeQuote instead. */
36
57
  getBrief(req: BriefRequest): Promise<Brief[]>;
37
- getKline(symbol: string, period: string): Promise<Kline[]>;
58
+ getKline(req: KlineRequest): Promise<Kline[]>;
38
59
  getTimeline(symbols: string[]): Promise<Timeline[]>;
60
+ getTimeline(req: TimelineRequest): Promise<Timeline[]>;
39
61
  /** Tick-by-tick trades. wire: trade_tick */
40
62
  getTradeTick(req: TradeTickRequest): Promise<TradeTick[]>;
41
63
  /** Depth snapshot. wire: quote_depth */
42
64
  getQuoteDepth(req: DepthQuoteRequest): Promise<Depth[]>;
43
- getOptionExpiration(symbol: string): Promise<OptionExpiration[]>;
44
- /** Option chain; `expiry` is "YYYY-MM-DD". */
45
- getOptionChain(symbol: string, expiry: string): Promise<OptionChain[]>;
65
+ getOptionExpiration(symbols: string[], market?: string): Promise<OptionExpiration[]>;
66
+ /**
67
+ * Option chain; each item is [symbol, "YYYY-MM-DD"].
68
+ *
69
+ * @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
70
+ * If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
71
+ * @param returnGreekValue - Whether to return Greeks (delta/gamma/theta/vega/rho).
72
+ * @param optionFilter - Optional filter for in-the-money status, IV range, open interest range, Greeks ranges.
73
+ */
74
+ getOptionChain(items: Array<[string, string]>, timezone?: string, returnGreekValue?: boolean, optionFilter?: OptionChainFilter): Promise<OptionChain[]>;
75
+ /**
76
+ * Option K-line by OCC-style identifier.
77
+ *
78
+ * @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
79
+ * If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
80
+ * @param limit - Maximum number of bars to return.
81
+ * @param sortDir - Sort direction ('asc' or 'desc').
82
+ */
83
+ getOptionKline(identifiers: string[], period: string, beginTime?: number, endTime?: number, timezone?: string, limit?: number, sortDir?: string): Promise<Kline[]>;
84
+ /**
85
+ * Real-time option quotes by OCC-style identifier.
86
+ *
87
+ * @param timezone - Optional IANA timezone for expiry conversion (e.g. 'America/New_York').
88
+ * If omitted, defaults to America/New_York for US symbols and Asia/Hong_Kong for .HK symbols.
89
+ */
90
+ getOptionQuote(identifiers: string[], timezone?: string): Promise<Brief[]>;
91
+ /** @deprecated Use getOptionQuote instead. */
46
92
  getOptionBrief(identifiers: string[]): Promise<Brief[]>;
47
- getOptionKline(identifier: string, period: string): Promise<Kline[]>;
48
93
  getFutureExchange(): Promise<FutureExchange[]>;
49
94
  getFutureContracts(exchange: string): Promise<FutureContractInfo[]>;
50
95
  /** Real-time futures quotes. wire: future_real_time_quote */
51
96
  getFutureRealTimeQuote(req: FutureBriefRequest): Promise<FutureQuote[]>;
52
- /** Futures K-line; use -1 for unbounded beginTime / endTime. */
53
- getFutureKline(req: FutureKlineRequest): Promise<FutureKline[]>;
54
97
  getFinancialDaily(req: FinancialDailyRequest): Promise<FinancialDailyItem[]>;
55
98
  getFinancialReport(req: FinancialReportRequest): Promise<FinancialReportItem[]>;
56
99
  /**
@@ -69,16 +112,12 @@ export declare class QuoteClient {
69
112
  getTradeMetas(req: TradeMetasRequest): Promise<TradeMeta[]>;
70
113
  /** Stock details. wire: stock_detail. Server returns {items:[...]}. */
71
114
  getStockDetails(req: StockDetailsRequest): Promise<StockDetail[]>;
72
- /** Delayed stock briefs. wire: quote_delay */
115
+ /** Delayed stock quotes. wire: quote_delay */
116
+ getDelayedQuote(req: StockDelayBriefsRequest): Promise<Brief[]>;
117
+ /** @deprecated Use getDelayedQuote instead. */
73
118
  getStockDelayBriefs(req: StockDelayBriefsRequest): Promise<Brief[]>;
74
- /** K-line bars (full request). wire: kline */
75
- getBars(req: BarsRequest): Promise<Kline[]>;
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[]>;
119
+ /** Client-side paginated K-line fetch. Loops until totalSize bars are collected, oldest-first. */
120
+ getKlineByPage(req: KlineByPageRequest): Promise<KlineItem[]>;
82
121
  /** Historical intraday timeline. wire: history_timeline */
83
122
  getTimelineHistory(req: TimelineHistoryRequest): Promise<Timeline[]>;
84
123
  /** Trade rank (top movers / volume). wire: trade_rank */
@@ -91,13 +130,18 @@ export declare class QuoteClient {
91
130
  getStockFundamental(req: StockFundamentalRequest): Promise<Record<string, unknown>>;
92
131
  /** Stock industry classification (array). wire: stock_industry */
93
132
  getStockIndustry(req: StockIndustryRequest): Promise<StockIndustry[]>;
94
- /** Quote permission detail. wire: get_quote_permission */
133
+ /** Market data permission entries. wire: get_quote_permission */
95
134
  getQuotePermission(req: QuotePermissionRequest): Promise<QuotePermission[]>;
96
135
  /** K-line quota usage. wire: kline_quota */
97
136
  getKlineQuota(req: KlineQuotaRequest): Promise<KlineQuota[]>;
98
- /** Option K-line. wire: option_kline (v2.0) */
99
- getOptionBars(req: OptionBarsRequest): Promise<Kline[]>;
100
- /** Option tick trades. wire: option_trade_tick */
137
+ /** Option tick trades. wire: option_trade_tick
138
+ *
139
+ * Server expects `biz_content` as a top-level JSON array (matches Java's
140
+ * `BatchApiModel` and Python's `MultipleContractParams.to_openapi_dict`).
141
+ * We unwrap the request here so the array is emitted directly instead of
142
+ * `{"contracts": [...]}`. Sending it as an object triggers
143
+ * `biz param error(failed to parse parameters in 'biz_content')`.
144
+ */
101
145
  getOptionTradeTicks(req: OptionTradeTicksRequest): Promise<TradeTick[]>;
102
146
  /** Option intraday timeline. wire: option_timeline */
103
147
  getOptionTimeline(req: OptionTimelineRequest): Promise<Timeline[]>;
@@ -117,14 +161,16 @@ export declare class QuoteClient {
117
161
  getFutureContinuousContracts(req: FutureContinuousContractsRequest): Promise<FutureContractInfo[]>;
118
162
  /** Historical main contracts. wire: future_main_contract */
119
163
  getFutureHistoryMainContract(req: FutureHistoryMainContractRequest): Promise<FutureMainContractHistory[]>;
120
- /**
121
- * Futures K-line (full request with index pagination). wire: future_kline
122
- * begin_time / end_time default to -1 when unset (server requires them present).
123
- */
124
- getFutureBars(req: FutureBarsRequest): Promise<FutureKline[]>;
164
+ /** Futures K-line. wire: future_kline
165
+ * beginTime / endTime default to -1 when unset (server requires them present).
166
+ * Server expects `contract_codes` (plural) — normalize singular `contractCode`
167
+ * to the plural form so callers can pass either shape. */
168
+ getFutureKline(req: FutureKlineRequest): Promise<FutureKline[]>;
125
169
  /** Client-side paginated futures K-line fetch. */
126
- getFutureBarsByPage(req: FutureBarsByPageRequest): Promise<FutureKlineItem[]>;
127
- /** Futures tick trades. wire: future_tick (API v3.0) */
170
+ getFutureKlineByPage(req: FutureKlineByPageRequest): Promise<FutureKlineItem[]>;
171
+ /** Futures tick trades. wire: future_tick (API v3.0)
172
+ * Server returns {contractCode, items:[...]}; unwrap items and backfill contractCode.
173
+ * endIndex defaults to 30 when not set (consistent with Python/Go SDK). */
128
174
  getFutureTradeTicks(req: FutureTradeTicksRequest): Promise<FutureTradeTickItem[]>;
129
175
  /** Futures depth. wire: future_depth */
130
176
  getFutureDepth(req: FutureDepthRequest): Promise<FutureDepth[]>;
@@ -138,12 +184,25 @@ export declare class QuoteClient {
138
184
  getFundQuote(req: FundQuoteRequest): Promise<FundQuote[]>;
139
185
  /** Fund historical NAV. wire: fund_history_quote */
140
186
  getFundHistoryQuote(req: FundHistoryQuoteRequest): Promise<FundHistoryQuote[]>;
141
- /** Warrant briefs. wire: warrant_briefs */
187
+ /** Real-time warrant quotes. wire: warrant_briefs */
188
+ getWarrantQuote(req: WarrantBriefsRequest): Promise<WarrantBrief[]>;
189
+ /** @deprecated Use getWarrantQuote instead. */
142
190
  getWarrantBriefs(req: WarrantBriefsRequest): Promise<WarrantBrief[]>;
143
191
  /** Warrant filter (paged). wire: warrant_filter */
144
192
  getWarrantFilter(req: WarrantFilterRequest): Promise<WarrantFilterResult | undefined>;
145
- /** Industry list. wire: industry_list */
146
- getIndustryList(req: IndustryListRequest): Promise<IndustryItem[]>;
193
+ /** Industry list. wire: industry_list
194
+ *
195
+ * `industryLevel` is required by the server — omitting it returns
196
+ * `industry level error, all supported is: [GSECTOR, GGROUP, GIND, GSUBIND]`.
197
+ * Defaults to `GGROUP` when unset, matching Python SDK's
198
+ * `IndustryLevel.GGROUP` default.
199
+ *
200
+ * Wire fields differ from other endpoints (see `IndustryItem`): server sends
201
+ * `nameCN` / `nameEN` / `industryLevel`. This method hydrates the
202
+ * backwards-compat `name` (from `nameEN || nameCN`) and mirrors
203
+ * `industryLevel` to `level` so existing callers keep working.
204
+ */
205
+ getIndustryList(req?: IndustryListRequest): Promise<IndustryItem[]>;
147
206
  /** Stocks inside an industry. wire: industry_stock_list */
148
207
  getIndustryStocks(req: IndustryStocksRequest): Promise<IndustryStock[]>;
149
208
  /** Corporate split (flattened). wire: corporate_action (action_type=split) */
@@ -152,6 +211,12 @@ export declare class QuoteClient {
152
211
  getCorporateDividend(req: CorporateActionRequest): Promise<CorporateAction[]>;
153
212
  /** Corporate earnings calendar (flattened). wire: corporate_action (action_type=earning) */
154
213
  getCorporateEarningsCalendar(req: CorporateActionRequest): Promise<CorporateAction[]>;
214
+ /** Corporate symbol change (flattened). wire: corporate_action (action_type=symbol_change) */
215
+ getCorporateSymbolChange(req: Omit<CorporateActionRequest, 'actionType'>): Promise<CorporateSymbolChange[]>;
216
+ /** Corporate delisting (flattened). wire: corporate_action (action_type=delisting) */
217
+ getCorporateDelisting(req: Omit<CorporateActionRequest, 'actionType'>): Promise<CorporateDelisting[]>;
218
+ /** Corporate IPO (flattened). wire: corporate_action (action_type=ipo) */
219
+ getCorporateIPO(req: Omit<CorporateActionRequest, 'actionType'>): Promise<CorporateIPO[]>;
155
220
  /** Financial currency per symbol. wire: financial_currency */
156
221
  getFinancialCurrency(req: FinancialCurrencyRequest): Promise<FinancialCurrency[]>;
157
222
  /** FX rates. wire: financial_exchange_rate */
@@ -159,7 +224,7 @@ export declare class QuoteClient {
159
224
  /** Trading calendar. wire: trading_calendar */
160
225
  getTradingCalendar(req: TradingCalendarRequest): Promise<TradingCalendarItem[]>;
161
226
  /** Available market-scanner tags. wire: market_scanner_tags */
162
- getMarketScannerTags(req: MarketScannerTagsRequest): Promise<MarketScannerTags | undefined>;
227
+ getMarketScannerTags(req: MarketScannerTagsRequest): Promise<MarketScannerTagGroup[]>;
163
228
  /** Overnight quote. wire: quote_overnight */
164
229
  getQuoteOvernight(req: QuoteOvernightRequest): Promise<QuoteOvernight[]>;
165
230
  }
@@ -7,17 +7,40 @@
7
7
  * v0.4.0: 所有查询类方法改为 Request 对象签名(OrdersRequest 等),补齐 17
8
8
  * 个新方法(账户管理 / 资产分析 / 资金调拨 / 持仓划转等)。
9
9
  */
10
- import type { HttpClient } from '../client/http-client';
10
+ import { HttpClient } from '../client/http-client';
11
+ import type { ClientConfig } from '../config/client-config';
12
+ import type { TokenManager } from '../config/token-manager';
11
13
  import type { OrderRequest, Order } from '../model/order';
12
14
  import type { Contract } from '../model/contract';
13
15
  import type { Position } from '../model/position';
14
- import type { Asset, PrimeAsset, PreviewResult, PlaceOrderResult, OrderIdResult, Transaction, ManagedAccount, AnalyticsAsset, AggregateAssets, EstimateTradableQuantity, ForexOrderResult, SegmentFund, SegmentFundHistoryItem, FundDetails, FundingHistoryItem, PositionTransferRecord, PositionTransferDetail, PositionTransferExternalRecord } from '../model/trade';
15
- import type { OrdersRequest, GetOrderRequest, OrderTransactionsRequest, PositionsRequest, AssetsRequest, ManagedAccountsRequest, DerivativeContractsRequest, AnalyticsAssetRequest, AggregateAssetsRequest, EstimateTradableQuantityRequest, ForexOrderRequest, SegmentFundRequest, FundDetailsRequest, FundingHistoryRequest, PositionTransferRequest, PositionTransferRecordsRequest, PositionTransferDetailRequest, PositionTransferExternalRecordsRequest } from '../model/trade-requests';
16
+ import type { Asset, PrimeAsset, PreviewResult, PlaceOrderResult, OrderIdResult, Transaction, ManagedAccount, AnalyticsAsset, AggregateAssets, EstimateTradableQuantity, ForexOrderResult, SegmentFund, SegmentFundAvailableItem, SegmentFundHistoryItem, FundDetails, FundingHistoryItem, PositionTransferRecord, PositionTransferDetail, PositionTransferExternalRecord, OptionExerciseCheckResult, OptionExercisePositionPageResult, OptionExerciseRecordPageResult } from '../model/trade';
17
+ import 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';
16
18
  /** Trading client wrapping all trade-related APIs. */
17
19
  export declare class TradeClient {
18
20
  private httpClient;
19
21
  private account;
20
- constructor(httpClient: HttpClient, account: string);
22
+ private secretKey?;
23
+ constructor(httpClient: HttpClient, account: string, secretKey?: string);
24
+ /** Create a TradeClient directly from a ClientConfig — no need to construct HttpClient manually. */
25
+ static fromConfig(config: ClientConfig, account: string, secretKey?: string): TradeClient;
26
+ /** Call the `user_token_refresh` API and return the new token. Read-only. */
27
+ queryToken(): Promise<string>;
28
+ /**
29
+ * Refresh the token: call the API, update the in-memory config token, and
30
+ * optionally persist via the provided TokenManager (file + writer callback).
31
+ *
32
+ * @param tokenManager - optional TokenManager for file persistence and writer callback
33
+ */
34
+ refreshToken(tokenManager?: TokenManager | null): Promise<void>;
35
+ /**
36
+ * Start background token auto-refresh. Returns a TokenManager that can be
37
+ * used to stop the background task via `tm.stopAutoRefresh()`.
38
+ *
39
+ * @param refreshDurationSecs - Refresh threshold in seconds (minimum 30).
40
+ * @param checkIntervalMs - How often to check, in milliseconds (default 300 000 / 5 min).
41
+ * @param tokenWriter - Optional callback invoked after each successful refresh.
42
+ */
43
+ startTokenAutoRefresh(refreshDurationSecs: number, checkIntervalMs?: number, tokenWriter?: (token: string) => void): TokenManager;
21
44
  private callInto;
22
45
  /** Strip `{items: [...]}` envelope used by most trade read endpoints. */
23
46
  private callIntoItems;
@@ -28,10 +51,25 @@ export declare class TradeClient {
28
51
  * `symbol` is the underlying (e.g. "AAPL"); `expiry` is "YYYYMMDD".
29
52
  */
30
53
  getQuoteContract(symbol: string, secType: string, expiry: string): Promise<Contract[]>;
54
+ /**
55
+ * Prepare an order request for the wire.
56
+ *
57
+ * The gateway expects `algo_params` as a `[{tag, value}, ...]` array
58
+ * (matching the Python SDK's AlgoParams.to_dict serialization), not the
59
+ * plain object shape that reads naturally in TypeScript. This helper
60
+ * normalizes the object form into the array form on outbound payloads
61
+ * so callers can pass the natural object and TWAP/VWAP orders work end
62
+ * to end without wire-format workarounds.
63
+ *
64
+ * Fields with undefined/null values are dropped; empty algoParams
65
+ * becomes an empty array rather than being stripped, matching the
66
+ * Python SDK behavior when the user passes an empty AlgoParams().
67
+ */
68
+ private marshalOrderForWire;
31
69
  placeOrder(order: OrderRequest): Promise<PlaceOrderResult | undefined>;
32
70
  previewOrder(order: OrderRequest): Promise<PreviewResult | undefined>;
33
- modifyOrder(id: number, order: OrderRequest): Promise<OrderIdResult | undefined>;
34
- cancelOrder(id: number): Promise<OrderIdResult | undefined>;
71
+ modifyOrder(id: number | string, order: OrderRequest): Promise<OrderIdResult | undefined>;
72
+ cancelOrder(id: number | string, secretKey?: string): Promise<OrderIdResult | undefined>;
35
73
  /**
36
74
  * Query all historical orders. v0.4.0: optional OrdersRequest for filtering.
37
75
  *
@@ -58,9 +96,6 @@ export declare class TradeClient {
58
96
  getFilledOrders(req?: OrdersRequest): Promise<Order[]>;
59
97
  /**
60
98
  * Get a single order by ID (v0.4.0 new).
61
- * Wire method: `orders` with id/order_id param; server returns a single Order object
62
- * (not `{items:[]}` envelope).
63
- *
64
99
  * Returns `undefined` if no match.
65
100
  */
66
101
  getOrder(req: GetOrderRequest): Promise<Order | undefined>;
@@ -71,9 +106,15 @@ export declare class TradeClient {
71
106
  getOrderTransactions(req: OrderTransactionsRequest): Promise<Transaction[]>;
72
107
  /** Query positions. v0.4.0: supports Symbol / SecType / Currency / Market filters. */
73
108
  getPositions(req?: PositionsRequest): Promise<Position[]>;
74
- /** Query assets. v0.4.0: supports sub-account list and aggregation options. */
109
+ /**
110
+ * Query assets. v0.4.0: supports sub-account list and aggregation options.
111
+ * `assetQuoteType`(ETH / RTH / OVERNIGHT) 选择资产行情口径。
112
+ */
75
113
  getAssets(req?: AssetsRequest): Promise<Asset[]>;
76
- /** Query prime assets. v0.4.0: takes AssetsRequest for filters. */
114
+ /**
115
+ * Query prime assets. v0.4.0: takes AssetsRequest for filters.
116
+ * `assetQuoteType`(ETH / RTH / OVERNIGHT) 选择资产行情口径。
117
+ */
77
118
  getPrimeAssets(req?: AssetsRequest): Promise<PrimeAsset | undefined>;
78
119
  /** Query managed sub-accounts (institutional). */
79
120
  getManagedAccounts(req?: ManagedAccountsRequest): Promise<ManagedAccount[]>;
@@ -84,14 +125,17 @@ export declare class TradeClient {
84
125
  getDerivativeContracts(req: DerivativeContractsRequest): Promise<Contract[]>;
85
126
  /** Daily P&L / net-value / holding-value analytics. */
86
127
  getAnalyticsAsset(req: AnalyticsAssetRequest): Promise<AnalyticsAsset[]>;
87
- /** Aggregate assets (prime) by base currency. */
128
+ /**
129
+ * Aggregate assets (prime) by base currency.
130
+ * `assetQuoteType`(ETH / RTH / OVERNIGHT) 选择资产行情口径。
131
+ */
88
132
  getAggregateAssets(req?: AggregateAssetsRequest): Promise<AggregateAssets | undefined>;
89
133
  /** Estimate tradable quantity given order parameters. */
90
134
  getEstimateTradableQuantity(req: EstimateTradableQuantityRequest): Promise<EstimateTradableQuantity | undefined>;
91
135
  /** Place forex order (sub-account base-currency swap). */
92
136
  placeForexOrder(req: ForexOrderRequest): Promise<ForexOrderResult | undefined>;
93
137
  /** Query amount available for inter-segment transfer. Returns array. */
94
- getSegmentFundAvailable(req: SegmentFundRequest): Promise<SegmentFund[]>;
138
+ getSegmentFundAvailable(req: SegmentFundRequest): Promise<SegmentFundAvailableItem[]>;
95
139
  /** Query segment fund transfer history. Server returns plain array (no items wrapper). */
96
140
  getSegmentFundHistory(req: SegmentFundRequest): Promise<SegmentFundHistoryItem[]>;
97
141
  /** Execute an inter-segment fund transfer. */
@@ -100,7 +144,8 @@ export declare class TradeClient {
100
144
  cancelSegmentFund(req: SegmentFundRequest): Promise<SegmentFund | undefined>;
101
145
  /** Fund-movement details (by segment / currency / fund-type). */
102
146
  getFundDetails(req: FundDetailsRequest): Promise<FundDetails[]>;
103
- /** Funding history (wire method: `transfer_fund`). */
147
+ /** Funding history (wire method: `transfer_fund`).
148
+ * Server returns bare list (no items wrapper). */
104
149
  getFundingHistory(req: FundingHistoryRequest): Promise<FundingHistoryItem[]>;
105
150
  /**
106
151
  * Internal position transfer (cross sub-account).
@@ -113,4 +158,14 @@ export declare class TradeClient {
113
158
  getPositionTransferDetail(req: PositionTransferDetailRequest): Promise<PositionTransferDetail | undefined>;
114
159
  /** Query external position transfer records (DWAC / FOP / etc.). */
115
160
  getPositionTransferExternalRecords(req: PositionTransferExternalRecordsRequest): Promise<PositionTransferExternalRecord[]>;
161
+ /** 行权检验:预估行权/作废后正股持仓变化 (wire: option_exercise_check) */
162
+ checkOptionExercise(req: OptionExerciseCheckRequest): Promise<OptionExerciseCheckResult | undefined>;
163
+ /** 查询可行权持仓列表 (wire: option_exercise_position) */
164
+ getOptionExercisePositions(req: OptionExercisePositionRequest): Promise<OptionExercisePositionPageResult | undefined>;
165
+ /** 提交行权/作废申请 (wire: option_exercise_submit) */
166
+ submitOptionExercise(req: OptionExerciseSubmitRequest): Promise<boolean>;
167
+ /** 分页查询行权记录 (wire: option_exercise_record) */
168
+ getOptionExerciseRecords(req: OptionExerciseRecordsRequest): Promise<OptionExerciseRecordPageResult | undefined>;
169
+ /** 撤销行权申请 (wire: option_exercise_cancel) */
170
+ cancelOptionExercise(req: OptionExerciseCancelRequest): Promise<boolean>;
116
171
  }
@@ -0,0 +1 @@
1
+ export declare const SDK_VERSION = "0.5.7";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tigeropen",
3
- "version": "0.4.0",
3
+ "version": "0.5.7",
4
4
  "description": "Tiger Brokers OpenAPI TypeScript SDK for market data, trading, and real-time push",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -24,13 +24,16 @@
24
24
  "url": "https://github.com/tigerfintech/openapi-typescript-sdk/issues"
25
25
  },
26
26
  "scripts": {
27
- "build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json",
28
- "build:esm": "tsc -p tsconfig.json",
27
+ "build": "node scripts/sync-version.mjs && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node scripts/fix-esm-imports.mjs",
28
+ "build:esm": "tsc -p tsconfig.json && node scripts/fix-esm-imports.mjs",
29
29
  "build:cjs": "tsc -p tsconfig.cjs.json",
30
30
  "prepublishOnly": "npm run build",
31
31
  "publish:all": "npm run build && npm publish --registry https://registry.npmjs.org --access public && npm pkg set name=tigeropen && npm publish --registry https://registry.npmjs.org && npm pkg set name=@tigeropenapi/tigeropen",
32
32
  "test": "vitest run",
33
+ "test:unit": "vitest run --config vitest.config.ts",
34
+ "test:integ": "TIGER_RUN_INTEG=true vitest run --config vitest.integ.config.ts",
33
35
  "test:watch": "vitest",
36
+ "sync-version": "node scripts/sync-version.mjs",
34
37
  "clean": "rm -rf dist",
35
38
  "proto:generate": "protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=./src/push/pb --ts_proto_opt=esModuleInterop=true,outputEncodeMethods=true,outputJsonMethods=false,outputClientImpl=false -I=./proto ./proto/*.proto"
36
39
  },
@@ -50,10 +53,12 @@
50
53
  "@types/node": "^25.6.0",
51
54
  "fast-check": "^3.15.0",
52
55
  "ts-proto": "^2.11.6",
56
+ "tsx": "^4.22.4",
53
57
  "typescript": "^5.3.0",
54
58
  "vitest": "^1.2.0"
55
59
  },
56
60
  "dependencies": {
57
61
  "@bufbuild/protobuf": "^2.12.0"
58
- }
62
+ },
63
+ "gitHead": "3655981845c4255e6b9f48d629e874dc3b0b699b"
59
64
  }