Files
trade/data/service/pair.ts
T
2026-06-15 23:25:06 +08:00

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