mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-04-17 13:21:31 +00:00
2.1 KiB
2.1 KiB
Phase 03 — Trading Trade History: Implementation Report
Files Modified / Created
| File | Action |
|---|---|
src/modules/trading/migrations/0001_trades.sql |
Created — schema + 2 indexes |
src/modules/trading/history.js |
Created — recordTrade, listTrades, formatTradesHtml, createHistoryHandler |
src/modules/trading/handlers.js |
Modified — handleBuy/handleSell accept optional onTrade callback |
src/modules/trading/index.js |
Modified — accept sql in init, wire onTrade, register /history command |
tests/modules/trading/history.test.js |
Created — 21 tests |
plans/260415-1010-d1-cron-infra/phase-03-trading-history.md |
Status → Complete, todos ticked |
plans/260415-1010-d1-cron-infra/plan.md |
Phase 03 → Complete |
Tasks Completed
- Migration SQL (
trading_trades+ 2 indexes) recordTrade— inserts row, logs+swallows on failure, skips silently when sql=nulllistTrades— camelCase mapping, limit clamp [1..50], returns [] when sql=nullformatTradesHtml— HTML-escaped symbols, BUY/SELL labels, Telegram HTML modecreateHistoryHandler— parses N, defaults to 10, clamps to 50- Wired into buy/sell via
onTradecallback pattern (keeps handlers.js clean) /historyregistered as public command in index.js
Tests Status
- Type check: N/A (plain JS)
- Unit tests: 160/160 pass (21 new in history.test.js)
- Lint: clean (Biome + ESLint)
Design Notes
onTradecallback pattern chosen over passingsqldirectly into handlers — keeps handlers.js unaware of D1, easier to test in isolation.createHistoryHandlertakessqlat factory time;index.jsuses a lazy wrapper(ctx) => createHistoryHandler(sql)(ctx)so the module-levelsqlvariable (set ininit) is captured correctly after startup.recordTradefailure path: try/catch logsconsole.errorand returns — portfolio KV remains source of truth.
Status: DONE
Summary: Phase 03 complete — trade history table, /history command, buy/sell wiring, 21 tests all green, lint clean.