HARSHARAVURI/stoker-mft
0
Stoker MFT — Multi-Agent Medium-Frequency Trading Simulation
A paper-trading simulation environment powered by a LangGraph-orchestrated committee of 6 specialized AI agents. Scans markets 24/7 — executing live during market hours and queuing proposals off-hours for execution at open.
No real orders are executed by default. This is a research and simulation tool only.
Live: huggingface.co/spaces/HARSHARAVURI/stoker-mft
Agent Pipeline
──────────────── Market Hours ────────────────────────────────
[Auto-scanner: every 15 min during NSE / NYSE hours]
│
▼
Fundamental → Screener → Quant → Risk ──APPROVED──► Execution (Meta)
└──REJECTED──► END
──────────────── Off-Hours / Holidays ────────────────────────
[Hourly pre-market scan]
│
▼
Fundamental → Screener → Quant → Risk ──APPROVED──► Queue Node → trade_queue DB
└──REJECTED──► END
[On market open (non-holiday)] → drain trade_queue → Execution (Meta)LLM Stack
Market Coverage
Scheduling Logic
Risk Rules (Deterministic — Not LLM-Overridable)
Observability — What Gets Logged
Structured logs (Logs tab — JSON-lines, IST timestamps)
learnings.md (project root — auto-appended on every trade close)
Each entry contains: entry rationale, market theme, planned R:R, confidence, close price, actual P&L, and a templated lesson per outcome type (WIN / LOSS / TIME). Accumulates over time as institutional memory for the system.
UI Tabs
Trade Intelligence Panel
Clicking any row in the Trade Ledger expands a full breakdown:
- Why we entered — market theme (Fundamental agent), Portfolio Manager's LLM rationale, confidence gauge
- Position metrics — entry / TP / SL with % distances, notional value, max reward, max risk, R:R ratio
- Why we exited — contextual explanation per status:
OPEN— conditions that will trigger a close, time in trade so farCLOSED_TP— "Take Profit hit" with close price vs planCLOSED_SL— "Stop Loss triggered" with loss vs max riskCLOSED_TIME— actual price move over hold period, neither target reached- Agent decision chain — table showing each agent's specific decision for this trade
Local Setup
pip install -r requirements.txt
cp .env.example .env # add GOOGLE_API_KEY at minimum (free at aistudio.google.com)
python app.py # Gradio UI → http://localhost:7860
python run_cycle.py # single IN market cycle (CLI)
python run_cycle.py --market US # single US market cycle (CLI)
python feedback_loop.py --days 7 --save # weekly review + save suggestionsEnvironment Variables
Required (at least one LLM key)
Optional
Live Trading (only when gate is passed)
WithoutDATABASE_URL, SQLite is used — trade data and the queue reset on every HF Space restart. Set a Neon or SupabaseDATABASE_URLfor persistence.
Live Trading Gate
Blocked until all four criteria are met (checked programmatically before every live order):
Project Structure
stoker_mft/
├── app.py Gradio UI (5 tabs)
├── run_cycle.py CLI test runner
├── feedback_loop.py Weekly performance review
├── learnings.md Auto-generated trade learnings log (appended on every close)
├── holidays.json Cached market holiday calendar (refreshed every Sunday)
├── requirements.txt
├── Dockerfile / run.sh HF Docker Space
│
├── graph/
│ ├── state.py TradingDeskState TypedDict (includes queue_mode flag)
│ ├── graph.py LangGraph wiring (Execution + Queue nodes)
│ └── nodes/
│ ├── fundamental.py News → market theme + bias
│ ├── opportunity.py RVOL scanner → watchlist
│ ├── quant.py Indicators → trade proposal (logs indicator snapshot)
│ ├── risk.py Deterministic veto (logs every rejection with reason)
│ ├── meta.py Slippage + ledger + broker (market-hours execution)
│ └── queue_node.py Off-hours — saves approved proposal to trade_queue table
│
├── tools/
│ ├── llm_factory.py Gemma 3 27B → gpt-5-nano fallback chain
│ ├── market_data.py yfinance wrappers + ticker validation
│ ├── indicators.py RSI, MACD, Bollinger, VWAP, EMA 9/21, ATR
│ ├── news_scraper.py DuckDuckGo + Finnhub news
│ ├── holiday_calendar.py Tavily/DDGS holiday fetch, is_holiday(), weekly Sunday refresh
│ ├── slippage.py Entry/exit slippage simulation + commission
│ ├── broker.py Zerodha + Alpaca order routing
│ ├── live_gate.py Live trading validation gate
│ ├── kill_switch.py 5% session drawdown halt
│ ├── alerts.py Telegram + email notifications
│ ├── logger.py IST-aware JSON-lines structured logging
│ └── scheduler.py 24/7 scanner — live, off-hours, holiday, queue drain, Sunday fetch
│
├── database/
│ ├── schema.sql trades, agent_runs, portfolio, trade_queue tables
│ ├── ledger.py SQLite/PostgreSQL CRUD + Postgres compatibility layer
│ ├── tracker.py Mark-to-market background loop (TP/SL/time exits)
│ ├── queue.py Trade queue CRUD (enqueue, drain, expire)
│ └── learnings.py Auto-appends to learnings.md on every trade close
│
└── logs/ Daily JSON-lines logs (IST timestamps, auto-created)