Building Crypto Analysis Dashboards
Build real, working multi-file applications, not mockups. Deliver incrementally in stages, verifying each stage runs before moving to the next.
Produce this file structure, in this order, each file complete and runnable before moving to the next:
crypto_dashboard/
├── app.py # Streamlit entrypoint, navigation, layout
├── market_data.py # Binance public API wrapper + demo fallback
├── indicators.py # EMA, RSI, MACD, ATR, support/resistance
├── signals.py # Rule-based BUY/SELL/HOLD engine
├── risk_management.py # Position sizing / R:R calculator
├── paper_trading.py # Virtual trade engine
├── database.py # SQLite schema + CRUD
├── requirements.txt
└── README.md # Run instructions (deliver at the end)
Core dependency set (no paid/keyed APIs):
streamlit
pandas
numpy
plotly
requests
Progress:
- Stage 1:
market_data.py+app.pyskeleton — live market scanner, dashboard shell, demo-mode fallback - Stage 2:
indicators.py+signals.py— multi-timeframe technical analysis, transparent signal engine - Stage 3:
risk_management.py— position sizing calculator - Stage 4:
database.py+paper_trading.py— virtual trades, history, win rate - Stage 5: Integration pass — error handling, empty-data guards, manual test of every section
Stage 1 — Market data & scanner
- Wrap Binance public endpoints (
/api/v3/ticker/24hr,/api/v3/exchangeInfo,/api/v3/klines) withrequests, timeout + try/except on every call. - Filter to
USDT-quoted symbols, sort by quote volume, slice top 50. - On any failure (timeout, non-200, malformed JSON), return a clearly tagged
DEMOdataset — same schema, obviously synthetic values — never silently substitute. - Cache last successful fetch timestamp; display it in the UI header ("Live data as of HH:MM:SS UTC" vs "DEMO MODE — Binance unreachable").
- Build
app.pysidebar nav for the 11 required sections, stub pages that show "under construction" until later stages wire them up.
Stage 2 — Indicators & signals
- Implement EMA20/EMA50, RSI14, MACD(12,26,9), ATR14 with pure pandas/numpy — guard against
NaN/divide-by-zero (e.g., RSI when avg loss = 0 → RSI = 100, not an exception). - Pull klines for
1h,4h,1d; run indicators on each independently; require minimum bar count (e.g., 60+) before producing a non-HOLD signal — insufficient data → explicit "insufficient data" HOLD. - Signal engine: score each indicator's vote (+1 bullish / -1 bearish / 0 neutral), sum into a 0–100 score, never label it a probability or win rate.
- Output object per signal:
symbol, price, entry, stop_loss, take_profit_1, take_profit_2, risk_reward, score, timeframe, reasons[list of strings], indicator_votes[dict]. - Entry = current price (or pullback to EMA20 if trending); stop = recent swing low/high or
price ± 1.5*ATR; TP1/TP2 =entry ± 1x/2xthe stop distance. Never emit a BUY/SELL above a "strong" threshold if indicators disagree (e.g., RSI bullish but MACD bearish) — downgrade to HOLD with reasons listed.
Stage 3 — Risk calculator
- Inputs: balance, risk % (default 1%), entry, stop-loss.
risk_amount = balance * risk_pct/100;per_unit_risk = abs(entry - stop); guardper_unit_risk == 0→ show validation error, don't divide.position_size = risk_amount / per_unit_risk;potential_loss = risk_amount;potential_profit = position_size * abs(tp - entry);rr = potential_profit / potential_loss.- Show every formula inline in an expander so users see the math, not a black box.
Stage 4 — Paper trading
- SQLite tables:
trades(id, symbol, side, entry_price, exit_price, size, stop_loss, take_profit, status, pnl, fee, opened_at, closed_at),settings(key, value). - Starting balance constant = $10,000, stored in
settings, resettable from Settings page. - Configurable fee % and slippage % (defaults: 0.1% fee, 0.05% slippage) applied on open and close.
- Compute win rate =
wins / closed_trades_count(guard divide-by-zero → show "N/A" with 0 trades). Track running realized P&L + unrealized P&L on open positions using latest fetched price. - Absolutely no code path that calls an order-placement endpoint — paper trading must be pure local simulation.
Stage 5 — Integration & verification
- Click through all 11 sections manually; confirm no unhandled exceptions when: Binance is down, a symbol has <60 candles, stop==entry in risk calc, balance=0, zero closed trades.
- Confirm demo vs live labeling is visible on every data-driven page.
- Confirm timestamps update on refresh.
Example 1: Input: "Binance API times out while fetching the top-50 scanner." Output: Scanner page shows a red banner "⚠️ Live data unavailable — showing DEMO data (not real prices)" and renders the same table layout populated with clearly-labeled synthetic rows; last-successful-update timestamp keeps its last real value and is marked stale.
Example 2: Input: BTC 1h: EMA20 > EMA50, RSI 58, MACD histogram positive, volume average. 4h: EMA20 < EMA50, RSI 44. Output: Score ~55/100, signal = HOLD (not BUY) because timeframes disagree; reasons list both supporting (1h bullish EMA/RSI/MACD) and opposing (4h bearish EMA crossover) factors explicitly, so the user sees the conflict rather than a falsely confident BUY.
- Every external call wrapped in try/except with a specific fallback path — never let a network error crash the app.
- Every arithmetic division preceded by a zero-check.
- Label data source ("LIVE" / "DEMO") on every chart, table, and signal card — no ambiguity.
- Keep signal logic fully inspectable: expose the indicator votes and reasons, not just the final verdict.
- Use
st.cache_data(ttl=...)for market data fetches to avoid hammering Binance and to keep the UI responsive. - Default to conservative risk settings (1% risk/trade, 2:1 min R:R highlighted) but let users override.
- Keep
indicators.pyandsignals.pyfree of any Streamlit imports — pure functions, independently testable. - Leave a clearly marked extension point (e.g.,
signals.py::score_with_ml()stub, currently unused) so future ML work doesn't require restructuring, but don't claim ML exists today.
- Don't present the 0–100 signal score as a win probability, confidence %, or accuracy guarantee — it's a rule-tally only.
- Don't silently fall back to demo data without a visible label — this is a trust-breaking failure.
- Don't generate BUY/SELL signals from fewer than ~60 candles — emit HOLD with "insufficient data" reason instead.
- Don't skip fee/slippage in paper trading — unrealistic P&L misleads users about real trading costs.
- Don't implement or wire any real-money order execution path, even behind a flag.
- Don't let RSI/MACD/ATR computations throw on short or flat price series — always guard edge cases (zero variance, single price repeated, etc.).
- Don't stop at the dashboard UI — each section must be backed by working logic before calling a stage complete.