Files
trade/data/db/entities/exchange.entity.ts
T
Rekey 85a0031a78 feat(data): 实现 Binance WebSocket 适配器与架构重构
- 新增 exchanges/ 模块:MarketDataFeed 统一接口、BaseExchangeAdapter 抽象基类、
  BinanceAdapter 完整实现(WebSocket + REST)
- WebSocket 层基于 binance 官方 SDK 的 WebsocketClient,自动多路复用与断线重连
- REST 层使用 MainClient(Spot),实现 fetchKlines 自动分页补拉 + fetchMarkets 元数据解析
- 数据标准化:Ticker/Trade/OrderBook/Kline 类型定义与 Binance 原生格式互转
- 引入 RxJS Subject 作为统一事件流管道,按 eventType 运行时路由分发
- 重构 config/:YAML 驱动配置加载 + 零依赖运行时校验(fail-fast)
- 重构 db/:TypeORM DataSource 配置 + TimescaleDB K 线 Hypertable 实体
- 新增 utils/logger.ts:Pino 结构化日志(开发环境 pino-pretty 彩色输出)
- 新增 env.yaml 作为 TS/Python 共享的统一环境配置源
- 删除旧版手写 SQL schema 与散落配置文件,收敛到 TypeORM 实体管理
- 安装 rxjs@7.8.2 依赖
2026-06-08 01:24:48 +08:00

42 lines
1.3 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.
// ============================================================
// exchange.entity.ts — 交易所配置实体
// ============================================================
// 映射到 PostgreSQL exchanges 表,存储已接入的交易所元信息。
// 由 TypeORM 管理(关系数据),不与 TimescaleDB 耦合。
//
// 继承 CommonBaseEntityid (UUID) / created_at / updated_at
// ============================================================
import {
Entity,
Column,
OneToMany,
} from "typeorm";
import { CommonBaseEntity } from "./common.entity";
@Entity("exchanges")
export class Exchange extends CommonBaseEntity {
/** 交易所唯一标识(如 binance / okx / bybit */
@Column("varchar", { length: 50, unique: true })
name!: string;
/** 交易所显示名称(如 Binance / OKX / Bybit */
@Column("varchar", { length: 100 })
label!: string;
/** 是否启用该交易所的数据采集 */
@Column("boolean", { default: true })
enabled!: boolean;
/** 交易所特定配置(JSON:费率、最小下单量、API 限频等) */
@Column("jsonb", { nullable: true })
config?: Record<string, unknown>;
/**
* 该交易所下的所有交易对。
* 使用字符串引用避免循环依赖(TradingPair 也引用 Exchange)。
*/
@OneToMany("TradingPair", "exchange")
tradingPairs!: unknown[];
}