--- frontmattername: python-trading-bot
description: Generate, refactor, and maintain Python live trading bots for NQ futures prop firm trading (Apex Trader Funding). Supports Databento API for market data, TradersPost for execution, eval/PA modes, custom strategies, and comprehensive production features. Triggers: "live trading bot", "Python bot", "NQ bot", "futures bot", "create bot", "refactor bot", "/bot:new", "/bot:refactor", "/bot:custom".
allowed-tools: Read, Write, Edit, Grep, Glob, Bash(pip:*, python3:*)
Python Trading Bot Skill
Generate, refactor, and maintain production-ready Python trading bots for NQ futures prop firm trading with:
- •Databento API for real-time and historical market data
- •TradersPost webhooks for order execution (Apex Trader Funding compatible)
- •Eval and PA modes with trailing drawdown, profit targets, dynamic sizing
- •5 backtested signals + support for custom strategies
- •Production features (state persistence, news filtering, alerting, comprehensive testing)
Commands
Bot Generation
| Command | Description |
|---|
/bot:new | Start interactive bot builder (with eval/PA mode selection) |
/bot:new <signal> | Start with signal pre-selected |
/bot:custom | Build bot with custom strategy/indicators |
/bot:keltner | Generate Keltner Channel bot (PF 10.04) |
/bot:ema | Generate EMA Cross bot (PF 6.23) |
/bot:vwap | Generate Rolling VWAP bot (PF 5.20) |
/bot:supertrend | Generate SuperTrend bot (PF 4.41) |
/bot:alligator | Generate Alligator bot (PF 4.16) |
/bot:list | Show signals with backtest metrics |
Bot Refactoring
| Command | Description |
|---|
/bot:refactor <bot_name> | Start interactive refactoring session |
/bot:add-feature <bot_name> <feature> | Add feature (news filter, indicator, etc.) |
/bot:remove-feature <bot_name> <feature> | Remove feature cleanly |
/bot:migrate-pa <bot_name> | Convert eval bot to PA mode |
/bot:analyze <bot_name> | Analyze code quality and suggest improvements |
Top 5 Entry Signals
| Signal | Profit Factor | Win Rate | Key Parameters |
|---|
| keltner | 10.04 | 87.8% | EMA=20, ATR_MULT=2.75 |
| ema_cross | 6.23 | 82.7% | Fast=3, Slow=8, Sep=0.35 |
| vwap | 5.20 | 85.3% | Window=720, Mult=1.0 |
| supertrend | 4.41 | 82.5% | Period=10, Mult=3.0 |
| alligator | 4.16 | 83.5% | Jaw=13, Teeth=8, Lips=5 |
Metrics from 219-day NQ futures backtest (May 2025 - Jan 2026) with ADX di_rising, threshold 35.
When to Use This Skill
Use this skill when:
- •Creating a new live trading bot for NQ futures
- •Refactoring or modifying existing trading bots
- •Converting eval bots to PA mode (or vice versa)
- •Adding features to bots (news filter, alerts, new indicators)
- •Building custom strategies beyond the 5 pre-built signals
- •Setting up Apex Trader Funding eval or PA accounts
- •Implementing prop firm risk management (trailing DD, dynamic sizing)
- •Testing strategies with CSV backtest before going live
Do NOT use for:
- •Offline backtesting only (use Python/backtest.py instead)
- •Creating platform indicators (use indicator-generator skill for TradingView/NinjaTrader/Tradovate)
- •Multi-account management (run separate bot instances)
- •Non-futures markets (skill optimized for NQ futures)
Generated Bot Structure
Each generated bot includes these files:
Python/bots/<signal>/
├── bot_<signal>.py # Main entry point (asyncio)
├── config.py # Configuration from .env
├── databento_client.py # Market data (Databento API)
├── traderspost_client.py # Order execution (TradersPost webhook)
├── risk_manager.py # Apex account tracking (eval/PA modes)
├── indicators.py # Self-contained indicator calculations
├── news_calendar.py # Economic calendar filtering (optional)
├── alerting.py # Email/SMS alerts (optional)
├── bot_state.db # SQLite persistence (created at runtime)
├── requirements.txt # Python dependencies
├── .env.example # Credential template
├── .gitignore # Exclude .env, logs, *.db
└── README.md # Bot documentation
Bot Architecture
┌─────────────────────────────────────────────────────────────┐
│ DATABENTO API │
│ https://databento.com (real-time & historical 2-min bars) │
│ + CSV files for backtesting │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ PYTHON BOT │
│ • Indicator calculation (EMA, ATR, ADX, signal-specific) │
│ • Signal detection (edge-triggered crossovers) │
│ • Apex account tracking (eval/PA modes, trailing DD) │
│ • Position management (SL/TP/trailing stops) │
│ • Re-entry logic (3 bars wait, ADX > 40) │
│ • News calendar filtering (blackout periods) │
│ • State persistence (SQLite - survive restarts) │
│ • Alerting (email/SMS on critical events) │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ TRADERSPOST WEBHOOK │
│ POST https://webhooks.traderspost.io/trading/webhook/... │
│ {ticker, action, quantity, stopLoss, takeProfit} │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ BROKER (Tradovate / Apex Trader Funding) │
│ Order execution, position management, OCO brackets │
└─────────────────────────────────────────────────────────────┘
Key Features
| Feature | Implementation |
|---|
| Market Data | Databento API (real-time + historical) + CSV files |
| Account Modes | Eval (profit target, trailing DD) or PA (risk %, static DD) |
| Position Sizing | Fixed contracts (eval) or risk-based % (PA mode) |
| Indicator calculations | Self-contained (EMA, ATR, ADX, VWAP, signal-specific) |
| Signal detection | Edge-triggered crossovers (5 pre-built + custom) |
| Position management | Entry price, SL, TP, HWM/LWM, trailing stops |
| Re-entry logic | 3 bars wait, ADX > 40, max 10 per direction |
| News calendar | Economic event blackouts (FOMC, NFP, CPI) |
| Alerting | Email + SMS on daily loss limit, DD breach, connection loss |
| State persistence | SQLite database (survive mid-day restarts) |
| Session filtering | Configurable allowed hours (ET timezone) |
| Volume filter | Volume > EMA(volume, 20) |
| Graceful shutdown | SIGINT/SIGTERM handlers, exit positions on shutdown |
| Logging | File + console with timestamps |
| Testing | CSV backtest mode, unit tests, integration tests |
Quick Start
1. Interactive Mode
User: Create a live trading bot
Assistant: [Runs /bot:new workflow]
- Step 1: Select signal (keltner, ema_cross, vwap, supertrend, alligator)
- Step 2: Configure signal parameters
- Step 3: Set risk parameters (contracts, daily max loss)
- Step 4: Configure exits (SL, TP, trailing)
- Step 5: API credentials guidance
- Step 6: Generate bot files
2. Direct Signal
User: /bot:keltner
Assistant: [Generates Keltner bot with optimal settings]
3. Quick Mode
User: /bot:new keltner --quick
Assistant: [Uses all defaults, generates immediately]
ADX Filter Modes
All 5 modes from backtest.py supported:
| Mode | Logic | Recommended |
|---|
traditional | ADX > threshold | |
di_aligned | + DIs aligned with direction | |
di_rising | + Dominant DI rising | ✅ |
adx_rising | + ADX itself rising | |
combined | All conditions | |
Exit Priority Order
- •Trailing Stop (if active AND hit)
- •Stop Loss (hard protective stop)
- •Take Profit (profit target)
Skill References
Core Documentation
Configuration Topics
Guides
Signal Details
Templates
Workflows
Examples
Related Files
| File | Purpose |
|---|
Python/backtest.py | Reference implementation (indicator calculations, signal logic) |
Python/docs/TRADOVATE_API_GUIDE.md | TradersPost payload format, Tradovate WebSocket |
Python/STRATEGY.md | Strategy specification |