PERSISTENCE.md 808 B

持久化(CSV/SQLite)

— 目标 —

  • 记录关键过程数据(净值、成交、持仓快照、订单流)以支持复盘与审计。

— 方案 A:CSV(最小实现) —

  • 路径:data/<date>/
  • 文件:
    • balances.csv: ts, exchange, accountId, asset, total, free
    • positions.csv: ts, exchange, accountId, symbol, side, qty, entryPrice, upnl, lev
    • orders.csv: ts, exchange, accountId, symbol, id, status, side, type, price, origQty, executedQty
    • trades.csv: ts, exchange, accountId, symbol, qty, price, event, direction
  • 频率:balances/positions 每 5-10s;orders/trades 实时追加。

— 方案 B:SQLite(后续) —

  • 表结构与索引:同上;
  • 优点:查询/聚合灵活;

— 数据保留 —

  • 保留 30-90 天;压缩归档;