An advanced crypto futures trading platform featuring multi-agent AI debate consensus, real-time backtesting, and automated execution on Binance.
Passive Income Ahh
An advanced AI-powered cryptocurrency futures trading platform that leverages multi-agent debate consensus, comprehensive backtesting, and real-time portfolio management to automate trading strategies on Binance Futures.
Key Features
Core Trading
- Multi-AI Debate System: Multiple AI personas (Bull, Bear, Analyst, Contrarian, Risk Manager) debate and reach consensus on trading decisions
- Advanced Decision Engine: Integrates OpenRouter to access top-tier LLMs (DeepSeek, Claude, GPT-4) with Chain-of-Thought reasoning
- Comprehensive Backtesting: Test strategies against historical Binance data with detailed metrics (Sharpe ratio, max drawdown, win rate, profit factor)
- Real-time Trading: Automated, low-latency execution on Binance Futures with Testnet and Mainnet support
- Bracket Orders: Atomic execution of Entry + Stop Loss + Take Profit orders
- WebSocket Real-time Updates: Sub-second position monitoring via Binance User Data Stream (1.13ms average latency vs 30-60s REST polling)
Risk Management (15+ Layers)
Entry Safety (7 Layers)
- EMA Spread Gate: Requires โฅ0.6% EMA spread for entries - blocks weak/choppy trends
- Momentum Exhaustion Detection: Blocks extended price + opposite MACD histogram entries
- Wick Rejection Pattern: Blocks when 3+ of 5 candles show rejection wicks
- Volume Decline Detection: Blocks when volume < 60% of 5-candle average
- Resistance/Support Buffer: Blocks entries within 0.5% of 40-candle high/low
- RSI Extreme Blocking: Blocks LONG if RSI >75, SHORT if RSI <25
- Counter-Trend Prevention: LONG requires Price > EMA9, SHORT requires Price < EMA9
Multi-Timeframe Confirmation (4 Checks)
- Trend Direction: Higher TF EMA9 vs EMA21 must align
- Price Action: Price must respect higher TF EMA21
- MACD Momentum: Higher TF histogram sign must support trade
- Trend Strength: Higher TF EMA spread must be โฅ0.4%
Open Interest Analysis (v3.52.0+)
- OI + Price Interpretation: Real money flow analysis revealing if trends are backed by new capital
- Top Trader Long/Short Ratio: Crowding detection warns when >70% of traders are on one side
- Falling Knife Protection: Blocks LONG entries during detected Long Liquidation cascades
- Rocket Short Protection: Blocks SHORT entries during detected Short Squeezes
Position Management
- Hard Validation: Enforced 3:1 minimum risk/reward ratio
- Noise Zone Protection: Block closing positions between -1.5% and +1.5% PnL to prevent panic selling
- Trailing Stop Loss: Automatically lock profits at +1% with 0.5% trailing distance
- Smart Loss Cut: Force close losers after extended hold time (30+ minutes with >1% loss)
- Max Hold Duration: Automatically close positions held longer than 4 hours
- Drawdown Protection: Close positions if drawdown from peak exceeds 40%
- Emergency Shutdown: Halt trading if balance drops below configured threshold ($60 default)
- Guaranteed Profit Lock: Automatically protect gains once threshold is reached (v3.48.0+)
- Daily Loss Limits: Stop trading after reaching daily loss threshold (15% default)
Dynamic Features
- Smart Find: AI-recommended volatile trading pairs with auto-refresh and OI-based discovery
- Turbo Mode: High-frequency scalping with dynamic coin discovery
- Copy Trading Mode: Monitor positions without executing trades
- Live Strategy Reload: Apply configuration changes without restarting
- Signal Confirmation: Wait for price stability and AI re-confirmation before executing medium-confidence trades
- Bilingual Support: English and Chinese AI prompts
Modern Dashboard
- Glassmorphism UI: Sleek React + TailwindCSS interface
- Real-time Logs: Live streaming of server logs via SSE
- Equity Curve: Visual portfolio growth tracking
- Strategy Ranking: Compare strategy performance with interactive charts
How It Works
The system operates on an automated loop (default: 5 minutes) combining technical analysis with AI reasoning:
- Market Analysis: Calculate hard mathematical indicators (EMA9/21 trends, RSI levels, MACD, ATR volatility, Bollinger Bands)
- Trend Validation: Check trend strength gate - only proceed if EMA spread > 0.2%
- AI Decision: Send structured prompt with account state, market data, and positions to LLM. The AI outputs a JSON decision with confidence, stop-loss, and take-profit levels
- Risk Validation: Enforce minimum 3:1 reward-to-risk ratio, leverage limits, and position sizing caps
- Noise Zone Check: Block closures in the -1.5% to +1.5% PnL zone unless confidence > 95%
- Execution: Execute validated trades as bracket orders (Entry + SL + TP simultaneously)
- Position Management: Track peak PnL, apply trailing stops, enforce max hold duration
Project Structure
auto-trader-ahh/
โโโ client/ # Frontend Application (React + Vite)
โ โโโ src/
โ โ โโโ components/ # Reusable UI components (Charts, Layouts, etc.)
โ โ โโโ contexts/ # React contexts (Auth, etc.)
โ โ โโโ lib/ # API clients and utilities
โ โ โโโ pages/ # Application views
โ โ โ โโโ Dashboard # Real-time trader status & positions
โ โ โ โโโ Strategies # Strategy configuration & management
โ โ โ โโโ Backtest # Historical backtesting
โ โ โ โโโ Debate # Multi-AI consensus arena
โ โ โ โโโ History # Trade history & PnL
โ โ โ โโโ Equity # Portfolio growth visualization
โ โ โ โโโ Ranking # Strategy performance comparison
โ โ โ โโโ Config # Global settings
โ โ โ โโโ Logs # Real-time server logs
โ โ โโโ types/ # TypeScript interfaces
โ โ โโโ App.tsx # Main entry point with routing
โ โโโ Dockerfile # Frontend container definition
โ โโโ package.json # Frontend dependencies
โ
โโโ server/ # Backend Application (Go)
โ โโโ api/ # HTTP API endpoints (net/http)
โ โโโ backtest/ # Backtesting engine and simulation
โ โโโ config/ # Configuration loading and validation
โ โโโ data/ # SQLite database storage (trading.db)
โ โโโ debate/ # Multi-agent debate and consensus
โ โโโ decision/ # AI decision engine (NOFX-style XML parsing)
โ โ โโโ prompt_builder # System/user prompt construction
โ โ โโโ parser # XML to JSON parsing
โ โ โโโ validator # Risk/reward validation
โ โโโ events/ # Event hub for real-time communication
โ โโโ exchange/ # Binance Futures API integration
โ โโโ logger/ # Log broadcasting system (SSE)
โ โโโ market/ # Technical indicators (EMA, RSI, MACD, ATR, etc.)
โ โโโ mcp/ # Multi-provider AI client (OpenRouter)
โ โโโ store/ # Database models (Strategies, Traders, Trades, etc.)
โ โโโ trader/ # Core trading engine and execution loop
โ โโโ main.go # Application entry point
โ โโโ Dockerfile # Backend container definition
โ โโโ go.mod # Go module definitions
โ
โโโ docker-compose.yml # Container orchestration
โโโ TRADING_ALGO.md # Algorithm documentation
โโโ RECOMMENDED_SETTINGS.md # Configuration guide
โโโ CHANGELOG.md # Version history
โโโ README.md # Project documentation
Tech Stack
Backend
- Language: Go 1.23
- Database: SQLite
- AI Integration: OpenRouter API (DeepSeek, Anthropic Claude, OpenAI GPT-4, Llama, etc.)
- Exchange: Binance Futures API
- Libraries: generic-go-binance, go-sqlite3
- Framework: React 18, Vite
- Language: TypeScript
- Styling: TailwindCSS, Framer Motion
- Components: Shadcn/UI, Lucide Icons
- Visualization: Recharts, D3
Getting Started
Prerequisites
- Go 1.23+
- Node.js 20+
- Docker & Docker Compose (recommended)
- Binance Futures Account (Testnet recommended for development)
- OpenRouter API Key
Docker Quick Start (Recommended)
- Clone the repository:
git clone https://github.com/LynchzDEV/ai-auto-trader-ahh.git
cd ai-auto-trader-ahh
- Configure Environment:
.env file in the server/ directory:
cd server
cp .env.example .env
Edit .env and add your keys:
API_PORT=8080
ACCESSPASSKEY=youroptional_passkey
- Run with Docker Compose:
cd ..
docker compose up -d --build
- Access the App:
Manual Installation
Backend
cd server
go mod download
go run main.go
Frontend
cd client
npm install
npm run dev
Configuration
The system is highly configurable via the Dashboard "Settings" page or server/.env.
Environment Variables
| Variable | Description | Default | |----------|-------------|---------| | OPENROUTERAPIKEY | OpenRouter API key for AI | Required | | OPENROUTER_MODEL | AI model to use | deepseek/deepseek-v3.2 | | BINANCEAPIKEY | Binance Futures API key | Required | | BINANCESECRETKEY | Binance Futures secret | Required | | BINANCE_TESTNET | Use testnet (true/false) | true | | API_PORT | Port for the Go server | 8080 | | ACCESS_PASSKEY | Optional app password | None |
Strategy Configuration
| Setting | Description | Default | |---------|-------------|---------| | Max Positions | Maximum concurrent positions | 2 | | BTC/ETH Leverage | Max leverage for BTC/ETH | 10x | | Altcoin Leverage | Max leverage for altcoins | 20x | | Min Confidence | Minimum AI confidence to trade | 85% | | Min R/R Ratio | Minimum reward-to-risk ratio | 3.0 | | Trading Interval | Minutes between trading cycles | 5 | | Daily Loss Limit | Stop trading after this loss % | 15% | | Noise Zone | PnL range to block closures | -1.5% to +1.5% |
See RECOMMENDED_SETTINGS.md for detailed configuration guides.
API Endpoints
| Method | Endpoint | Description | |--------|----------|-------------| | GET | /api/health | Health check | | GET | /api/traders | List traders | | POST | /api/traders | Create trader | | POST | /api/traders/{id}/start | Start trader | | POST | /api/traders/{id}/stop | Stop trader | | GET | /api/strategies | List strategies | | POST | /api/strategies | Create strategy | | PUT | /api/strategies/{id} | Update strategy | | GET | /api/status | Get trader status | | GET | /api/positions | Get open positions | | GET | /api/decisions | Get recent AI decisions | | GET | /api/trades | Get trade history | | GET | /api/backtest | List backtests | | POST | /api/backtest/start | Start backtest | | GET | /api/debate/sessions | List debate sessions | | POST | /api/debate/sessions | Create debate session | | GET | /api/settings | Get global settings | | PUT | /api/settings | Update global settings | | GET | /api/logs/stream | SSE log stream | | GET | /api/events | SSE event stream |
Disclaimer
This trading software is for educational and experimental purposes only. Cryptocurrency futures trading involves significant financial risk including the possibility of losing more than your initial investment. The authors and contributors are not responsible for any financial losses incurred while using this software. Use at your own risk.
License
Distributed under the MIT License. See LICENSE for more information.