24/7 live trading execution engine for strategies exported from AlphaLab.
Export a backtested strategy from AlphaLab → deploy to Railway → it trades automatically. Get Telegram alerts for every trade and daily summaries.
AlphaLab and AlphaLive are two separate platforms that work together:
| Platform | Purpose | When to Run | Where to Run |
|---|---|---|---|
| AlphaLab | Strategy development & backtesting | As needed (not 24/7) | Locally on your computer |
| AlphaLive | Live trading execution | 24/7 during trading hours | Railway (recommended) or locally |
What it does:
- Develop trading strategies (code signal logic)
- Backtest on 5 years of historical data
- Optimize parameters (walk-forward validation, grid search)
- Export strategies as JSON for AlphaLive
When you use it:
- Creating new strategies
- Testing strategy ideas
- Monthly re-backtesting on new data
- Analyzing why live performance differs from backtest
Run it: Only when developing/testing strategies (NOT 24/7)
What it does:
- Load strategy JSON from AlphaLab
- Connect to Alpaca broker (paper or live account)
- Generate buy/sell signals in real-time
- Execute trades automatically
- Monitor positions for stop loss / take profit
- Send Telegram alerts
When you use it:
- 24/7 during trading hours (9:30 AM - 4:00 PM ET, Mon-Fri)
- Runs continuously even when you're asleep/away
Run it: 24/7 on Railway (recommended) or locally
┌─────────────────────────────────────────────────────────────────┐
│ AlphaLab (Local, As Needed) │
└─────────────────────────────────────────────────────────────────┘
│
│ 1. Develop strategy
│ 2. Backtest on historical data
│ 3. Optimize parameters
│ 4. Export as JSON
↓
┌─────────────────────────────────────────────────────────────────┐
│ AlphaLive (Railway or Local, 24/7) │
└─────────────────────────────────────────────────────────────────┘
│
│ 5. Load strategy JSON
│ 6. Run dry run (1 week)
│ 7. Run paper trading (2-4 weeks)
│ 8. Run live trading (gradual scale up)
↓
┌─────────────────────────────────────────────────────────────────┐
│ Monitor & Analyze Results │
└─────────────────────────────────────────────────────────────────┘
│
│ 9. Compare live vs backtest performance
│ 10. If performance degrades: back to AlphaLab
│ 11. Re-optimize and re-export
└──────────────┐
│ (loop back to step 1)
You need BOTH platforms — AlphaLab develops strategies, AlphaLive executes them.
AlphaLive can run locally on your computer (FREE) or on Railway (~$5-20/month).
Best for:
- ✅ Testing (dry run, paper trading)
- ✅ Saving money (~$5-20/month)
- ✅ Full control over environment
Requirements:
- Your computer must be ON 24/7 during trading hours (9:30 AM - 4:00 PM ET)
- Stable internet connection
- No sleep/hibernate during trading hours
Risks:
- ❌ Power outage = missed trades
- ❌ Computer restart = bot stops until you manually restart it
- ❌ Internet outage = no trading
- ❌ You must be available to restart bot if it crashes
How to run locally:
# Foreground (blocks terminal, Ctrl+C to stop)
python run.py --config configs/your_strategy.json
# Background (keeps running after closing terminal)
nohup python run.py --config configs/your_strategy.json > alphalive.log 2>&1 &
# Check if running
ps aux | grep "run.py"
# Stop background process
pkill -f "run.py"Best for:
- ✅ Live trading with real money
- ✅ 24/7 reliability (professional infrastructure)
- ✅ Auto-restart on crashes
- ✅ Deploy updates from anywhere (git push)
Benefits:
- Bot runs even when your computer is off
- Auto-restart if process crashes
- View logs from anywhere (phone, laptop)
- No need to manage servers
Cost: ~$5-20/month (Hobby plan or pay-as-you-go)
How to deploy: See SETUP.md for complete guide
| Feature | Local | Railway |
|---|---|---|
| Cost | FREE | ~$5-20/month |
| Uptime | Only when your computer is on | 24/7 professional infrastructure |
| Auto-restart on crash | No (manual) | Yes (automatic) |
| Deploy updates | Local only | From anywhere (git push) |
| View logs | Local terminal only | From anywhere (dashboard) |
| Power outage protection | No | Yes |
| Best for | Testing, development | Live trading |
| Phase | Recommended Deployment |
|---|---|
| Phase 1: Dry Run (1 week) | Local (free) |
| Phase 2: Paper Trading (2-4 weeks) | Local or Railway (your choice) |
| Phase 3-4: Live Trading | Railway (reliability is worth $5-20/month) |
Bottom line: Test locally for free, deploy to Railway when going live.
Platform: AlphaLab (separate repository)
Run it:
- Locally on your computer
- As needed (not 24/7)
- When developing new strategies or re-backtesting
Cost: FREE
Platform: AlphaLive (this repository)
Run it:
- Locally:
python run.py --dry-run(dry run mode) - Locally:
python run.py(paper trading mode) - Railway: Deploy with
DRY_RUN=trueorALPACA_PAPER=true
Cost: FREE (local) or ~$5-20/month (Railway)
Platform: AlphaLive (this repository)
Run it:
- Railway (recommended): See SETUP.md
- Or locally:
python run.pywithALPACA_PAPER=false
Requirements:
- Alpaca live account (FREE, but real money at risk)
- Optional: Market data subscription (~$15-30/month for real-time SIP data)
- Railway subscription (~$5-20/month) if using Railway
Total cost for live trading:
- Minimum: $0/month (local + free Alpaca + IEX data)
- Recommended: $5-50/month (Railway $5-20 + optional SIP data $15-30)
- Backtest strategies in AlphaLab until you find ones you like
- Click "Export to AlphaLive" → saves a JSON config with your strategy parameters
- Commit the JSON to
configs/in this repo - Deploy to Railway (or run locally for testing)
- AlphaLive runs 24/7: sleeps when market is closed, trades when open
- Get Telegram alerts for every trade, exit, and daily summary
AlphaLive is a production-grade trading bot with:
- Signal Generation: Replicates AlphaLab strategy logic exactly (5 strategies supported)
- Risk Management: Stop loss, take profit, trailing stop, position sizing, daily limits
- Order Execution: Alpaca Markets API with retry logic, slippage checks, partial fill handling
- Market Data: Real-time bars from Alpaca with caching and staleness detection
- Notifications: Telegram alerts for trades, exits, errors, daily summaries
- Resilience: Auto-restart on Railway, position reconciliation, corporate action detection
┌─────────────────────────────────────────────────────────────┐
│ AlphaLive (Railway) │
├─────────────────────────────────────────────────────────────┤
│ Main Loop (24/7) │
│ ↓ │
│ Market Data Fetcher (Alpaca) → Signal Engine → Risk Mgr │
│ ↓ │
│ Order Manager → Alpaca Broker → Positions │
│ ↓ │
│ Telegram Notifier → Your Phone │
└─────────────────────────────────────────────────────────────┘
Market Closed Behavior:
- Checks if market is open every 30 seconds
- Sleeps efficiently when closed (no wasted API calls)
- Wakes up at 9:30 AM ET and starts trading
Signal Timing:
- 1Day strategies: Check once per day at 9:35 AM ET
- 1Hour strategies: Check every hour at :00 minutes
- 15Min strategies: Check every 15 minutes (:00, :15, :30, :45)
Exit Monitoring:
- Checks stop loss / take profit every 5 minutes during market hours
- Corporate action detection (skips trading on 20% overnight moves)
- End-of-day summary sent at 3:55 PM ET
- Python 3.11+
- Alpaca Markets account (free paper trading account)
- Telegram bot (optional, for notifications)
-
Clone the repo:
git clone https://github.com/yourusername/AlphaLive.git cd AlphaLive -
Install dependencies:
pip install -r requirements.txt
-
Configure environment:
cp .env.example .env # Edit .env with your API keys -
Create a strategy config or use the example:
# configs/example_strategy.json already exists # Or export from AlphaLab to configs/
-
Validate configuration (recommended first step):
python run.py --validate-only
This tests:
- ✅ Strategy JSON is valid
- ✅ Alpaca connection works
- ✅ Market data fetch works
- ✅ Signal generation works
-
Run in dry-run mode (recommended for testing):
python run.py --dry-run
This logs trades without executing them. Perfect for testing signal logic.
-
Run with paper trading:
python run.py
Default is paper trading (
ALPACA_PAPER=true). Safe for testing with fake money.
python run.py [OPTIONS]
Options:
--config PATH Path to strategy JSON (default: STRATEGY_CONFIG env var)
--dry-run Log trades without executing (for testing)
--validate-only Test config and connections, then exit
--replay-mode Test on historical data (FREE - no subscription needed)
--replay-start DATE Start date for replay (YYYY-MM-DD, default: 2015-01-01)
--replay-end DATE End date for replay (YYYY-MM-DD, default: 2019-12-31)Before paying for Alpaca premium, test your strategy on 9+ years of historical data for FREE:
# Test on 2015-2019 (pre-COVID normal markets)
python run.py \
--config configs/your_strategy.json \
--replay-mode \
--replay-start 2015-01-01 \
--replay-end 2019-12-31 \
--dry-runWhat you get:
- ✅ Test on 5-9 years of historical data (100% FREE)
- ✅ See signals, trades, P&L, win rate
- ✅ Verify strategy works before upgrading to premium
- ✅ Smart defaults avoid COVID-19 market anomalies
Recommended testing:
- Pre-COVID (2015-2019): 5 years of normal markets
- Post-COVID (2022-2024): 3 years of recovery
Cost: $0 (historical data is free on Alpaca)
Use the interactive test script:
./test_replay_mode.shSee SETUP.md for detailed deployment guide.
Quick steps:
- Create Railway account: railway.app
- Create new project → Deploy from GitHub repo
- Set environment variables:
ALPACA_API_KEYALPACA_SECRET_KEYTELEGRAM_BOT_TOKENTELEGRAM_CHAT_IDSTRATEGY_CONFIG=configs/your_strategy.jsonALPACA_PAPER=true(start with paper trading!)
- Deploy → Railway auto-builds and runs 24/7
Cost: ~$5/month on Railway Starter plan (500 hours included).
| Variable | Description | Example |
|---|---|---|
ALPACA_API_KEY |
Alpaca API key (get from alpaca.markets) | PK... |
ALPACA_SECRET_KEY |
Alpaca secret key | xxx... |
STRATEGY_CONFIG |
Path to strategy JSON file | configs/ma_crossover.json |
| Variable | Default | Description |
|---|---|---|
ALPACA_PAPER |
true |
Use paper trading (recommended for testing) |
TELEGRAM_BOT_TOKEN |
None |
Telegram bot token (for notifications) |
TELEGRAM_CHAT_ID |
None |
Your Telegram chat ID |
LOG_LEVEL |
INFO |
Logging level (DEBUG, INFO, WARNING, ERROR) |
DRY_RUN |
false |
Log trades without executing |
TRADING_PAUSED |
false |
Pause trading (kill switch) |
Alpaca Markets:
- Sign up at alpaca.markets
- Go to Your API Keys in dashboard
- Generate new paper trading keys
- Copy API Key and Secret Key
Telegram Bot:
- Open Telegram and search for @BotFather
- Send
/newbotand follow prompts - Copy bot token (looks like
123456:ABC-DEF...) - Start a chat with your bot
- Get your chat ID by visiting:
https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates - Send a message to your bot, then refresh the URL above — your chat ID is in the response
AlphaLive has multiple layers of protection:
- Stop Loss: Automatically close positions at configured loss threshold
- Take Profit: Lock in gains at target price
- Trailing Stop: Follow price up, exit on pullback (optional)
- Position Sizing: Max % of account per position (prevents overexposure)
- Daily Loss Limit: Halt all trading if daily loss exceeds threshold
- Max Positions: Limit simultaneous open positions
- Consecutive Loss Breaker: Pause trading after 3 stop-outs in a row
- Kill Switch: Set
TRADING_PAUSED=truein Railway to halt immediately - Corporate Action Detection: Skip trading on 20% overnight moves (stock splits, etc.)
- Position Drift Auto-Halt: Halts if Alpaca positions don't match bot's internal tracking
- Data Staleness Checks: Won't trade on old data (market may be closed)
- Startup Warmup Validation: Ensures indicators are ready before first trade
- Rate Limiting: Exponential backoff prevents API bans
- Graceful Degradation: Telegram failures don't crash trading
- SIGTERM Handling: Clean shutdown on Railway restarts
When you switch to live trading (ALPACA_PAPER=false), you'll see:
⚠️ ⚠️ ⚠️ WARNING ⚠️ ⚠️ ⚠️
⚠️ LIVE TRADING MODE — REAL MONEY AT RISK ⚠️
⚠️ ⚠️ ⚠️ WARNING ⚠️ ⚠️ ⚠️
Recommendation: Run on paper for at least 1 week before switching to live.
AlphaLive supports 5 strategies exported from AlphaLab:
Description: Buy when fast SMA crosses above slow SMA, sell when it crosses below.
Parameters:
fast_period: Fast SMA period (default: 10)slow_period: Slow SMA period (default: 20)
Best For: Trending markets, daily timeframes
Description: Buy when RSI is oversold, sell when overbought.
Parameters:
period: RSI period (default: 14)oversold: Oversold threshold (default: 30)overbought: Overbought threshold (default: 70)
Best For: Range-bound markets, intraday
Description: Buy on new high with volume surge.
Parameters:
lookback: Lookback period for rolling high (default: 20)surge_pct: Volume surge multiplier (default: 1.5)atr_period: ATR period for trailing stop (default: 14)
Best For: Volatile stocks, breakout plays
Description: Buy on consecutive closes above upper band with volume confirmation.
Parameters:
period: Bollinger Bands period (default: 20)std_dev: Standard deviation multiplier (default: 2.0)confirmation_bars: Consecutive bars above/below band (default: 2)
Best For: Trend continuation, daily/hourly
Description: Buy when price is far below VWAP and RSI is oversold, sell when far above and RSI is overbought.
Parameters:
deviation_threshold: Deviation in standard deviations (default: 2.0)rsi_period: RSI period (default: 14)oversold: RSI oversold threshold (default: 30)overbought: RSI overbought threshold (default: 70)
Best For: Intraday mean reversion
AlphaLive can run multiple strategies simultaneously by loading all JSONs from a directory:
- Export multiple strategies from AlphaLab
- Place all JSONs in
configs/directory - Set environment variable:
STRATEGY_CONFIG_DIR=configs/
- Deploy → AlphaLive runs all strategies in parallel
Risk Scope:
- Per-Strategy Limits:
max_open_positions,stop_loss_pct,take_profit_pct - Global Limits:
max_daily_loss_pct(halts ALL strategies),portfolio_max_positions(total positions across all)
Example: 3 strategies with max_open_positions=[5,3,2] → total potential = 10 positions, but portfolio_max_positions=8 caps it at 8.
When configured, you'll receive:
- Bot Started: "🚀 AlphaLive Started" with strategy details
- Trade Executed: "🟢 BUY 66 AAPL @ $150.00"
- Position Closed: "💰 Position Closed — P&L: $495.00 (+5.00%)"
- Stop Loss Hit: "🛑 Stop loss triggered — AAPL -$300.00"
- Daily Summary: "📈 Daily Summary — 5 trades, $450 profit, 60% win rate"
- Error Alerts: "
⚠️ Alpaca API timeout" - Circuit Breaker: "
⚠️ 3 consecutive losses — trading paused"
Graceful Degradation: If Telegram fails, trading continues (alerts are lost but trades still execute).
AlphaLive logs to STDOUT in structured format:
2026-03-09 09:35:00 [INFO] alphalive.main: Market is open — running signal check
2026-03-09 09:35:01 [INFO] alphalive.data.market_data: Fetched 200 bars for AAPL (latest: 2026-03-09 09:34:00 EST)
2026-03-09 09:35:02 [INFO] alphalive.strategy.signal_engine: BUY signal: MA crossover (fast SMA crossed above slow SMA)
2026-03-09 09:35:03 [INFO] alphalive.execution.order_manager: MARKET BUY 66 AAPL @ market | Order ID: abc123-def456
2026-03-09 09:35:05 [INFO] alphalive.broker.alpaca_broker: Order filled: 66 shares @ $150.25
Railway: Logs are captured automatically and viewable in dashboard.
Local: Logs print to terminal.
- Check that
ALPACA_API_KEYandALPACA_SECRET_KEYare correct - Verify you're using paper trading keys (not live keys) if
ALPACA_PAPER=true
- Market may be closed (bot sleeps automatically)
- Check Alpaca status: status.alpaca.markets
- Check
TELEGRAM_BOT_TOKENandTELEGRAM_CHAT_IDare correct - Verify bot is not blocked
- Bot will auto-retry every 10 minutes
- Bot has hit
max_daily_loss_pctfor the day - Trading resumes next trading day automatically
- Alpaca positions don't match bot's internal tracking
- Manually reconcile positions in Alpaca dashboard
- Set
TRADING_PAUSED=falseto resume
AlphaLive is part of the Alpha trading suite:
- AlphaLab: Backtest strategies, export to AlphaLive
- AlphaLive: Execute strategies 24/7 on Railway (this repo)
For questions, issues, or contributions, open an issue on GitHub.
What is it: SEC regulation requiring $25,000 minimum account balance for accounts that execute 4+ day trades within 5 business days.
How it affects AlphaLive:
- Paper Trading: No PDT restrictions (unlimited day trades)
- Live Trading with <$25k:
- Limited to 3 day trades per 5 business days
- AlphaLive does NOT track day trade count
- You must manually monitor via Alpaca dashboard
- Exceeding limit results in 90-day trading restriction by your broker
- Live Trading with ≥$25k: No restrictions
Recommended Strategies:
- Use 1Day timeframe strategies (no day trades)
- Monitor
daytrade_countin Alpaca dashboard daily - Set
max_trades_per_dayconservatively in strategy JSON - Consider swing trading strategies (hold overnight)
References:
MIT License — see LICENSE file for details.
Trading involves substantial risk of loss. Past performance does not guarantee future results.
- AlphaLive is provided "as is" without warranty
- You are responsible for your own trading decisions
- Always test on paper trading before using live funds
- Monitor your bot regularly
- Use appropriate position sizing and risk limits
Use at your own risk.