stock-sdk 1.9.1 → 1.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -139,6 +139,17 @@ interface CircuitBreakerOptions {
139
139
  onStateChange?: (from: CircuitState, to: CircuitState) => void;
140
140
  }
141
141
 
142
+ interface HostHealthState {
143
+ host: string;
144
+ failureCount: number;
145
+ successCount: number;
146
+ cooldownUntil: number;
147
+ lastFailureAt: number;
148
+ lastErrorCode?: SdkErrorCode;
149
+ }
150
+ interface HostHealthStats extends HostHealthState {
151
+ }
152
+
142
153
  /**
143
154
  * 请求客户端配置选项
144
155
  */
@@ -162,6 +173,64 @@ interface RequestClientOptions {
162
173
  */
163
174
  providerPolicies?: Partial<Record<ProviderName, ProviderRequestPolicy>>;
164
175
  }
176
+ /**
177
+ * GET 请求选项
178
+ */
179
+ interface GetOptions {
180
+ responseType?: 'text' | 'json' | 'arraybuffer';
181
+ provider?: ProviderName;
182
+ }
183
+ declare class RequestClient {
184
+ private readonly baseUrl;
185
+ private readonly defaultPolicy;
186
+ private readonly providerPolicies;
187
+ private readonly runtimeStates;
188
+ private readonly fallbackManager;
189
+ constructor(options?: RequestClientOptions);
190
+ /**
191
+ * 获取 provider 运行时状态,按需初始化限流器和熔断器。
192
+ */
193
+ private getProviderState;
194
+ /**
195
+ * 获取默认超时时间
196
+ */
197
+ getTimeout(): number;
198
+ /**
199
+ * 获取 host 健康状态
200
+ */
201
+ getHostHealth(provider?: ProviderName): HostHealthStats[];
202
+ /**
203
+ * 计算指数退避延迟时间
204
+ */
205
+ private calculateDelay;
206
+ /**
207
+ * 休眠指定毫秒
208
+ */
209
+ private sleep;
210
+ /**
211
+ * 判断是否应该重试
212
+ */
213
+ private shouldRetry;
214
+ /**
215
+ * 单 host 带重试的请求执行器
216
+ */
217
+ private executeWithRetry;
218
+ /**
219
+ * 执行单次 HTTP 请求
220
+ */
221
+ private performRequest;
222
+ /**
223
+ * 发送 GET 请求(带自动重试、限流、熔断和 fallback)
224
+ */
225
+ get<T = string>(url: string, options?: GetOptions): Promise<T>;
226
+ /**
227
+ * 腾讯财经专用请求(GBK 解码,带自动重试)
228
+ */
229
+ getTencentQuote(params: string): Promise<{
230
+ key: string;
231
+ fields: string[];
232
+ }[]>;
233
+ }
165
234
 
166
235
  /**
167
236
  * 响应解析器
@@ -233,6 +302,72 @@ interface JsonpOptions {
233
302
  */
234
303
  declare function jsonpRequest<T = unknown>(url: string, options?: JsonpOptions): Promise<T>;
235
304
 
305
+ /**
306
+ * 时间元信息工具
307
+ *
308
+ * 给行情/K线/分时等含时间字段的数据补充统一的 `timestamp` (UTC unix ms)
309
+ * 与 `tz` (IANA 时区名),让消费者无需自己根据各数据源的字符串格式做时区换算。
310
+ *
311
+ * 设计要点:
312
+ * - 不引入第三方时区库 (SDK 零依赖),通过 `Intl.DateTimeFormat` 计算时区偏移。
313
+ * - 兼容多种本地时间字符串格式 (yyyyMMddHHmmss / YYYY-MM-DD HH:mm:ss / YYYY-MM-DD HH:mm /
314
+ * YYYY-MM-DD / yyyyMMdd / HH:mm 配 baseDate)。
315
+ * - 解析失败/输入为空时 `timestamp` 为 `NaN`,调用方可用 `Number.isNaN` 检测。
316
+ */
317
+ /**
318
+ * 已支持的市场时区。沿用 IANA 时区名。
319
+ *
320
+ * - `Asia/Shanghai`: A 股 (沪深北)
321
+ * - `Asia/Hong_Kong`: 港股
322
+ * - `America/New_York`: 美股 (含夏令时切换)
323
+ */
324
+ declare const MARKET_TZ: {
325
+ readonly CN: "Asia/Shanghai";
326
+ readonly HK: "Asia/Hong_Kong";
327
+ readonly US: "America/New_York";
328
+ };
329
+ type MarketTz = (typeof MARKET_TZ)[keyof typeof MARKET_TZ];
330
+ /**
331
+ * 时间元信息:与原始 `time`/`date` 字符串配套使用。
332
+ */
333
+ interface TimeMeta {
334
+ /** UTC unix 毫秒时间戳。原始字符串无法解析时为 `NaN`。 */
335
+ timestamp: number;
336
+ /** 原始字符串对应的市场时区 (IANA name)。 */
337
+ tz: MarketTz;
338
+ }
339
+ /**
340
+ * 解析"市场本地时间字符串"为 UTC unix ms。失败返回 `NaN`。
341
+ *
342
+ * 支持的格式:
343
+ * - `'YYYY-MM-DD HH:mm:ss'` / `'YYYY-MM-DDTHH:mm:ss'`
344
+ * - `'YYYY-MM-DD HH:mm'`
345
+ * - `'YYYY-MM-DD'` (按当日 00:00 计)
346
+ * - `'yyyyMMddHHmmss'` (腾讯接口 14 位无分隔)
347
+ * - `'yyyyMMdd'` (8 位日期)
348
+ *
349
+ * @param local 市场本地时间字符串
350
+ * @param tz 市场时区 (使用 `MARKET_TZ`)
351
+ */
352
+ declare function parseMarketTime(local: string, tz: MarketTz): number;
353
+ /**
354
+ * 构造 `TimeMeta`。原始字符串无法解析时 `timestamp` 为 `NaN`。
355
+ *
356
+ * @param local 市场本地时间字符串
357
+ * @param tz 市场时区
358
+ */
359
+ declare function buildTimeMeta(local: string, tz: MarketTz): TimeMeta;
360
+ /**
361
+ * 将"基础日期 (YYYY-MM-DD) + HH:mm 时间片"组合后构造 `TimeMeta`。
362
+ *
363
+ * 用于"当日分时"等只返回 `HH:mm` 的接口。
364
+ *
365
+ * @param baseDate 形如 `'2024-05-12'` 的日期字符串
366
+ * @param hhmm 形如 `'09:30'` 或 `'09:30:00'` 的时间片
367
+ * @param tz 市场时区
368
+ */
369
+ declare function buildTimeMetaFromDateAndTime(baseDate: string, hhmm: string, tz: MarketTz): TimeMeta;
370
+
236
371
  /**
237
372
  * A 股 / 指数 全量行情
238
373
  */
@@ -265,8 +400,12 @@ interface FullQuote {
265
400
  price: number;
266
401
  volume: number;
267
402
  }[];
268
- /** 时间戳 yyyyMMddHHmmss */
403
+ /** 行情时间(原始字符串,腾讯接口格式 `yyyyMMddHHmmss`,市场时区) */
269
404
  time: string;
405
+ /** 行情时间对应的 UTC unix 毫秒时间戳;无法解析时为 `NaN` */
406
+ timestamp: number;
407
+ /** 行情时间所属市场时区 (`Asia/Shanghai`) */
408
+ tz: MarketTz;
270
409
  /** 涨跌额 */
271
410
  change: number;
272
411
  /** 涨跌幅% */
@@ -356,7 +495,12 @@ interface FundFlow {
356
495
  /** 总资金流 */
357
496
  totalFlow: number;
358
497
  name: string;
498
+ /** 数据日期(原始字符串,A 股时区) */
359
499
  date: string;
500
+ /** 数据日期对应当日 00:00 (`Asia/Shanghai`) 的 UTC 毫秒时间戳;无法解析时为 `NaN` */
501
+ timestamp: number;
502
+ /** 数据日期所属时区 (`Asia/Shanghai`) */
503
+ tz: MarketTz;
360
504
  raw: string[];
361
505
  }
362
506
  /**
@@ -384,7 +528,12 @@ interface HKQuote {
384
528
  prevClose: number;
385
529
  open: number;
386
530
  volume: number;
531
+ /** 行情时间(原始字符串,腾讯接口格式 `yyyyMMddHHmmss`,港股时区) */
387
532
  time: string;
533
+ /** UTC unix 毫秒时间戳;无法解析时为 `NaN` */
534
+ timestamp: number;
535
+ /** 行情时间所属市场时区 (`Asia/Hong_Kong`) */
536
+ tz: MarketTz;
388
537
  change: number;
389
538
  changePercent: number;
390
539
  high: number;
@@ -414,8 +563,12 @@ interface USQuote {
414
563
  open: number;
415
564
  /** 成交量 */
416
565
  volume: number;
417
- /** 时间 */
566
+ /** 行情时间(原始字符串,腾讯接口格式 `yyyyMMddHHmmss`,美东时区) */
418
567
  time: string;
568
+ /** UTC unix 毫秒时间戳(自动处理美东夏令时);无法解析时为 `NaN` */
569
+ timestamp: number;
570
+ /** 行情时间所属市场时区 (`America/New_York`) */
571
+ tz: MarketTz;
419
572
  /** 涨跌额 */
420
573
  change: number;
421
574
  /** 涨跌幅% */
@@ -455,8 +608,12 @@ interface FundQuote {
455
608
  accNav: number;
456
609
  /** 当日涨跌额 */
457
610
  change: number;
458
- /** 净值日期 */
611
+ /** 净值日期(原始字符串,如 `'2024-05-12'`,A 股时区) */
459
612
  navDate: string;
613
+ /** 净值日期对应当日 00:00 (`Asia/Shanghai`) 的 UTC 毫秒时间戳;无法解析时为 `NaN` */
614
+ timestamp: number;
615
+ /** 净值日期所属时区 (`Asia/Shanghai`) */
616
+ tz: MarketTz;
460
617
  raw: string[];
461
618
  }
462
619
 
@@ -464,8 +621,12 @@ interface FundQuote {
464
621
  * A 股历史 K 线(日/周/月)
465
622
  */
466
623
  interface HistoryKline {
467
- /** 日期 YYYY-MM-DD */
624
+ /** 日期 YYYY-MM-DD (A 股时区) */
468
625
  date: string;
626
+ /** 当日 00:00 (`Asia/Shanghai`) 的 UTC 毫秒时间戳;无法解析时为 `NaN` */
627
+ timestamp: number;
628
+ /** 日期所属市场时区 (`Asia/Shanghai`) */
629
+ tz: MarketTz;
469
630
  /** 股票代码 */
470
631
  code: string;
471
632
  /** 开盘价 */
@@ -493,8 +654,12 @@ interface HistoryKline {
493
654
  * A 股分时数据(1 分钟)
494
655
  */
495
656
  interface MinuteTimeline {
496
- /** 时间 YYYY-MM-DD HH:mm */
657
+ /** 时间 YYYY-MM-DD HH:mm (A 股时区) */
497
658
  time: string;
659
+ /** UTC 毫秒时间戳 (`Asia/Shanghai` 解释);无法解析时为 `NaN` */
660
+ timestamp: number;
661
+ /** 时间所属市场时区 (`Asia/Shanghai`) */
662
+ tz: MarketTz;
498
663
  /** 开盘价 */
499
664
  open: number | null;
500
665
  /** 收盘价 */
@@ -514,8 +679,12 @@ interface MinuteTimeline {
514
679
  * A 股分钟 K 线(5/15/30/60)
515
680
  */
516
681
  interface MinuteKline {
517
- /** 时间 YYYY-MM-DD HH:mm */
682
+ /** 时间 YYYY-MM-DD HH:mm (A 股时区) */
518
683
  time: string;
684
+ /** UTC 毫秒时间戳 (`Asia/Shanghai` 解释);无法解析时为 `NaN` */
685
+ timestamp: number;
686
+ /** 时间所属市场时区 (`Asia/Shanghai`) */
687
+ tz: MarketTz;
519
688
  /** 开盘价 */
520
689
  open: number | null;
521
690
  /** 收盘价 */
@@ -541,8 +710,15 @@ interface MinuteKline {
541
710
  * 当日分时项
542
711
  */
543
712
  interface TodayTimeline {
544
- /** 时间 HH:mm */
713
+ /** 时间 HH:mm (A 股时区) */
545
714
  time: string;
715
+ /**
716
+ * UTC 毫秒时间戳。由所属 `TodayTimelineResponse.date` 与 `time` 拼接后,
717
+ * 按 `Asia/Shanghai` 解释得到;无法解析时为 `NaN`。
718
+ */
719
+ timestamp: number;
720
+ /** 时间所属市场时区 (`Asia/Shanghai`) */
721
+ tz: MarketTz;
546
722
  /** 当前价 */
547
723
  price: number;
548
724
  /** 均价 */
@@ -558,8 +734,12 @@ interface TodayTimeline {
558
734
  interface TodayTimelineResponse {
559
735
  /** 股票代码 */
560
736
  code: string;
561
- /** 交易日期 YYYY-MM-DD */
737
+ /** 交易日期 YYYY-MM-DD (A 股时区) */
562
738
  date: string;
739
+ /** 交易日 00:00 (`Asia/Shanghai`) 的 UTC 毫秒时间戳;无法解析时为 `NaN` */
740
+ timestamp: number;
741
+ /** 日期所属市场时区 (`Asia/Shanghai`) */
742
+ tz: MarketTz;
563
743
  /**
564
744
  * 昨收价
565
745
  * - 由 SDK 解析腾讯接口的 `quoteFields[4]` 得到
@@ -570,11 +750,16 @@ interface TodayTimelineResponse {
570
750
  data: TodayTimeline[];
571
751
  }
572
752
  /**
573
- * 港股 / 美股历史 K 线
753
+ * 港股 / 美股历史 K 线公共字段。
754
+ *
755
+ * 内部基类,通常不直接使用。请用具体的 `HKHistoryKline` 或 `USHistoryKline`,
756
+ * 它们各自带本地化字段 (`currency` / `lotSize`)。
574
757
  */
575
- interface HKUSHistoryKline {
576
- /** 日期 YYYY-MM-DD */
758
+ interface ForeignHistoryKlineBase {
759
+ /** 日期 YYYY-MM-DD (市场本地时区) */
577
760
  date: string;
761
+ /** UTC 毫秒时间戳;无法解析时为 `NaN` */
762
+ timestamp: number;
578
763
  /** 股票代码 */
579
764
  code: string;
580
765
  /** 股票名称 */
@@ -600,6 +785,41 @@ interface HKUSHistoryKline {
600
785
  /** 换手率% */
601
786
  turnoverRate: number | null;
602
787
  }
788
+ /**
789
+ * 港股历史 K 线
790
+ *
791
+ * `currency` 固定 `'HKD'`,`tz` 固定 `'Asia/Hong_Kong'`。
792
+ * `lotSize`(每手股数)由 K 线接口本身不直接返回,目前为 `null`,
793
+ * 后续若数据源补齐再填充;如需港股每手股数请用 `getHKQuotes` 的 `lotSize` 字段。
794
+ */
795
+ interface HKHistoryKline extends ForeignHistoryKlineBase {
796
+ /** 时区 (`Asia/Hong_Kong`) */
797
+ tz: MarketTz;
798
+ /** 计价币种 (固定 `'HKD'`) */
799
+ currency: 'HKD';
800
+ /** 港股每手股数;K 线接口暂不返回,固定 `null` */
801
+ lotSize: number | null;
802
+ }
803
+ /**
804
+ * 美股历史 K 线
805
+ *
806
+ * `currency` 固定 `'USD'`,`tz` 固定 `'America/New_York'`(自动处理夏令时切换)。
807
+ * 不含盘前/盘后(extended hours)数据,仅常规交易时段。
808
+ */
809
+ interface USHistoryKline extends ForeignHistoryKlineBase {
810
+ /** 时区 (`America/New_York`,含夏令时) */
811
+ tz: MarketTz;
812
+ /** 计价币种 (固定 `'USD'`) */
813
+ currency: 'USD';
814
+ }
815
+ /**
816
+ * 港股 / 美股历史 K 线 (兼容别名)
817
+ *
818
+ * @deprecated 自 v1.9.1 起拆分为 {@link HKHistoryKline} 与 {@link USHistoryKline},
819
+ * 各自带本地化字段 (currency / lotSize)。本别名仍是它们的 union,
820
+ * 老代码无需立即迁移;新代码请直接用具体类型以获得更好的类型推断。
821
+ */
822
+ type HKUSHistoryKline = HKHistoryKline | USHistoryKline;
603
823
 
604
824
  /**
605
825
  * 行业板块列表项
@@ -1752,9 +1972,19 @@ interface GetUSCodeListOptions {
1752
1972
  */
1753
1973
 
1754
1974
  interface HistoryKlineOptions {
1755
- /** K 线周期 */
1975
+ /** K 线周期 @default 'daily' */
1756
1976
  period?: 'daily' | 'weekly' | 'monthly';
1757
- /** 复权类型 */
1977
+ /**
1978
+ * 复权类型
1979
+ *
1980
+ * - `'qfq'` 前复权(默认):用最新一次分红送股调整历史价格,适合看走势
1981
+ * - `'hfq'` 后复权:固定历史价格,把分红送股摊到当下,适合长期收益率/复利计算
1982
+ * - `''` 不复权:返回交易所原始价格
1983
+ *
1984
+ * **未传时默认使用 `'qfq'`**。如果做回测、计算分红再投资收益,请显式传 `'hfq'` 或 `''`。
1985
+ *
1986
+ * @default 'qfq'
1987
+ */
1758
1988
  adjust?: '' | 'qfq' | 'hfq';
1759
1989
  /** 开始日期 YYYYMMDD */
1760
1990
  startDate?: string;
@@ -1762,9 +1992,17 @@ interface HistoryKlineOptions {
1762
1992
  endDate?: string;
1763
1993
  }
1764
1994
  interface MinuteKlineOptions {
1765
- /** K 线周期 */
1995
+ /** K 线周期 @default '1' */
1766
1996
  period?: '1' | '5' | '15' | '30' | '60';
1767
- /** 复权类型(仅 5/15/30/60 分钟有效) */
1997
+ /**
1998
+ * 复权类型(仅 5/15/30/60 分钟有效;1 分钟分时不支持复权)
1999
+ *
2000
+ * - `'qfq'` 前复权(默认)
2001
+ * - `'hfq'` 后复权
2002
+ * - `''` 不复权
2003
+ *
2004
+ * @default 'qfq'
2005
+ */
1768
2006
  adjust?: '' | 'qfq' | 'hfq';
1769
2007
  /** 开始时间 */
1770
2008
  startDate?: string;
@@ -1780,9 +2018,19 @@ interface MinuteKlineOptions {
1780
2018
  * 通用历史 K 线请求选项
1781
2019
  */
1782
2020
  interface HistoryKlineRequestOptions {
1783
- /** K 线周期 */
2021
+ /** K 线周期 @default 'daily' */
1784
2022
  period?: 'daily' | 'weekly' | 'monthly';
1785
- /** 复权类型 */
2023
+ /**
2024
+ * 复权类型
2025
+ *
2026
+ * - `'qfq'` 前复权(默认)
2027
+ * - `'hfq'` 后复权
2028
+ * - `''` 不复权
2029
+ *
2030
+ * 详见 [复权说明](https://stock-sdk.linkdiary.cn/guide/dividend-adjustment.html)。
2031
+ *
2032
+ * @default 'qfq'
2033
+ */
1786
2034
  adjust?: '' | 'qfq' | 'hfq';
1787
2035
  /** 开始日期 YYYYMMDD */
1788
2036
  startDate?: string;
@@ -2580,6 +2828,38 @@ declare global {
2580
2828
  }
2581
2829
  }
2582
2830
 
2831
+ declare abstract class BaseService {
2832
+ protected readonly client: RequestClient;
2833
+ constructor(client: RequestClient);
2834
+ }
2835
+
2836
+ declare class QuoteService extends BaseService {
2837
+ constructor(client: RequestClient);
2838
+ getFullQuotes(codes: string[]): Promise<FullQuote[]>;
2839
+ getSimpleQuotes(codes: string[]): Promise<SimpleQuote[]>;
2840
+ getHKQuotes(codes: string[]): Promise<HKQuote[]>;
2841
+ getUSQuotes(codes: string[]): Promise<USQuote[]>;
2842
+ getFundQuotes(codes: string[]): Promise<FundQuote[]>;
2843
+ getFundFlow(codes: string[]): Promise<FundFlow[]>;
2844
+ getPanelLargeOrder(codes: string[]): Promise<PanelLargeOrder[]>;
2845
+ getTodayTimeline(code: string): Promise<TodayTimelineResponse>;
2846
+ search(keyword: string): Promise<SearchResult[]>;
2847
+ getAShareCodeList(options?: GetAShareCodeListOptions | boolean): Promise<string[]>;
2848
+ getUSCodeList(options?: GetUSCodeListOptions | boolean): Promise<string[]>;
2849
+ getHKCodeList(): Promise<string[]>;
2850
+ getFundCodeList(): Promise<string[]>;
2851
+ getAllAShareQuotes(options?: GetAllAShareQuotesOptions): Promise<FullQuote[]>;
2852
+ getAllHKShareQuotes(options?: GetAllAShareQuotesOptions): Promise<HKQuote[]>;
2853
+ getAllUSShareQuotes(options?: GetAllUSQuotesOptions): Promise<USQuote[]>;
2854
+ getAllQuotesByCodes(codes: string[], options?: GetAllAShareQuotesOptions): Promise<FullQuote[]>;
2855
+ batchRaw(params: string): Promise<{
2856
+ key: string;
2857
+ fields: string[];
2858
+ }[]>;
2859
+ getTradingCalendar(): Promise<string[]>;
2860
+ getDividendDetail(symbol: string): Promise<DividendDetail[]>;
2861
+ }
2862
+
2583
2863
  type MarketType = 'A' | 'HK' | 'US';
2584
2864
  /**
2585
2865
  * `getKlineWithIndicators` 的请求参数
@@ -2610,6 +2890,78 @@ interface KlineWithIndicatorsOptions {
2610
2890
  indicators?: IndicatorOptions;
2611
2891
  }
2612
2892
 
2893
+ /**
2894
+ * 交易日历 / 市场状态工具
2895
+ *
2896
+ * 在原有 `getTradingCalendar()` 字符串数组之外,提供更高层的便利方法:
2897
+ * - `isTradingDay(date?)`:判断是否交易日 (A 股,基于上游日历)
2898
+ * - `nextTradingDay(date?)` / `prevTradingDay(date?)`:跳转最近的交易日
2899
+ * - `getMarketStatus(market?)`:返回当前市场是开盘/午休/盘前/盘后/休市等状态
2900
+ *
2901
+ * 港股 / 美股没有官方日历数据源,`getMarketStatus('HK' | 'US')` 退化为
2902
+ * "周一-周五 + 已知交易时段"判断。法定假日不会被识别。
2903
+ */
2904
+
2905
+ /**
2906
+ * 市场实时状态。
2907
+ *
2908
+ * - `'pre_market'` 盘前(含集合竞价)
2909
+ * - `'open'` 连续竞价交易中
2910
+ * - `'lunch_break'` 午间休市(港股 12:00-13:00,A 股 11:30-13:00;美股无)
2911
+ * - `'after_hours'` 盘后
2912
+ * - `'closed'` 非交易日 / 周末 / 凌晨等远离交易时段的时间
2913
+ */
2914
+ type MarketStatus = 'pre_market' | 'open' | 'lunch_break' | 'after_hours' | 'closed';
2915
+ /** 支持的市场枚举,用于 `getMarketStatus`。 */
2916
+ type SupportedMarket = 'A' | 'HK' | 'US';
2917
+ declare class TradingCalendarService {
2918
+ private readonly quoteService;
2919
+ constructor(quoteService: QuoteService);
2920
+ /**
2921
+ * 判断给定日期是否为 A 股交易日。
2922
+ *
2923
+ * 数据源:`getTradingCalendar()` (腾讯接口,带 12 小时缓存)。
2924
+ * 因此第一次调用会拉取全量交易日列表,后续命中缓存。
2925
+ *
2926
+ * @param date 不传则取"现在 `Asia/Shanghai` 的当日"。可传 `'YYYY-MM-DD'` /
2927
+ * `'YYYYMMDD'` / `Date` 对象。
2928
+ * @returns `true` 表示是交易日;`false` 表示节假日 / 周末。
2929
+ */
2930
+ isTradingDay(date?: string | Date): Promise<boolean>;
2931
+ /**
2932
+ * 返回 A 股下一个交易日 (`'YYYY-MM-DD'`)。
2933
+ *
2934
+ * - 如果 `date` 本身是交易日,返回它**之后**的下一个交易日
2935
+ * - 如果 `date` 是节假日,返回大于它的第一个交易日
2936
+ * - 如果在已知日历范围之外,抛 `RangeError`
2937
+ *
2938
+ * @param date 不传则取"现在 `Asia/Shanghai` 的当日"
2939
+ */
2940
+ nextTradingDay(date?: string | Date): Promise<string>;
2941
+ /**
2942
+ * 返回 A 股上一个交易日 (`'YYYY-MM-DD'`)。
2943
+ *
2944
+ * - 如果 `date` 本身是交易日,返回它**之前**的上一个交易日
2945
+ * - 如果 `date` 是节假日,返回小于它的最后一个交易日
2946
+ * - 如果在已知日历范围之外,抛 `RangeError`
2947
+ *
2948
+ * @param date 不传则取"现在 `Asia/Shanghai` 的当日"
2949
+ */
2950
+ prevTradingDay(date?: string | Date): Promise<string>;
2951
+ /**
2952
+ * 返回当前市场状态 (同步,不发请求)。
2953
+ *
2954
+ * - **A 股**:仅按交易时段判断,**不识别法定假日**(SDK 不会为此发请求)。
2955
+ * 如需精确判断"今天是否真的是交易日",请用 `await isTradingDay()`。
2956
+ * 返回 `'closed'` 时表示"周末或非交易时段",可能是节假日 / 凌晨 / 深夜。
2957
+ * - **港股 / 美股**:同样按"周一-周五 + 已知时段"判断,不识别假日。
2958
+ *
2959
+ * @param market `'A'`(默认) / `'HK'` / `'US'`
2960
+ * @param now 用于测试注入"当前时间";生产代码不需要传
2961
+ */
2962
+ getMarketStatus(market?: SupportedMarket, now?: Date): MarketStatus;
2963
+ }
2964
+
2613
2965
  declare class StockSDK {
2614
2966
  private readonly client;
2615
2967
  private readonly quoteService;
@@ -2623,6 +2975,7 @@ declare class StockSDK {
2623
2975
  private readonly marketEventService;
2624
2976
  private readonly dragonTigerService;
2625
2977
  private readonly dataService;
2978
+ private readonly tradingCalendarService;
2626
2979
  /**
2627
2980
  * 创建 Stock SDK 实例。
2628
2981
  * 旧的全局 `timeout` / `retry` / `rateLimit` / `circuitBreaker` 配置继续有效,
@@ -2641,12 +2994,12 @@ declare class StockSDK {
2641
2994
  getSimpleQuotes(codes: string[]): Promise<SimpleQuote[]>;
2642
2995
  /**
2643
2996
  * 获取港股行情
2644
- * @param codes 港股代码数组(如 `['hk00700']`)
2997
+ * @param codes 港股代码数组(5 位数字,无需 `hk` 前缀,如 `['00700', '09988']`)
2645
2998
  */
2646
2999
  getHKQuotes(codes: string[]): Promise<HKQuote[]>;
2647
3000
  /**
2648
3001
  * 获取美股行情
2649
- * @param codes 美股代码数组(如 `['usAAPL']`)
3002
+ * @param codes 美股代码数组(无需 `us` 前缀,如 `['AAPL', 'BABA']`)
2650
3003
  */
2651
3004
  getUSQuotes(codes: string[]): Promise<USQuote[]>;
2652
3005
  /**
@@ -2722,29 +3075,50 @@ declare class StockSDK {
2722
3075
  */
2723
3076
  getConceptMinuteKline(symbol: string, options?: ConceptBoardMinuteKlineOptions): Promise<ConceptBoardMinuteTimeline[] | ConceptBoardMinuteKline[]>;
2724
3077
  /**
2725
- * 获取 A 股历史 K 线(日/周/月,含复权)
3078
+ * 获取 A 股历史 K 线(日/周/月,含复权)。
3079
+ *
3080
+ * **复权默认值:`adjust='qfq'`(前复权)。**
3081
+ * - 前复权适合看走势/做技术分析
3082
+ * - 后复权 `'hfq'` 适合算长期收益率/复利
3083
+ * - 不复权 `''` 是交易所原始价
3084
+ *
3085
+ * 不显式传 `adjust` 时返回的是已经被前复权调整过的价格,
3086
+ * 做回测/收益计算时务必显式传值,详见
3087
+ * [复权说明](https://stock-sdk.linkdiary.cn/guide/dividend-adjustment.html)。
3088
+ *
2726
3089
  * @param symbol 股票代码
2727
3090
  * @param options K 线参数
2728
3091
  */
2729
3092
  getHistoryKline(symbol: string, options?: HistoryKlineOptions): Promise<HistoryKline[]>;
2730
3093
  /**
2731
- * 获取 A 股分时/分钟 K 线
3094
+ * 获取 A 股分时/分钟 K 线。
3095
+ *
3096
+ * **复权默认值:`adjust='qfq'`(前复权,仅 5/15/30/60 分钟有效)。** 1 分钟分时不支持复权。
3097
+ *
2732
3098
  * @param symbol 股票代码
2733
- * @param options 周期参数(不传周期则返回当日分时)
3099
+ * @param options 周期参数(不传周期则返回当日分时)
2734
3100
  */
2735
3101
  getMinuteKline(symbol: string, options?: MinuteKlineOptions): Promise<MinuteTimeline[] | MinuteKline[]>;
2736
3102
  /**
2737
- * 获取港股历史 K 线
3103
+ * 获取港股历史 K 线。
3104
+ *
3105
+ * **复权默认值:`adjust='qfq'`(前复权)。** 详见
3106
+ * [复权说明](https://stock-sdk.linkdiary.cn/guide/dividend-adjustment.html)。
3107
+ *
2738
3108
  * @param symbol 港股代码
2739
3109
  * @param options K 线参数
2740
3110
  */
2741
- getHKHistoryKline(symbol: string, options?: HKKlineOptions): Promise<HKUSHistoryKline[]>;
3111
+ getHKHistoryKline(symbol: string, options?: HKKlineOptions): Promise<HKHistoryKline[]>;
2742
3112
  /**
2743
- * 获取美股历史 K 线
3113
+ * 获取美股历史 K 线。
3114
+ *
3115
+ * **复权默认值:`adjust='qfq'`(前复权)。** 详见
3116
+ * [复权说明](https://stock-sdk.linkdiary.cn/guide/dividend-adjustment.html)。
3117
+ *
2744
3118
  * @param symbol 美股代码
2745
3119
  * @param options K 线参数
2746
3120
  */
2747
- getUSHistoryKline(symbol: string, options?: USKlineOptions): Promise<HKUSHistoryKline[]>;
3121
+ getUSHistoryKline(symbol: string, options?: USKlineOptions): Promise<USHistoryKline[]>;
2748
3122
  /**
2749
3123
  * 模糊搜索股票/指数/基金等
2750
3124
  * @param keyword 关键词(代码 / 名称 / 拼音)
@@ -2801,6 +3175,53 @@ declare class StockSDK {
2801
3175
  * 获取交易日历(A 股)
2802
3176
  */
2803
3177
  getTradingCalendar(): Promise<string[]>;
3178
+ /**
3179
+ * 判断给定日期是否为 A 股交易日。
3180
+ *
3181
+ * 数据源:`getTradingCalendar()` (腾讯接口,带 12 小时缓存)。
3182
+ * 第一次调用会拉取全量交易日列表,后续命中缓存。
3183
+ *
3184
+ * @param date 不传则取"现在 `Asia/Shanghai` 的当日"。
3185
+ * 支持 `'YYYY-MM-DD'` / `'YYYYMMDD'` / `Date` 对象。
3186
+ * @example
3187
+ * ```ts
3188
+ * await sdk.isTradingDay(); // 今天是否交易日
3189
+ * await sdk.isTradingDay('2024-10-01'); // false (国庆)
3190
+ * ```
3191
+ */
3192
+ isTradingDay(date?: string | Date): Promise<boolean>;
3193
+ /**
3194
+ * 返回 A 股下一个交易日 (`'YYYY-MM-DD'`)。
3195
+ *
3196
+ * 如果 `date` 本身是交易日,返回它**之后**的下一个;否则返回大于它的第一个交易日。
3197
+ *
3198
+ * @param date 不传则取"现在 `Asia/Shanghai` 的当日"
3199
+ * @throws RangeError 当 `date` 已超过日历范围时
3200
+ */
3201
+ nextTradingDay(date?: string | Date): Promise<string>;
3202
+ /**
3203
+ * 返回 A 股上一个交易日 (`'YYYY-MM-DD'`)。
3204
+ *
3205
+ * 如果 `date` 本身是交易日,返回它**之前**的上一个;否则返回小于它的最后一个交易日。
3206
+ *
3207
+ * @param date 不传则取"现在 `Asia/Shanghai` 的当日"
3208
+ * @throws RangeError 当 `date` 早于日历最早日期时
3209
+ */
3210
+ prevTradingDay(date?: string | Date): Promise<string>;
3211
+ /**
3212
+ * 返回当前市场实时状态 (同步,不发请求)。
3213
+ *
3214
+ * 状态包括:`'pre_market'`(盘前)/ `'open'`(交易中)/ `'lunch_break'`(午休) /
3215
+ * `'after_hours'`(盘后)/ `'closed'`(休市/周末)。
3216
+ *
3217
+ * **注意:此方法仅按交易时段判断,不识别法定假日**。如需精确判断"今天是否交易日",
3218
+ * 请用 `await isTradingDay()` (会发请求)。
3219
+ *
3220
+ * 港股 / 美股没有官方日历,只按 "周一-周五 + 已知交易时段" 判断,假日不会被识别。
3221
+ *
3222
+ * @param market `'A'`(默认) / `'HK'` / `'US'`
3223
+ */
3224
+ getMarketStatus(market?: SupportedMarket): MarketStatus;
2804
3225
  /**
2805
3226
  * 获取分红配股明细
2806
3227
  * @param symbol 股票代码
@@ -3020,4 +3441,4 @@ declare class StockSDK {
3020
3441
  */
3021
3442
  declare function generateSearchExternalLinks(result: SearchResult): ExternalLink[];
3022
3443
 
3023
- export { type AShareMarket, type ATROptions, type BIASOptions, type BOLLOptions, type BlockTradeDailyStatItem, type BlockTradeDateOptions, type BlockTradeDetailItem, type BlockTradeMarketStatItem, type BoardChangeItem, type CCIOptions, type CFFEXOptionQuote, type CFFEXOptionQuotesOptions, type ComexInventory, type ComexInventoryOptions, type ConceptBoard, type ConceptBoardConstituent, type ConceptBoardKline, type ConceptBoardKlineOptions, type ConceptBoardMinuteKline, type ConceptBoardMinuteKlineOptions, type ConceptBoardMinuteTimeline, type ConceptBoardSpot, type DMIOptions$1 as DMIOptions, type DMIResult$1 as DMIResult, type DatacenterQuery, type DatacenterResult, type DividendDetail, type DragonTigerBranchItem, type DragonTigerDateOptions, type DragonTigerDetailItem, type DragonTigerInstitutionItem, type DragonTigerPeriod, type DragonTigerSeatItem, type DragonTigerStockStatItem, type ETFOptionCate, type ETFOptionExpireDay, type ETFOptionMonth, type ExternalLink, type FullQuote, type FundFlow, type FundFlowOptions, type FundFlowRankItem, type FundFlowRankOptions, type FundQuote, type FuturesExchange, type FuturesInventory, type FuturesInventoryOptions, type FuturesInventorySymbol, type FuturesKline, type FuturesKlineOptions, type GetAShareCodeListOptions, type GetAllAShareQuotesOptions, type GlobalFuturesKlineOptions, type GlobalFuturesQuote, type GlobalFuturesSpotOptions, type HKQuote, type HKUSHistoryKline, type HistoryKline, HttpError, INDICATOR_REGISTRY, type IndexOptionProduct, type IndicatorKey, type IndicatorOptions, type IndustryBoard, type IndustryBoardConstituent, type IndustryBoardKline, type IndustryBoardKlineOptions, type IndustryBoardMinuteKline, type IndustryBoardMinuteKlineOptions, type IndustryBoardMinuteTimeline, type IndustryBoardSpot, type JsonpOptions, type KCOptions$1 as KCOptions, type KCResult$1 as KCResult, type KDJOptions, type KlineWithIndicators, type MACDOptions, type MAOptions, type MarginAccountItem, type MarginTargetItem, type MarketFundFlow, type MarketType, type MinuteKline, type MinuteTimeline, type NorthboundDirection, type NorthboundFlowSummary, type NorthboundHistoryItem, type NorthboundHistoryOptions, type NorthboundHoldingRankItem, type NorthboundHoldingRankOptions, type NorthboundIndividualItem, type NorthboundMarket, type NorthboundMinuteItem, type NorthboundRankPeriod, type OBVOptions$1 as OBVOptions, type OBVResult$1 as OBVResult, type OptionKline, type OptionLHBItem, type OptionMinute, type OptionTQuote, type OptionTQuoteResult, type PanelLargeOrder, type ProviderName, type ProviderRequestPolicy, type ROCOptions$1 as ROCOptions, type ROCResult$1 as ROCResult, type RSIOptions, type RequestClientOptions, type RequestError, type RetryOptions, type SAROptions$1 as SAROptions, type SARResult$1 as SARResult, SdkError, type SearchResult, type SearchResultType, type SectorFundFlowItem, type SimpleQuote, type StockChangeItem, type StockChangeType, type StockFundFlowDaily, StockSDK, type TodayTimeline, type TodayTimelineResponse, type USQuote, type WROptions, type ZTPoolItem, type ZTPoolType, addIndicators, asyncPool, buildIndicatorContext, calcATR, calcBIAS, calcBOLL, calcCCI, calcDMI, calcEMA, calcKC, calcKDJ, calcMA, calcMACD, calcOBV, calcROC, calcRSI, calcSAR, calcSMA, calcWMA, calcWR, chunkArray, decodeGBK, StockSDK as default, estimateIndicatorLookback, extractJsonFromJsonp, generateSearchExternalLinks, getEnabledIndicatorKeys, getSdkErrorCode, jsonpRequest, parseResponse, safeNumber, safeNumberOrNull };
3444
+ export { type AShareMarket, type ATROptions, type BIASOptions, type BOLLOptions, type BlockTradeDailyStatItem, type BlockTradeDateOptions, type BlockTradeDetailItem, type BlockTradeMarketStatItem, type BoardChangeItem, type CCIOptions, type CFFEXOptionQuote, type CFFEXOptionQuotesOptions, type ComexInventory, type ComexInventoryOptions, type ConceptBoard, type ConceptBoardConstituent, type ConceptBoardKline, type ConceptBoardKlineOptions, type ConceptBoardMinuteKline, type ConceptBoardMinuteKlineOptions, type ConceptBoardMinuteTimeline, type ConceptBoardSpot, type DMIOptions$1 as DMIOptions, type DMIResult$1 as DMIResult, type DatacenterQuery, type DatacenterResult, type DividendDetail, type DragonTigerBranchItem, type DragonTigerDateOptions, type DragonTigerDetailItem, type DragonTigerInstitutionItem, type DragonTigerPeriod, type DragonTigerSeatItem, type DragonTigerStockStatItem, type ETFOptionCate, type ETFOptionExpireDay, type ETFOptionMonth, type ExternalLink, type FullQuote, type FundFlow, type FundFlowOptions, type FundFlowRankItem, type FundFlowRankOptions, type FundQuote, type FuturesExchange, type FuturesInventory, type FuturesInventoryOptions, type FuturesInventorySymbol, type FuturesKline, type FuturesKlineOptions, type GetAShareCodeListOptions, type GetAllAShareQuotesOptions, type GetAllUSQuotesOptions, type GetUSCodeListOptions, type GlobalFuturesKlineOptions, type GlobalFuturesQuote, type GlobalFuturesSpotOptions, type HKHistoryKline, type HKQuote, type HKUSHistoryKline, type HistoryKline, HttpError, INDICATOR_REGISTRY, type IndexOptionProduct, type IndicatorKey, type IndicatorOptions, type IndustryBoard, type IndustryBoardConstituent, type IndustryBoardKline, type IndustryBoardKlineOptions, type IndustryBoardMinuteKline, type IndustryBoardMinuteKlineOptions, type IndustryBoardMinuteTimeline, type IndustryBoardSpot, type JsonpOptions, type KCOptions$1 as KCOptions, type KCResult$1 as KCResult, type KDJOptions, type KlineWithIndicators, type MACDOptions, type MAOptions, MARKET_TZ, type MarginAccountItem, type MarginTargetItem, type MarketFundFlow, type MarketStatus, type MarketType, type MarketTz, type MinuteKline, type MinuteTimeline, type NorthboundDirection, type NorthboundFlowSummary, type NorthboundHistoryItem, type NorthboundHistoryOptions, type NorthboundHoldingRankItem, type NorthboundHoldingRankOptions, type NorthboundIndividualItem, type NorthboundMarket, type NorthboundMinuteItem, type NorthboundRankPeriod, type OBVOptions$1 as OBVOptions, type OBVResult$1 as OBVResult, type OptionKline, type OptionLHBItem, type OptionMinute, type OptionTQuote, type OptionTQuoteResult, type PanelLargeOrder, type ProviderName, type ProviderRequestPolicy, type ROCOptions$1 as ROCOptions, type ROCResult$1 as ROCResult, type RSIOptions, type RequestClientOptions, type RequestError, type RetryOptions, type SAROptions$1 as SAROptions, type SARResult$1 as SARResult, SdkError, type SearchResult, type SearchResultType, type SectorFundFlowItem, type SimpleQuote, type StockChangeItem, type StockChangeType, type StockFundFlowDaily, StockSDK, type SupportedMarket, type TimeMeta, type TodayTimeline, type TodayTimelineResponse, TradingCalendarService, type USHistoryKline, type USMarket, type USQuote, type WROptions, type ZTPoolItem, type ZTPoolType, addIndicators, asyncPool, buildIndicatorContext, buildTimeMeta, buildTimeMetaFromDateAndTime, calcATR, calcBIAS, calcBOLL, calcCCI, calcDMI, calcEMA, calcKC, calcKDJ, calcMA, calcMACD, calcOBV, calcROC, calcRSI, calcSAR, calcSMA, calcWMA, calcWR, chunkArray, decodeGBK, StockSDK as default, estimateIndicatorLookback, extractJsonFromJsonp, generateSearchExternalLinks, getEnabledIndicatorKeys, getSdkErrorCode, jsonpRequest, parseMarketTime, parseResponse, safeNumber, safeNumberOrNull };