refactor(exchanges): fetchKlines 改为 params 对象签名,新增 type/exchange 参数
- 新增 FetchKlinesParams 接口统一 fetchKlines 参数(exchange/type/symbol/startTime/limit/endTime) - BaseRestClient 抽象方法 + MarketDataFeed 接口改为 params 对象签名 - BinanceRestClient / BinanceFuturesRestClient 由调用方传入 type,不再硬编码 spot/um - index.ts 新增静态 fetchKlines(params) 便捷函数,按 exchange+type 自动路由 - exchange.ts / bnkline.ts 调用方适配新签名 - 初始化 SQL 补充 BNBUSDT/SOLUSDT 合约交易对
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { logger } from "../utils/logger";
|
||||
import { getAllPairs, updatePairLastBackfillTime } from '../service/pair';
|
||||
import { upsertOrUpdateKlines } from "../service/kline";
|
||||
import { createRestClient } from '../exchanges';
|
||||
import { fetchKlines } from '../exchanges';
|
||||
|
||||
function getNowMinuteMS() {
|
||||
const minuteMS = 1000 * 60;
|
||||
@@ -11,17 +11,17 @@ function getNowMinuteMS() {
|
||||
const allPairs = await getAllPairs();
|
||||
|
||||
for (const pair of allPairs) {
|
||||
const exchangeId = pair.type === 'um' ? 'binance_futures' : 'binance';
|
||||
const client = createRestClient(exchangeId);
|
||||
let lastBackfillTime = pair.last_backfill_time.getTime();
|
||||
try {
|
||||
while (lastBackfillTime < getNowMinuteMS()) {
|
||||
console.log('lastBackfillTime', lastBackfillTime);
|
||||
const klines = await client.fetchKlines(
|
||||
pair.symbol,
|
||||
lastBackfillTime,
|
||||
500
|
||||
);
|
||||
const klines = await fetchKlines({
|
||||
exchange: 'binance',
|
||||
type: pair.type,
|
||||
symbol: pair.symbol,
|
||||
startTime: lastBackfillTime,
|
||||
limit: 500,
|
||||
});
|
||||
console.log(`拉取到 ${klines.length} 条 K 线`);
|
||||
if (klines.length > 0) {
|
||||
await upsertOrUpdateKlines(klines);
|
||||
|
||||
Reference in New Issue
Block a user