A replay-based XAUUSD trading simulator built for one thing: train execution and risk control without leaking future candles.
- 🧠 Focus: discipline, anti-cheat replay, risk awareness
- 🛠 Stack: FastAPI + Next.js + lightweight-charts
- 🎲 Random historical start per session
- ⏩ Time stepping:
+1M / +5M / +15M / +1H - 🕯 Timeframes:
1M / 5M / 15M / 1H / 4H / 1D - 🔐 Username + password auth (new users get one-time generated password)
- ⚡ Backend fast-forward settlement until
SL / TP / stop_out / data_end - 📈 Personal stats: win rate, Sharpe, total PnL
- 🏆 Global leaderboard
- 🌍 Frontend i18n (Chinese / English)
- Backend:
FastAPI+SQLite - Frontend:
Next.js 14+TypeScript+tailwindcss - Charting:
TradingView lightweight-charts
xauusd_trainer/
├── .env.example
├── docker-compose.yml
├── backend/
│ ├── Dockerfile
│ ├── main.py
│ └── requirements.txt
├── deploy/
│ └── data/
│ └── XAUUSD_1M.parquet
├── frontend/
│ ├── app/
│ ├── components/
│ ├── lib/
│ └── next.config.js
├── assets/
│ └── readme-banner.jpg
└── README.md
cd backend
pip install -r requirements.txt
python main.pyBackend: http://localhost:28761
cd frontend
npm install
npm run devFrontend: http://localhost:3000
/api/* is proxied by next.config.js:
- Local default:
http://localhost:28761/api/* - Production: set
BACKEND_API_BASE(example:https://api.your-domain.com)
cp .env.example .env
# ensure your 1-minute data file exists:
# ./deploy/data/XAUUSD_1M.parquet
docker compose up -d --build backendIf your data directory is elsewhere, set HOST_DATA_DIR in .env to an absolute path.
- New username (3–24 letters/numbers/underscore) auto-creates an account
- A 12-character one-time password is generated for new users
- Save it immediately (copy/screenshot)
- Auth token is hashed server-side and valid for
90days
- Symbol:
XAUUSD - Contract size:
1 lot = 100 oz - Fixed spread:
$0.20(20 points) - Min lot:
0.01 - Min initial balance:
$10 - Max trades per game:
10
Margin model used in this project:
- Gold margin:
1 lot = $1000(so0.01 lot = $10) - Entry requires:
balance >= required margin - Margin ratio:
equity / used margin * 100% - Stop-out trigger:
<= 30%
Price coordinate:
- Chart/K-line =
Bid Ask = Bid + 0.20- Buy entry uses
Ask, Sell entry usesBid - Frontend
SL/TPinput usesBidcoordinate
- Each session has a strict
current_timeboundary - K-line API only returns data
<= current_time - Step API returns incremental 1M bars only
- Random start excludes first
5000and last10000bars
POST /api/auth/loginGET /api/auth/meGET /api/stats/meGET /api/leaderboardPOST /api/game/startGET /api/market/klinesPOST /api/game/stepPOST /api/trade/orderGET /api/game/session/{session_id}
- Session state is cached in memory and recoverable from DB on cache miss/restart
- Users/sessions/trades/steps/logs persist in SQLite at
DB_PATH(defaultbackend/trainer.db, compose:/app/data/trainer.db) - CORS is currently permissive (
allow_origins=["*"]) and should be restricted in production - This project is for training/research use only, not investment advice
- Strict CORS allow-list
- API rate limiting
- Deployment/network boundary hardening
- Monitoring and audit strategy
I built this platform because of an experience in my own family.
My father has traded XAUUSD for a long time. He believes strongly in his method, and often says he can make a few hundred dollars a day.
But over a longer window, his cumulative loss was already more than $8,000.
I was pulled into this market as well.
The beginning looked great. In just a few days, my account went from $3,000 to $9,000+, and it was easy to believe I had finally figured it out.
Then came the extreme move from January 29, 2026 to February 2, 2026. Gold dropped hard, most of the profit was erased, and the account came close to a margin call.
After that, I had to face one fact:
the hardest part of trading is staying clear-headed over time.
So I built this platform.
I want it to pull people back from emotion into rules, and to train execution and risk control in a replayable environment.
I built it for my father first, and as a reminder for myself.
I joined the Upway affiliate program.
If you are looking for a live/demo gold trading platform, you can use my referral link:
https://login.jrjr.com/#/user/reg/tjsid=851345
If you register via this link, I may receive an affiliate commission.
Thank you for supporting this project ❤️
