A newer version of the Streamlit SDK is available: 1.62.0
Testnet Trading Implementation Plan
Goal
Mirror the DRL bot's LONG/SHORT trading decisions to Binance Testnet with real order execution and full dashboard visibility.
Architecture
Constraints
- Binance Testnet (testnet.binance.vision) is SPOT only β no futures/perpetuals
- LONG positions: execute real BUY orders on testnet
- CLOSE LONG: execute real SELL orders on testnet
- SHORT/CLOSE SHORT: recorded as conceptual trades (spot can't truly short); if base currency held, it is sold
Components
1. src/api/testnet_executor.py (NEW)
TestnetExecutorclass β singleton used by orchestrator and api_servermirror_trade(bot_trade, bot_result)β translates bot decision β real testnet orderget_current_positions()β live positions with current prices + unrealized PNLget_trades(limit)β read fromlogs/testnet_trades.jsonget_pnl_summary()β realized + unrealized PNL, win rate- Stores each trade in
logs/testnet_trades.json(line-delimited JSON) - Uses
BinanceConnectorfor all API calls - Reads
BINANCE_TESTNET_API_KEY/BINANCE_TESTNET_API_SECRETfrom env
2. src/ui/api_server.py (MODIFIED β 4 new endpoints)
GET /api/testnet/tradesβ trade history from testnet_trades.jsonGET /api/testnet/positionsβ open positions with live prices + unrealized PNLGET /api/testnet/pnlβ realized + unrealized PNL summary + equity curve dataPOST /api/testnet/executeβ manually trigger a testnet trade (for testing)
3. live_trading_multi.py (MODIFIED β auto-execution hook)
MultiAssetOrchestrator.__init__: instantiateTestnetExecutorifTESTNET_MIRROR=truerun_single_cycle(): after each bot decision, callself.testnet_executor.mirror_trade()- Log both dry-run result and testnet execution result
- Guard with try/except so testnet failures never block the main trading loop
4. src/ui/app.py (MODIFIED β enhanced Testnet tab)
New sections added to the Testnet tab (all data from API endpoints):
- Open Positions table: symbol, side, entry price, current price, unrealized PNL, SL, TP
- Trade History table: timestamp, symbol, action, price, amount, PNL, order_id
- PNL Summary: realized, unrealized, total, win rate, total trades
- Equity Curve chart: cumulative PNL over time (Plotly line chart)
- Live Order Book: open/pending orders from
/api/testnet/orders
5. tests/test_testnet_trading.py (NEW)
- Test testnet connectivity
- Test place a small market order on testnet
- Test
/api/testnet/tradesreturns list - Test
/api/testnet/positionsreturns list - Test PNL calculation
Data Flow
Bot run_iteration()
ββ> execute_trade() β trade dict
ββ> [if TESTNET_MIRROR=true]
ββ> TestnetExecutor.mirror_trade()
ββ> BinanceConnector.place_market_order() (50%)
ββ> BinanceConnector.place_limit_order() (50%)
ββ> _save_trade() β logs/testnet_trades.json
Dashboard (app.py Testnet Tab)
ββ> GET /api/testnet/status (existing β balance/portfolio)
ββ> GET /api/testnet/positions (new β open bot-mirrored positions)
ββ> GET /api/testnet/trades (new β trade history)
ββ> GET /api/testnet/pnl (new β PNL + equity curve)
ββ> GET /api/testnet/orders (existing β open orders)
Trade Record Schema
{
"symbol": "BTCUSDT",
"ccxt_symbol": "BTC/USDT",
"action": "OPEN_LONG_SPLIT",
"side": "BUY",
"price": 43250.50,
"filled_price": 43251.00,
"amount": 0.00578,
"sl": 41087.98,
"tp": 46000.25,
"confidence": 0.72,
"timestamp": "2026-03-19T14:32:00.000Z",
"order_id": "12345678",
"limit_order_id": "12345679",
"limit_price": 43034.87,
"limit_amount": 0.00579,
"executed": true,
"error": null,
"pnl": null,
"dry_run": false
}
Environment Variables
TESTNET_MIRROR=trueβ enables auto-execution hook (default: false)BINANCE_TESTNET_API_KEYβ testnet API key (already set)BINANCE_TESTNET_API_SECRETβ testnet API secret (already set)BINANCE_TESTNET_PROXY_URLβ optional Cloudflare proxy (already set)
Risk Controls
- TestnetExecutor failures are caught and logged β never block main loop
- Minimum trade value: $10 USDT
- Max position: 25% of testnet USDT balance Γ confidence scale
- Split entry: 50% market + 50% limit (mirrors bot logic)
- No automatic SL/TP orders placed (bot logic manages exits and mirrors them)