AlphaDrift: Building an AI-Powered Autonomous Trading Agent
24/7 autonomous trading with ML-driven strategy selection and built-in risk guardrails.
The Vision
What if a trading bot could:
- Run multiple strategies simultaneously
- Predict which strategy will perform best in current conditions
- Automatically pause when things go wrong
- Put idle capital to work earning yield
That's AlphaDrift.
Architecture Overview
ProviderPool → FeatureStore → Selector → Strategy → Execution Router → RiskGuard → On-chain
↕
Python ML /predict
Data Layer
Multiple providers feed real-time market data:
- Pyth: Oracle price feeds
- Dexscreener: DEX analytics
- Chainbase: On-chain data
- BirdEye: Token analytics
All data flows into a TimescaleDB feature store optimized for time-series operations.
Strategy Layer
Four core strategies, each suited to different market conditions:
| Strategy | Best For | Risk Level |
|---|---|---|
| Momentum | Trending markets | Medium |
| Mean Reversion | Range-bound markets | Medium |
| Funding (Perp Carry) | Stable funding rates | Low |
| Arbitrage | Price discrepancies | Low |
ML Strategy Selector
Here's where it gets interesting. Every 5 minutes, a Python sidecar predicts which strategy will have the best risk-adjusted returns:
# LightGBM model predicts Sharpe ratio for each strategy
features = await feature_store.get_latest()
predictions = model.predict(features)
best_strategy = strategies[np.argmax(predictions)]
The model is trained using Optuna for hyperparameter optimization, targeting Sharpe ratio predictions.
Risk Guard Rails
No trading system is complete without risk management:
- Max Drawdown 5%: Auto-pause if intraday losses exceed 5%
- Gas Budget 1%: Throttle transactions if gas costs spike
- Oracle Gap Veto: Skip trades if oracle price diverges >1% from DEX mid
interface RiskGuard {
maxDrawdown: 0.05; // 5% intraday limit
gasBudget: 0.01; // 1% of equity per day
oracleGapThreshold: 0.01; // 1% max divergence
}
Smart Execution
Orders route through multiple aggregators for best execution:
- 0x Protocol: DEX aggregation
- CoW Protocol: MEV protection
- Paraswap: Multi-DEX routing
Plus MEV rebates through Titan builder.
Idle Yield
When capital isn't actively trading, it earns:
- USDC → sDAI (4-5% APY)
- ETH → stETH (3-4% APY)
Tech Stack
| Layer | Technology |
|---|---|
| Core Agent | TypeScript, @elizaos/core |
| ML Sidecar | Python, FastAPI, LightGBM |
| Hyperparameter Tuning | Optuna |
| Feature Store | TimescaleDB |
| CI/CD | GitHub Actions, Docker Compose |
Development Roadmap
Completed:
- ✅ M0: Scaffold, providers, feature store, strategy implementations
- ✅ M1: Selector, execution router, risk guard, agent wiring
- ✅ M2: Python ML service, Optuna training pipelines, CI
In Progress:
- 🔄 M3: Paper trading validation
- 🔄 M4: Limited live trading
- 📋 M5: Full autonomous operation
Lessons Learned
- Start with risk, not returns: Build the guardrails first
- Separate ML from trading logic: The Python sidecar pattern works well
- Time-series databases matter: TimescaleDB's compression and retention policies are essential
- Paper trade extensively: Simulated performance rarely matches live
Open Source
AlphaDrift is being built in the open. The codebase demonstrates patterns for:
- Multi-strategy trading systems
- ML integration with trading agents
- Risk management frameworks
- Feature store design
Follow the development: github.com/hyperdrift-io/alpha-drift. Building something similar? Talk to us.
Experimental software. Never trade with money you can't afford to lose.
Get weekly intel — courtesy of intel.hyperdrift.io