Files
trade/data/exchanges/index.ts
T
Rekey 1adb093100 refactor(data/exchanges): 多子类架构 + 工厂入口
- 每个交易所独立子类:BinanceRestClient extends BaseRestClient
- 统一入口 createRestClient(exchangeId) 工厂函数
- KLINE_INTERVAL_MS 移至 constants.ts
- fetchKlines 签名统一为 (symbol, startTime, limit?, endTime?)
- throttle 限流实际生效
- convertBinanceKline interval 参数化
- 删除 filterConsecutive 死代码
- 更新 run/exchange.ts 和 service/bnkline.ts 调用方
2026-06-16 17:53:36 +08:00

33 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { BaseRestClient } from "./base";
import { BinanceRestClient } from "./binance/rest";
/** 交易所 ID 到 RestClient 构造器的注册表 */
const registry: Record<string, () => BaseRestClient> = {
binance: () => new BinanceRestClient(),
};
/**
* 创建交易所 REST 客户端。
*
* 根据交易所 ID 返回对应的 RestClient 实例,
* 外部无需感知具体子类。
*
* @param exchangeId - 交易所标识(如 "binance"
* @returns 对应交易所的 RestClient 实例
* @throws 如果 exchangeId 未注册
*/
export function createRestClient(exchangeId: string): BaseRestClient {
const factory = registry[exchangeId];
if (!factory) {
const supported = Object.keys(registry).join(", ");
throw new Error(
`[exchanges] 不支持的交易所: "${exchangeId}",当前支持: ${supported}`,
);
}
return factory();
}
export { BaseRestClient } from "./base";
export { BinanceRestClient } from "./binance/rest";
export { KLINE_INTERVAL_MS } from "./constants";