Files
trade/data/service/pair.ts
T
Rekey 705a2f6ea0 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 空函数
2026-06-16 18:39:40 +08:00

55 lines
1.7 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 { AppDataSource } from "../db/data-source";
import { TradingPair } from "../db/entities/trading-pair.entity";
import type { PairType } from '../types';
const repo = AppDataSource.getRepository(TradingPair);
/**
* 获取所有交易对列表。
*
* 从 trading_pairs 表中查询全部记录,返回完整交易对信息,
* 常用于行情拉取时遍历所有币种、或管理界面展示。
*/
export async function getAllPairs() {
const pairs = await repo.find({});
return pairs;
}
/**
* 获取指定交易对的历史 K 线最后补全时间。
*
* @param symbol - 交易对名称(如 "BTCUSDT"
* @param type - 交易对类型(默认 'spot'
* @returns 最后补全时间(UTC),若交易对不存在返回 undefined
*/
export async function getPairLastBackfillTime(symbol: string, type: PairType = 'spot') {
const pair = await repo.findOneBy({
symbol,
type,
});
return pair?.last_backfill_time;
}
/**
* 更新指定交易对的历史 K 线最后补全时间。
*
* 在批量回补 K 线数据后调用,记录已补全的时间断点,
* 下次回补时从该时间点之后开始拉取,避免重复。
*
* @param symbol - 交易对名称(如 "BTCUSDT"
* @param time - 新的最后补全时间(UTC)
* @param type - 交易对类型(默认 'spot'
* @returns 保存后的交易对实体,若交易对不存在返回 undefined
*/
export async function updatePairLastBackfillTime(symbol: string, time: Date, type: PairType = 'spot') {
const pair = await repo.findOneBy({
symbol,
type,
});
if (pair === null) {
return;
}
pair.last_backfill_time = time;
return pair.save();
}