85a0031a78
- 新增 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 依赖
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import { DataSource } from "typeorm";
|
|
import { pgsql } from "../config";
|
|
import * as entities from "./entities";
|
|
|
|
export const AppDataSource = new DataSource({
|
|
type: "postgres",
|
|
host: pgsql.host,
|
|
port: pgsql.port,
|
|
database: pgsql.database,
|
|
username: pgsql.user,
|
|
password: pgsql.password,
|
|
// 实体注册:关系实体通过 entities/index.ts 统一导出
|
|
// TimescaleDB K 线实体后续通过 @timescaledb/typeorm 装饰器注册
|
|
entities: [
|
|
...Object.values(entities),
|
|
],
|
|
// 生产环境禁用 synchronize,使用 Migration
|
|
synchronize: true,
|
|
migrations: [__dirname + "/migrations/*.{ts,js}"],
|
|
// 连接池
|
|
extra: {
|
|
max: pgsql.max, // 最大连接数 20
|
|
idleTimeoutMillis: pgsql.idleTimeoutMillis, // 空闲超时 30s
|
|
connectionTimeoutMillis: pgsql.connectionTimeoutMillis, // 连接超时 5s
|
|
},
|
|
logging: process.env.NODE_ENV === "development" ? ["error", "warn"] : ["error"],
|
|
});
|
|
|
|
await AppDataSource.initialize(); |