Files
miti99bot/plans/260414-1457-trading-module/plan.md
tiennm99 c9270764f2 feat: add fake trading module with crypto, stocks, forex and gold
Paper trading system with 5 commands (trade_topup, trade_buy,
trade_sell, trade_convert, trade_stats). Supports VN stocks via TCBS,
crypto via CoinGecko, forex via ER-API, and gold via PAX Gold proxy.
Per-user portfolio stored in KV with 60s price caching. 54 new tests.
2026-04-14 15:16:53 +07:00

1.9 KiB

title, description, status, priority, effort, branch, tags, created
title description status priority effort branch tags created
Fake Trading Module Paper trading module for Telegram bot — virtual portfolio with crypto, stocks, forex, gold pending P2 6h main
feature
module
trading
2026-04-14

Fake Trading Module

Phases

# Phase Status Effort Files
1 Symbol registry + formatters Pending 45m src/modules/trading/symbols.js, src/modules/trading/format.js
2 Price fetching + caching Pending 1h src/modules/trading/prices.js
3 Portfolio data layer Pending 45m src/modules/trading/portfolio.js
4 Command handlers + module entry Pending 1.5h src/modules/trading/index.js
5 Integration wiring Pending 15m src/modules/index.js, wrangler.toml
6 Tests Pending 1.5h tests/modules/trading/*.test.js

Dependencies

Phase 1 ──┐
Phase 2 ──┼──► Phase 4 ──► Phase 5
Phase 3 ──┘                    │
Phase 1,2,3,4 ────────────► Phase 6

Data flow

User /trade_buy 0.5 BTC
  -> index.js parses args, validates
  -> prices.js fetches BTC/VND (cache-first, 60s TTL)
  -> portfolio.js reads user KV, checks VND balance
  -> portfolio.js deducts VND, adds BTC qty, writes KV
  -> format.js renders reply
  -> ctx.reply()

Rollback

Remove trading from MODULES in wrangler.toml + src/modules/index.js. KV data inert.

Key decisions

  • VND sole settlement currency for buy/sell
  • Single KV object per user (acceptable race for paper trading)
  • 60s price cache TTL via KV putJSON with expirationTtl
  • Gold via PAX Gold on CoinGecko (troy ounces)
  • Stocks integer-only quantities