AI-powered crypto perpetual futures trading bot for Hyperliquid DEX
β οΈ Disclaimer: This project is for educational and research purposes only. Leveraged trading carries substantial risk of loss. Always test on testnet before using real funds.
Quant Flow is an AI-powered automated trading system for Hyperliquid DEX, built on LangChain/LangGraph. It supports two independent trading strategies:
| Strategy | Entry Point | Description |
|---|---|---|
| Perpetual Agent | main.py |
Multi-agent architecture with one independent decision context per trading pair |
| Grid Flow | grid_main.py |
AI-driven grid market making β LLM judges direction & width, math engine calculates params |
- π€ Multi-Agent Architecture β Independent decision-making per trading pair
- π Multi-LLM Support β OpenAI, NVIDIA, Google, Cloudflare, LiteLLM
- π Grid Flow Strategy β AI-driven dynamic grid market making
- π Kelly Formula Position Sizing β Dynamic optimal position calculation
- π‘οΈ ATR Dynamic Stop-Loss/Take-Profit β Volatility-adaptive risk management
- π Account Protection β Max drawdown limits, position timeout
- π Decision Validation β Multi-timeframe trend resonance, signal quality
- π Backtesting β
single/gridstrategies with checkpoint resume - π API Fallback β LLM and Hyperliquid API fallback mechanisms
| Feature | Paper | Config | Description |
|---|---|---|---|
| FinCoT Reasoning | arXiv:2506.16123 | prompt.set: nof1-improved |
6-step forced reasoning chain, +17% accuracy, -8.9x token cost |
| Bull/Bear Debate | arXiv:2412.20138 | debate.enabled |
Two agents debate bull/bear to eliminate confirmation bias |
| CEX Signals + On-chain | MDPI Mathematics 14(2):346 | enhanced_analysis.enabled |
Binance funding rate, Fear&Greed, MVRV/SOPR signals |
| Regime Adaptive | Springer Digital Finance | regime_adaptive.enabled |
Dynamic params for trending/ranging/volatile market states |
| Market Monitor | β | market_monitor.enabled |
Independent thread triggers decisions on volatility spikes |
All enhancements are controlled by independent config flags and are off by default.
# 1. Initialize (auto-configure UID/GID, create directories)
bash init-deployment.sh
# 2. Configure
cp config.yaml.example config.yaml
cp config.grid.yaml.example config.grid.yaml # optional, for grid mode
vim .env # API keys and private key
vim config.yaml # trading parameters
# 3. Start (main strategy by default)
docker compose up -d
# Run grid strategy only
RUN_MODE=grid docker compose up -d
# Run both strategies simultaneously
RUN_MODE=all docker compose up -d
# View logs
docker compose logs -f# Install uv (if not installed)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install dependencies (Python 3.11+ required)
uv sync
# Configure
cp .env.example .env
cp config.yaml.example config.yaml
# Run main strategy
uv run python main.py
# Run grid strategy
uv run python grid_main.py --config config.grid.yaml --env-file .env# LLM API (configure based on client_type in config.yaml)
NVIDIA_API_KEY=xxx
OPENAI_API_KEY=xxx
OPENAI_API_BASE=xxx
# Hyperliquid
HYPERLIQUID_PRIVATE_KEY=0x... # wallet private key
HYPERLIQUID_TESTNET=true # true=testnet, false=mainnetWallet modes: Single wallet (fill
HYPERLIQUID_PRIVATE_KEYonly) or API wallet proxy (also fillHYPERLIQUID_ACCOUNT_ADDRESS, requires authorization on the main wallet webpage).
llm:
client_type: langchain_nvidia # openai / cloudflare / google / litellm / nvidia
model: deepseek-ai/deepseek-v3.2
temperature: 0.2
trading:
symbols: [BTC, ETH]
max_trade_amount: 100
max_leverage: 10
prompt:
set: nof1-improved # recommended: integrates FinCoT 6-step reasoning
enhanced_analysis:
enabled: true
debate:
enabled: false # +2 LLM calls per decision
regime_adaptive:
enabled: false # requires enhanced_analysis: true
account_protection:
enabled: true
max_drawdown_pct: 0.10
max_daily_loss_pct: 0.05
market_monitor:
enabled: false
alert_threshold_pct: 3.0See config.yaml.example for the full reference.
# Single agent backtest
uv run python backtest.py --symbol BTC --strategy single \
--start-date 2024-01-01 --end-date 2024-12-01
# Grid strategy backtest
uv run python backtest.py --symbol BTC --strategy grid \
--start-date 2024-01-01 --end-date 2024-12-01
# Resume from checkpoint
uv run python backtest.py --resume-from backtest_results/backtest_BTC_xxx/live_report.json
# A/B comparison (test effect of specific features)
uv run python backtest_comparison.py --symbol BTC --compare all
uv run python backtest_comparison.py --symbol BTC --compare fincotSee BACKTEST_README.md for full backtest documentation.
uv run pytest tests/
uv run pytest tests/test_decision_validator.py -v
uv run pytest tests/ --cov=srcquant-flow/
βββ main.py # Main strategy entry
βββ grid_main.py # Grid strategy entry
βββ backtest.py # Backtest runner
βββ backtest_comparison.py # A/B comparison tool
βββ src/
β βββ agent/ # Agent implementations
β βββ trading/ # Trading core (client, orders, risk)
β βββ data/ # Market data, indicators, enricher
β βββ llm/ # LLM client wrappers
β βββ backtest/ # Backtest engine
β βββ notification/ # Notification module
βββ prompts/ # 8 prompt strategy sets
βββ website/ # Docusaurus documentation site
βββ tests/ # Test suite
docker compose up -d # Start
docker compose down # Stop
docker compose logs -f # Logs
docker compose ps # Status
# Update
git pull && docker compose build && docker compose up -d| Error | Solution |
|---|---|
PermissionError: /app/logs/... |
Run bash init-deployment.sh |
open interest is at cap |
Asset hit OI cap, use a different trading pair |
Leverage exceeds maximum allowed |
Lower max_leverage in config |
| API wallet can't trade | Authorize the API wallet on the main wallet webpage |
- π Full Documentation
- π¦ Hyperliquid
- π° Testnet Faucet
- βοΈ LangChain