feat: 接入 USDT-M 合约数据 — type 字段方案

- PairType 定义移至 types/kline.ts (spot/um/cm)
- Kline 接口新增 type 字段,全链路透传
- klines 5列复合主键 (exchange, symbol, type, interval, time)
- 拆出 BinanceFuturesRestClient (USDMClient)
- exchanges/index.ts 注册 binance_futures
- trading_pairs 唯一约束加 type,种子数据加合约对
- 12个连续聚合视图 SELECT/GROUP BY/INDEX 加 type
- 清理 bnkline.ts 废弃代码和 pair.ts 空函数
This commit is contained in:
Rekey
2026-06-16 18:39:40 +08:00
parent 1adb093100
commit 705a2f6ea0
15 changed files with 442 additions and 209 deletions
+9 -4
View File
@@ -1,5 +1,6 @@
import { AppDataSource } from "../db/data-source";
import { TradingPair } from "../db/entities/trading-pair.entity";
import type { PairType } from '../types';
const repo = AppDataSource.getRepository(TradingPair);
@@ -18,11 +19,13 @@ export async function getAllPairs() {
* 获取指定交易对的历史 K 线最后补全时间。
*
* @param symbol - 交易对名称(如 "BTCUSDT"
* @param type - 交易对类型(默认 'spot'
* @returns 最后补全时间(UTC),若交易对不存在返回 undefined
*/
export async function getPairLastBackfillTime(symbol: string) {
export async function getPairLastBackfillTime(symbol: string, type: PairType = 'spot') {
const pair = await repo.findOneBy({
symbol
symbol,
type,
});
return pair?.last_backfill_time;
}
@@ -35,11 +38,13 @@ export async function getPairLastBackfillTime(symbol: string) {
*
* @param symbol - 交易对名称(如 "BTCUSDT"
* @param time - 新的最后补全时间(UTC)
* @param type - 交易对类型(默认 'spot'
* @returns 保存后的交易对实体,若交易对不存在返回 undefined
*/
export async function updatePairLastBackfillTime(symbol: string, time: Date) {
export async function updatePairLastBackfillTime(symbol: string, time: Date, type: PairType = 'spot') {
const pair = await repo.findOneBy({
symbol
symbol,
type,
});
if (pair === null) {
return;