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
+6 -2
View File
@@ -24,7 +24,7 @@ import {
UpdateDateColumn,
} from "typeorm";
import type { KlineInterval } from '../../types';
import type { KlineInterval, PairType } from '../../types';
/**
* 1 分钟 K 线 Hypertable
@@ -40,7 +40,7 @@ import type { KlineInterval } from '../../types';
compression: {
compress: true,
compress_orderby: "time DESC",
compress_segmentby: "exchange, symbol",
compress_segmentby: "exchange, symbol, type",
policy: {
schedule_interval: "30 days", // 30 天后自动压缩
},
@@ -65,6 +65,10 @@ export class Kline {
@PrimaryColumn("text")
symbol!: string;
/** 交易对类型(如 spot */
@PrimaryColumn("text", { default: 'spot' })
type!: PairType;
/** K 线周期(1m */
@PrimaryColumn("text")
interval!: KlineInterval;
+6 -1
View File
@@ -21,9 +21,10 @@ import {
} from "typeorm";
import { Exchange } from "./exchange.entity";
import { CommonBaseEntity } from "./common.entity";
import type { KlineInterval, PairType } from '../../types';
@Entity("trading_pairs")
@Index(["exchange", "symbol"], { unique: true }) // 同一交易所下 symbol 唯一
@Index(["exchange", "symbol", "type"], { unique: true }) // 同一交易所下 symbol + type 唯一
@Index(["active"]) // 按激活状态快速筛选
export class TradingPair extends CommonBaseEntity {
/** 所属交易所 */
@@ -35,6 +36,10 @@ export class TradingPair extends CommonBaseEntity {
@Column("varchar", { length: 20 })
symbol!: string;
/** 交易对类型(如 spot */
@Column("text", { default: 'spot' })
type!: PairType;
/** 基础币种(如 BTC */
@Column("varchar", { length: 10 })
base_asset!: string;