stock-sdk 1.9.2 → 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.cjs +1 -1
- package/dist/index.d.cts +191 -3
- package/dist/index.d.ts +191 -3
- package/dist/index.js +1 -1
- package/package.json +1 -1
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
|
* 响应解析器
|
|
@@ -258,6 +327,46 @@ declare const MARKET_TZ: {
|
|
|
258
327
|
readonly US: "America/New_York";
|
|
259
328
|
};
|
|
260
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;
|
|
261
370
|
|
|
262
371
|
/**
|
|
263
372
|
* A 股 / 指数 全量行情
|
|
@@ -2719,6 +2828,38 @@ declare global {
|
|
|
2719
2828
|
}
|
|
2720
2829
|
}
|
|
2721
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
|
+
|
|
2722
2863
|
type MarketType = 'A' | 'HK' | 'US';
|
|
2723
2864
|
/**
|
|
2724
2865
|
* `getKlineWithIndicators` 的请求参数
|
|
@@ -2773,6 +2914,53 @@ interface KlineWithIndicatorsOptions {
|
|
|
2773
2914
|
type MarketStatus = 'pre_market' | 'open' | 'lunch_break' | 'after_hours' | 'closed';
|
|
2774
2915
|
/** 支持的市场枚举,用于 `getMarketStatus`。 */
|
|
2775
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
|
+
}
|
|
2776
2964
|
|
|
2777
2965
|
declare class StockSDK {
|
|
2778
2966
|
private readonly client;
|
|
@@ -2806,12 +2994,12 @@ declare class StockSDK {
|
|
|
2806
2994
|
getSimpleQuotes(codes: string[]): Promise<SimpleQuote[]>;
|
|
2807
2995
|
/**
|
|
2808
2996
|
* 获取港股行情
|
|
2809
|
-
* @param codes
|
|
2997
|
+
* @param codes 港股代码数组(5 位数字,无需 `hk` 前缀,如 `['00700', '09988']`)
|
|
2810
2998
|
*/
|
|
2811
2999
|
getHKQuotes(codes: string[]): Promise<HKQuote[]>;
|
|
2812
3000
|
/**
|
|
2813
3001
|
* 获取美股行情
|
|
2814
|
-
* @param codes
|
|
3002
|
+
* @param codes 美股代码数组(无需 `us` 前缀,如 `['AAPL', 'BABA']`)
|
|
2815
3003
|
*/
|
|
2816
3004
|
getUSQuotes(codes: string[]): Promise<USQuote[]>;
|
|
2817
3005
|
/**
|
|
@@ -3253,4 +3441,4 @@ declare class StockSDK {
|
|
|
3253
3441
|
*/
|
|
3254
3442
|
declare function generateSearchExternalLinks(result: SearchResult): ExternalLink[];
|
|
3255
3443
|
|
|
3256
|
-
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 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, 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 USHistoryKline, 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 };
|
package/dist/index.d.ts
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
|
* 响应解析器
|
|
@@ -258,6 +327,46 @@ declare const MARKET_TZ: {
|
|
|
258
327
|
readonly US: "America/New_York";
|
|
259
328
|
};
|
|
260
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;
|
|
261
370
|
|
|
262
371
|
/**
|
|
263
372
|
* A 股 / 指数 全量行情
|
|
@@ -2719,6 +2828,38 @@ declare global {
|
|
|
2719
2828
|
}
|
|
2720
2829
|
}
|
|
2721
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
|
+
|
|
2722
2863
|
type MarketType = 'A' | 'HK' | 'US';
|
|
2723
2864
|
/**
|
|
2724
2865
|
* `getKlineWithIndicators` 的请求参数
|
|
@@ -2773,6 +2914,53 @@ interface KlineWithIndicatorsOptions {
|
|
|
2773
2914
|
type MarketStatus = 'pre_market' | 'open' | 'lunch_break' | 'after_hours' | 'closed';
|
|
2774
2915
|
/** 支持的市场枚举,用于 `getMarketStatus`。 */
|
|
2775
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
|
+
}
|
|
2776
2964
|
|
|
2777
2965
|
declare class StockSDK {
|
|
2778
2966
|
private readonly client;
|
|
@@ -2806,12 +2994,12 @@ declare class StockSDK {
|
|
|
2806
2994
|
getSimpleQuotes(codes: string[]): Promise<SimpleQuote[]>;
|
|
2807
2995
|
/**
|
|
2808
2996
|
* 获取港股行情
|
|
2809
|
-
* @param codes
|
|
2997
|
+
* @param codes 港股代码数组(5 位数字,无需 `hk` 前缀,如 `['00700', '09988']`)
|
|
2810
2998
|
*/
|
|
2811
2999
|
getHKQuotes(codes: string[]): Promise<HKQuote[]>;
|
|
2812
3000
|
/**
|
|
2813
3001
|
* 获取美股行情
|
|
2814
|
-
* @param codes
|
|
3002
|
+
* @param codes 美股代码数组(无需 `us` 前缀,如 `['AAPL', 'BABA']`)
|
|
2815
3003
|
*/
|
|
2816
3004
|
getUSQuotes(codes: string[]): Promise<USQuote[]>;
|
|
2817
3005
|
/**
|
|
@@ -3253,4 +3441,4 @@ declare class StockSDK {
|
|
|
3253
3441
|
*/
|
|
3254
3442
|
declare function generateSearchExternalLinks(result: SearchResult): ExternalLink[];
|
|
3255
3443
|
|
|
3256
|
-
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 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, 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 USHistoryKline, 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 };
|