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:

StrategyBest ForRisk Level
MomentumTrending marketsMedium
Mean ReversionRange-bound marketsMedium
Funding (Perp Carry)Stable funding ratesLow
ArbitragePrice discrepanciesLow

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

LayerTechnology
Core AgentTypeScript, @elizaos/core
ML SidecarPython, FastAPI, LightGBM
Hyperparameter TuningOptuna
Feature StoreTimescaleDB
CI/CDGitHub 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

  1. Start with risk, not returns: Build the guardrails first
  2. Separate ML from trading logic: The Python sidecar pattern works well
  3. Time-series databases matter: TimescaleDB's compression and retention policies are essential
  4. 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