refactor(data): 重构交易所适配器,修复 Kline 实体复合主键

- 废弃旧 adapter 体系 (base/binance/types.ts),新增 base_rest/rest.ts
  基于 Binance 官方 SDK 实现 REST K 线拉取
- Kline 实体改为四列复合主键 (exchange/symbol/interval/time),
  修复单列 time PK 导致的跨 symbol 写入冲突
- 新增 filterConsecutive():K 线连续性过滤,首缺口截断策略
- 新增 service/kline.ts:批量 UPSERT K 线入库
- 新增 types/ 共享类型定义、example/ 示例、run/ 运行脚本
This commit is contained in:
Rekey
2026-06-08 18:18:16 +08:00
parent 85a0031a78
commit 5e385547c7
16 changed files with 829 additions and 1043 deletions
+27
View File
@@ -0,0 +1,27 @@
import { AppDataSource } from "../db/data-source";
import { TradingPair } from "../db/entities/trading-pair.entity";
const repo = AppDataSource.getRepository(TradingPair);
export async function getAllPairs() {
const pairs = await repo.find({});
return pairs;
}
export async function getPairLastBackfillTime(symbol: string) {
const pair = await repo.findOneBy({
symbol
});
return pair?.last_backfill_time;
}
export async function updatePairLastBackfillTime(symbol: string, time: Date) {
const pair = await repo.findOneBy({
symbol
});
if (pair === null) {
return;
}
pair.last_backfill_time = time;
return pair.save();
}