stock-sdk 1.4.5 → 1.5.0

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
@@ -630,6 +630,15 @@ interface SearchResult {
630
630
  * 腾讯财经 - 批量操作
631
631
  */
632
632
 
633
+ /**
634
+ * A 股市场/板块类型
635
+ * - sh: 上交所(6 开头)
636
+ * - sz: 深交所(0 和 3 开头,包含创业板)
637
+ * - bj: 北交所(92 开头)
638
+ * - kc: 科创板(688 开头)
639
+ * - cy: 创业板(30 开头)
640
+ */
641
+ type AShareMarket = 'sh' | 'sz' | 'bj' | 'kc' | 'cy';
633
642
  /**
634
643
  * 获取全部 A 股行情的配置选项
635
644
  */
@@ -640,6 +649,62 @@ interface GetAllAShareQuotesOptions {
640
649
  concurrency?: number;
641
650
  /** 进度回调函数 */
642
651
  onProgress?: (completed: number, total: number) => void;
652
+ /**
653
+ * 筛选特定的交易所或板块
654
+ * - 不传或 undefined: 返回全部 A 股
655
+ * - 'sh': 上交所(6 开头,包含科创板)
656
+ * - 'sz': 深交所(0 和 3 开头,包含创业板)
657
+ * - 'bj': 北交所(92 开头)
658
+ * - 'kc': 科创板(688 开头)
659
+ * - 'cy': 创业板(30 开头)
660
+ */
661
+ market?: AShareMarket;
662
+ }
663
+ /**
664
+ * 获取全部美股行情的配置选项
665
+ */
666
+ interface GetAllUSQuotesOptions {
667
+ /** 单次请求的股票数量,默认 500 */
668
+ batchSize?: number;
669
+ /** 最大并发请求数,默认 7 */
670
+ concurrency?: number;
671
+ /** 进度回调函数 */
672
+ onProgress?: (completed: number, total: number) => void;
673
+ /**
674
+ * 筛选特定市场
675
+ * - 'NASDAQ': 纳斯达克 (105)
676
+ * - 'NYSE': 纽交所 (106)
677
+ * - 'AMEX': 美交所 (107)
678
+ */
679
+ market?: USMarket;
680
+ }
681
+ /**
682
+ * 获取 A 股代码列表的配置选项
683
+ */
684
+ interface GetAShareCodeListOptions {
685
+ /**
686
+ * 是否返回简化的代码(不含交易所前缀)
687
+ * - false(默认): 返回带前缀的完整代码,如 'sh600000', 'sz000001'
688
+ * - true: 返回纯数字代码,如 '600000', '000001'
689
+ */
690
+ simple?: boolean;
691
+ /**
692
+ * 筛选特定的交易所或板块
693
+ * - 不传或 undefined: 返回全部 A 股
694
+ * - 'sh': 上交所(6 开头,包含科创板)
695
+ * - 'sz': 深交所(0 和 3 开头,包含创业板)
696
+ * - 'bj': 北交所(92 开头)
697
+ * - 'kc': 科创板(688 开头)
698
+ * - 'cy': 创业板(30 开头)
699
+ */
700
+ market?: AShareMarket;
701
+ }
702
+ type USMarket = 'NASDAQ' | 'NYSE' | 'AMEX';
703
+ interface GetUSCodeListOptions {
704
+ /** 是否移除市场前缀,默认 false */
705
+ simple?: boolean;
706
+ /** 筛选特定市场 */
707
+ market?: USMarket;
643
708
  }
644
709
 
645
710
  /**
@@ -852,6 +917,80 @@ interface ATRResult {
852
917
  /** 平均真实波幅 */
853
918
  atr: number | null;
854
919
  }
920
+ interface OBVOptions$1 {
921
+ /** OBV 均线周期 */
922
+ maPeriod?: number;
923
+ }
924
+ interface OBVResult$1 {
925
+ /** OBV 值 */
926
+ obv: number | null;
927
+ /** OBV 均线 */
928
+ obvMa: number | null;
929
+ }
930
+ interface ROCOptions$1 {
931
+ /** ROC 周期,默认 12 */
932
+ period?: number;
933
+ /** 信号线周期 */
934
+ signalPeriod?: number;
935
+ }
936
+ interface ROCResult$1 {
937
+ /** ROC 值(百分比) */
938
+ roc: number | null;
939
+ /** 信号线 */
940
+ signal: number | null;
941
+ }
942
+ interface DMIOptions$1 {
943
+ /** 周期,默认 14 */
944
+ period?: number;
945
+ /** ADX 平滑周期 */
946
+ adxPeriod?: number;
947
+ }
948
+ interface DMIResult$1 {
949
+ /** +DI 值 */
950
+ pdi: number | null;
951
+ /** -DI 值 */
952
+ mdi: number | null;
953
+ /** ADX 值 */
954
+ adx: number | null;
955
+ /** ADXR 值 */
956
+ adxr: number | null;
957
+ }
958
+ interface SAROptions$1 {
959
+ /** 加速因子初始值,默认 0.02 */
960
+ afStart?: number;
961
+ /** 加速因子增量,默认 0.02 */
962
+ afIncrement?: number;
963
+ /** 加速因子最大值,默认 0.2 */
964
+ afMax?: number;
965
+ }
966
+ interface SARResult$1 {
967
+ /** SAR 值 */
968
+ sar: number | null;
969
+ /** 趋势方向:1 上升,-1 下降 */
970
+ trend: 1 | -1 | null;
971
+ /** 极值点 */
972
+ ep: number | null;
973
+ /** 加速因子 */
974
+ af: number | null;
975
+ }
976
+ interface KCOptions$1 {
977
+ /** EMA 周期,默认 20 */
978
+ emaPeriod?: number;
979
+ /** ATR 周期,默认 10 */
980
+ atrPeriod?: number;
981
+ /** ATR 倍数,默认 2 */
982
+ multiplier?: number;
983
+ }
984
+ interface KCResult$1 {
985
+ /** 中轨(EMA) */
986
+ mid: number | null;
987
+ /** 上轨 */
988
+ upper: number | null;
989
+ /** 下轨 */
990
+ lower: number | null;
991
+ /** 通道宽度 */
992
+ width: number | null;
993
+ }
855
994
 
856
995
  /**
857
996
  * 计算简单移动平均线 SMA
@@ -941,6 +1080,245 @@ declare function calcCCI(data: OHLCV[], options?: CCIOptions): CCIResult[];
941
1080
  */
942
1081
  declare function calcATR(data: OHLCV[], options?: ATROptions): ATRResult[];
943
1082
 
1083
+ /**
1084
+ * OBV - On Balance Volume(能量潮)
1085
+ * 通过成交量的累积来判断股价走势
1086
+ */
1087
+
1088
+ /**
1089
+ * OBV 配置选项
1090
+ */
1091
+ interface OBVOptions {
1092
+ /** OBV 均线周期,默认不计算 */
1093
+ maPeriod?: number;
1094
+ }
1095
+ /**
1096
+ * OBV 计算结果
1097
+ */
1098
+ interface OBVResult {
1099
+ /** OBV 值 */
1100
+ obv: number | null;
1101
+ /** OBV 均线(如果配置了 maPeriod) */
1102
+ obvMa: number | null;
1103
+ }
1104
+ /**
1105
+ * 计算 OBV(能量潮)
1106
+ *
1107
+ * @description
1108
+ * OBV 是一个累积指标,通过比较当日收盘价与前一日收盘价来确定成交量的正负:
1109
+ * - 当日收盘价 > 前日收盘价:OBV = 前日 OBV + 当日成交量
1110
+ * - 当日收盘价 < 前日收盘价:OBV = 前日 OBV - 当日成交量
1111
+ * - 当日收盘价 = 前日收盘价:OBV = 前日 OBV
1112
+ *
1113
+ * @param data K 线数据数组
1114
+ * @param options 配置选项
1115
+ * @returns OBV 结果数组
1116
+ *
1117
+ * @example
1118
+ * const obv = calcOBV(klines);
1119
+ * console.log(obv[10].obv); // OBV 值
1120
+ */
1121
+ declare function calcOBV(data: OHLCV[], options?: OBVOptions): OBVResult[];
1122
+
1123
+ /**
1124
+ * ROC - Rate of Change(变动率指标)
1125
+ * 衡量价格变化的速度和幅度
1126
+ */
1127
+
1128
+ /**
1129
+ * ROC 配置选项
1130
+ */
1131
+ interface ROCOptions {
1132
+ /** ROC 周期,默认 12 */
1133
+ period?: number;
1134
+ /** 信号线周期,默认不计算 */
1135
+ signalPeriod?: number;
1136
+ }
1137
+ /**
1138
+ * ROC 计算结果
1139
+ */
1140
+ interface ROCResult {
1141
+ /** ROC 值(百分比) */
1142
+ roc: number | null;
1143
+ /** ROC 的 MA 信号线 */
1144
+ signal: number | null;
1145
+ }
1146
+ /**
1147
+ * 计算 ROC(变动率指标)
1148
+ *
1149
+ * @description
1150
+ * ROC = (当日收盘价 - N 日前收盘价) / N 日前收盘价 × 100
1151
+ *
1152
+ * 信号解读:
1153
+ * - ROC 由负转正:买入信号
1154
+ * - ROC 由正转负:卖出信号
1155
+ * - ROC 与价格背离:可能的反转信号
1156
+ *
1157
+ * @param data K 线数据数组
1158
+ * @param options 配置选项
1159
+ * @returns ROC 结果数组
1160
+ *
1161
+ * @example
1162
+ * const roc = calcROC(klines, { period: 12 });
1163
+ * console.log(roc[20].roc); // ROC 值
1164
+ */
1165
+ declare function calcROC(data: OHLCV[], options?: ROCOptions): ROCResult[];
1166
+
1167
+ /**
1168
+ * DMI/ADX - Directional Movement Index(趋向指标)
1169
+ * 判断趋势的方向和强度
1170
+ */
1171
+
1172
+ /**
1173
+ * DMI 配置选项
1174
+ */
1175
+ interface DMIOptions {
1176
+ /** 周期,默认 14 */
1177
+ period?: number;
1178
+ /** ADX 平滑周期,默认与 period 相同 */
1179
+ adxPeriod?: number;
1180
+ }
1181
+ /**
1182
+ * DMI 计算结果
1183
+ */
1184
+ interface DMIResult {
1185
+ /** +DI 值 */
1186
+ pdi: number | null;
1187
+ /** -DI 值 */
1188
+ mdi: number | null;
1189
+ /** ADX 值(趋势强度) */
1190
+ adx: number | null;
1191
+ /** ADXR 值(ADX 的平均) */
1192
+ adxr: number | null;
1193
+ }
1194
+ /**
1195
+ * 计算 DMI/ADX(趋向指标)
1196
+ *
1197
+ * @description
1198
+ * DMI 包含三个指标:
1199
+ * - +DI:上升方向指标
1200
+ * - -DI:下降方向指标
1201
+ * - ADX:平均趋向指数,衡量趋势强度
1202
+ *
1203
+ * 信号解读:
1204
+ * - +DI > -DI:上升趋势
1205
+ * - -DI > +DI:下降趋势
1206
+ * - ADX > 25:趋势明显
1207
+ * - ADX < 20:横盘整理
1208
+ *
1209
+ * @param data K 线数据数组
1210
+ * @param options 配置选项
1211
+ * @returns DMI 结果数组
1212
+ *
1213
+ * @example
1214
+ * const dmi = calcDMI(klines, { period: 14 });
1215
+ * console.log(dmi[20].pdi); // +DI
1216
+ * console.log(dmi[20].mdi); // -DI
1217
+ * console.log(dmi[20].adx); // ADX
1218
+ */
1219
+ declare function calcDMI(data: OHLCV[], options?: DMIOptions): DMIResult[];
1220
+
1221
+ /**
1222
+ * SAR - Parabolic SAR(抛物线转向指标)
1223
+ * 判断趋势反转点和止损位
1224
+ */
1225
+
1226
+ /**
1227
+ * SAR 配置选项
1228
+ */
1229
+ interface SAROptions {
1230
+ /** 加速因子初始值,默认 0.02 */
1231
+ afStart?: number;
1232
+ /** 加速因子增量,默认 0.02 */
1233
+ afIncrement?: number;
1234
+ /** 加速因子最大值,默认 0.2 */
1235
+ afMax?: number;
1236
+ }
1237
+ /**
1238
+ * SAR 计算结果
1239
+ */
1240
+ interface SARResult {
1241
+ /** SAR 值 */
1242
+ sar: number | null;
1243
+ /** 当前趋势:1 为上升,-1 为下降 */
1244
+ trend: 1 | -1 | null;
1245
+ /** 极值点 */
1246
+ ep: number | null;
1247
+ /** 加速因子 */
1248
+ af: number | null;
1249
+ }
1250
+ /**
1251
+ * 计算 SAR(抛物线转向指标)
1252
+ *
1253
+ * @description
1254
+ * Parabolic SAR 用于确定价格的趋势方向和潜在的反转点:
1255
+ * - 当价格在 SAR 之上时,SAR 在价格下方,表示上升趋势
1256
+ * - 当价格在 SAR 之下时,SAR 在价格上方,表示下降趋势
1257
+ * - SAR 可用作动态止损位
1258
+ *
1259
+ * @param data K 线数据数组
1260
+ * @param options 配置选项
1261
+ * @returns SAR 结果数组
1262
+ *
1263
+ * @example
1264
+ * const sar = calcSAR(klines);
1265
+ * console.log(sar[20].sar); // SAR 值
1266
+ * console.log(sar[20].trend); // 趋势方向
1267
+ */
1268
+ declare function calcSAR(data: OHLCV[], options?: SAROptions): SARResult[];
1269
+
1270
+ /**
1271
+ * KC - Keltner Channel(肯特纳通道)
1272
+ * 基于 ATR 的价格通道指标
1273
+ */
1274
+
1275
+ /**
1276
+ * KC 配置选项
1277
+ */
1278
+ interface KCOptions {
1279
+ /** EMA 周期,默认 20 */
1280
+ emaPeriod?: number;
1281
+ /** ATR 周期,默认 10 */
1282
+ atrPeriod?: number;
1283
+ /** ATR 倍数,默认 2 */
1284
+ multiplier?: number;
1285
+ }
1286
+ /**
1287
+ * KC 计算结果
1288
+ */
1289
+ interface KCResult {
1290
+ /** 中轨(EMA) */
1291
+ mid: number | null;
1292
+ /** 上轨 */
1293
+ upper: number | null;
1294
+ /** 下轨 */
1295
+ lower: number | null;
1296
+ /** 通道宽度 */
1297
+ width: number | null;
1298
+ }
1299
+ /**
1300
+ * 计算 KC(肯特纳通道)
1301
+ *
1302
+ * @description
1303
+ * Keltner Channel 是一个基于 ATR 的价格通道:
1304
+ * - 中轨 = EMA(close, period)
1305
+ * - 上轨 = 中轨 + multiplier × ATR
1306
+ * - 下轨 = 中轨 - multiplier × ATR
1307
+ *
1308
+ * 与布林带相比,KC 使用 ATR 而非标准差,对价格变化反应更平滑。
1309
+ *
1310
+ * @param data K 线数据数组
1311
+ * @param options 配置选项
1312
+ * @returns KC 结果数组
1313
+ *
1314
+ * @example
1315
+ * const kc = calcKC(klines, { emaPeriod: 20, multiplier: 2 });
1316
+ * console.log(kc[30].upper); // 上轨
1317
+ * console.log(kc[30].mid); // 中轨
1318
+ * console.log(kc[30].lower); // 下轨
1319
+ */
1320
+ declare function calcKC(data: OHLCV[], options?: KCOptions): KCResult[];
1321
+
944
1322
  /**
945
1323
  * 带技术指标的 K 线数据
946
1324
  */
@@ -1097,20 +1475,69 @@ declare class StockSDK {
1097
1475
  search(keyword: string): Promise<SearchResult[]>;
1098
1476
  /**
1099
1477
  * 从远程获取 A 股代码列表
1100
- * @param includeExchange 是否包含交易所前缀(如 sh、sz、bj),默认 true
1478
+ * @param options 配置选项
1479
+ *
1480
+ * @example
1481
+ * // 获取全部 A 股(带交易所前缀)
1482
+ * const codes = await sdk.getAShareCodeList();
1483
+ *
1484
+ * @example
1485
+ * // 获取全部 A 股(不带交易所前缀)
1486
+ * const codes = await sdk.getAShareCodeList({ simple: true });
1487
+ *
1488
+ * @example
1489
+ * // 获取科创板股票
1490
+ * const codes = await sdk.getAShareCodeList({ market: 'kc' });
1491
+ *
1492
+ * @example
1493
+ * // 获取创业板股票(不带前缀)
1494
+ * const codes = await sdk.getAShareCodeList({ simple: true, market: 'cy' });
1101
1495
  */
1102
- getAShareCodeList(includeExchange?: boolean): Promise<string[]>;
1496
+ getAShareCodeList(options?: GetAShareCodeListOptions | boolean): Promise<string[]>;
1103
1497
  /**
1104
1498
  * 从远程获取美股代码列表
1105
- * @param includeMarket 是否包含市场前缀(如 105.、106.),默认 true
1499
+ * @param options 配置选项
1500
+ *
1501
+ * @example
1502
+ * // 获取全部美股(带市场前缀)
1503
+ * const codes = await sdk.getUSCodeList();
1504
+ * // ['105.AAPL', '106.BABA', ...]
1505
+ *
1506
+ * @example
1507
+ * // 获取全部美股(不带市场前缀)
1508
+ * const codes = await sdk.getUSCodeList({ simple: true });
1509
+ * // ['AAPL', 'BABA', ...]
1510
+ *
1511
+ * @example
1512
+ * // 筛选纳斯达克股票
1513
+ * const codes = await sdk.getUSCodeList({ market: 'NASDAQ' });
1514
+ * // ['105.AAPL', ...]
1515
+ *
1516
+ * @example
1517
+ * // 筛选纽交所股票
1518
+ * const codes = await sdk.getUSCodeList({ market: 'NYSE' });
1519
+ * // ['106.BABA', ...]
1106
1520
  */
1107
- getUSCodeList(includeMarket?: boolean): Promise<string[]>;
1521
+ getUSCodeList(options?: GetUSCodeListOptions | boolean): Promise<string[]>;
1108
1522
  /**
1109
1523
  * 从远程获取港股代码列表
1110
1524
  */
1111
1525
  getHKCodeList(): Promise<string[]>;
1112
1526
  /**
1113
1527
  * 获取全部 A 股实时行情
1528
+ * @param options 配置选项
1529
+ *
1530
+ * @example
1531
+ * // 获取全部 A 股行情
1532
+ * const quotes = await sdk.getAllAShareQuotes();
1533
+ *
1534
+ * @example
1535
+ * // 获取科创板行情
1536
+ * const kcQuotes = await sdk.getAllAShareQuotes({ market: 'kc' });
1537
+ *
1538
+ * @example
1539
+ * // 获取创业板行情
1540
+ * const cyQuotes = await sdk.getAllAShareQuotes({ market: 'cy' });
1114
1541
  */
1115
1542
  getAllAShareQuotes(options?: GetAllAShareQuotesOptions): Promise<FullQuote[]>;
1116
1543
  /**
@@ -1119,8 +1546,24 @@ declare class StockSDK {
1119
1546
  getAllHKShareQuotes(options?: GetAllAShareQuotesOptions): Promise<HKQuote[]>;
1120
1547
  /**
1121
1548
  * 获取全部美股实时行情
1549
+ * @param options 配置选项
1550
+ *
1551
+ * @example
1552
+ * // 获取全部美股行情
1553
+ * const quotes = await sdk.getAllUSShareQuotes();
1554
+ *
1555
+ * @example
1556
+ * // 获取纳斯达克股票行情
1557
+ * const nasdaqQuotes = await sdk.getAllUSShareQuotes({ market: 'NASDAQ' });
1558
+ *
1559
+ * @example
1560
+ * // 获取纽交所股票行情(带进度回调)
1561
+ * const nyseQuotes = await sdk.getAllUSShareQuotes({
1562
+ * market: 'NYSE',
1563
+ * onProgress: (completed, total) => console.log(`${completed}/${total}`)
1564
+ * });
1122
1565
  */
1123
- getAllUSShareQuotes(options?: GetAllAShareQuotesOptions): Promise<USQuote[]>;
1566
+ getAllUSShareQuotes(options?: GetAllUSQuotesOptions): Promise<USQuote[]>;
1124
1567
  /**
1125
1568
  * 获取全部股票实时行情(使用自定义股票代码列表)
1126
1569
  */
@@ -1189,4 +1632,4 @@ declare class StockSDK {
1189
1632
  }): Promise<KlineWithIndicators<HistoryKline | HKUSHistoryKline>[]>;
1190
1633
  }
1191
1634
 
1192
- export { type ATROptions, type BIASOptions, type BOLLOptions, type CCIOptions, type ConceptBoard, type ConceptBoardConstituent, type ConceptBoardKline, type ConceptBoardKlineOptions, type ConceptBoardMinuteKline, type ConceptBoardMinuteKlineOptions, type ConceptBoardMinuteTimeline, type ConceptBoardSpot, type FullQuote, type FundFlow, type FundQuote, type GetAllAShareQuotesOptions, type HKQuote, type HKUSHistoryKline, type HistoryKline, HttpError, type IndicatorOptions, type IndustryBoard, type IndustryBoardConstituent, type IndustryBoardKline, type IndustryBoardKlineOptions, type IndustryBoardMinuteKline, type IndustryBoardMinuteKlineOptions, type IndustryBoardMinuteTimeline, type IndustryBoardSpot, type KDJOptions, type KlineWithIndicators, type MACDOptions, type MAOptions, type MarketType, type MinuteKline, type MinuteTimeline, type PanelLargeOrder, type RSIOptions, type RequestClientOptions, type RetryOptions, type SearchResult, type SimpleQuote, StockSDK, type TodayTimeline, type TodayTimelineResponse, type USQuote, type WROptions, addIndicators, asyncPool, calcATR, calcBIAS, calcBOLL, calcCCI, calcEMA, calcKDJ, calcMA, calcMACD, calcRSI, calcSMA, calcWMA, calcWR, chunkArray, decodeGBK, StockSDK as default, parseResponse, safeNumber, safeNumberOrNull };
1635
+ export { type AShareMarket, type ATROptions, type BIASOptions, type BOLLOptions, type CCIOptions, 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 FullQuote, type FundFlow, type FundQuote, type GetAShareCodeListOptions, type GetAllAShareQuotesOptions, type HKQuote, type HKUSHistoryKline, type HistoryKline, HttpError, type IndicatorOptions, type IndustryBoard, type IndustryBoardConstituent, type IndustryBoardKline, type IndustryBoardKlineOptions, type IndustryBoardMinuteKline, type IndustryBoardMinuteKlineOptions, type IndustryBoardMinuteTimeline, type IndustryBoardSpot, type KCOptions$1 as KCOptions, type KCResult$1 as KCResult, type KDJOptions, type KlineWithIndicators, type MACDOptions, type MAOptions, type MarketType, type MinuteKline, type MinuteTimeline, type OBVOptions$1 as OBVOptions, type OBVResult$1 as OBVResult, type PanelLargeOrder, type ROCOptions$1 as ROCOptions, type ROCResult$1 as ROCResult, type RSIOptions, type RequestClientOptions, type RetryOptions, type SAROptions$1 as SAROptions, type SARResult$1 as SARResult, type SearchResult, type SimpleQuote, StockSDK, type TodayTimeline, type TodayTimelineResponse, type USQuote, type WROptions, addIndicators, asyncPool, calcATR, calcBIAS, calcBOLL, calcCCI, calcDMI, calcEMA, calcKC, calcKDJ, calcMA, calcMACD, calcOBV, calcROC, calcRSI, calcSAR, calcSMA, calcWMA, calcWR, chunkArray, decodeGBK, StockSDK as default, parseResponse, safeNumber, safeNumberOrNull };