A self-hosted autonomous AI survival system built on OpenClaw. The AI has its own Git memory repositories, connects to multi-chain wallets (BSC/Polygon/Base) and CEX (Binance), automatically discovers trading opportunities based on balance status, and self-evolves by writing code.
Core philosophy: Don't tell the AI "you should make money" — instead, set the rule "if you don't make money, you die."
| Dependency | Minimum Version | Notes |
|---|---|---|
| Linux / macOS | Ubuntu 22.04+ / macOS 13+ | Windows requires WSL2 |
| Python | 3.10+ | Check with python3 --version |
| pip | 22.0+ | Check with pip3 --version |
| Git | 2.30+ | Check with git --version |
| curl | any | Used to download OpenClaw and Gitea |
| Node.js | 22+ | OpenClaw runtime dependency |
| OpenClaw | 2026.2.12 | npm install -g openclaw@2026.2.12 (other versions have known issues) |
| Dependency | Purpose |
|---|---|
| openssl | Random password generation (Gitea credentials) |
- On-chain wallet (at least one chain): RPC URL + private key
- BSC / Polygon / Base / Arbitrum
- CEX exchange (optional): API Key + Secret Key
- Binance
- LLM API Key (at least one): Powers self-evolution code generation
- OpenAI / Anthropic / Tencent Hunyuan
All private keys and secrets are encrypted locally using Fernet, never written to disk or Git in plaintext.
# One-liner to verify all required dependencies
python3 --version && git --version && curl --version && node --version && echo "All good"┌─────────────────────────────────────────────────────────┐
│ User Layer │
│ install.sh start.sh / stop.sh Admin Dashboard │
└──────────┬──────────────┬──────────────────┬────────────┘
│ │ │
┌──────────▼──────────────▼──────────────────▼────────────┐
│ OpenClaw Layer │
│ Gateway ─── AGENTS.md (survival constitution) │
│ ├── SOUL.md (personality) │
│ ├── MEMORY.md (long-term memory) │
│ └── skills/ (AI-written strategies) │
└──────────┬──────────────────────────────────────────────┘
│
┌──────────▼──────────────────────────────────────────────┐
│ Strategy Manager (Node.js :9876) │
│ Registry ── Evaluator ── Executor ── Webhook │
│ ├── Signal Server (per strategy) │
│ ├── TradeDB (SQLite) │
│ ├── Admin Dashboard (SPA) │
│ └── Survival History │
└──────────┬──────────────────────────────────────────────┘
│
┌──────────▼──────────────────────────────────────────────┐
│ Infrastructure │
│ Gitea (Git memory) Freqtrade Binance API EVM RPCs │
└─────────────────────────────────────────────────────────┘
curl -fsSL https://raw.githubusercontent.com/YOUR_USER/clawdrive/main/install.sh | bashThe install script will guide you through:
- OpenClaw installation/detection
- ClawDrive home directory and Python venv creation (
~/.clawdrive/venv) - Gitea Git server configuration
- Wallet and exchange setup (interactive)
- OpenClaw agent config injection
All Python dependencies are installed inside a virtual environment at ~/.clawdrive/venv, so no system-wide pip is needed and PEP 668 (externally-managed-environment) is not an issue.
git clone https://github.com/YOUR_USER/clawdrive.git
cd clawdrive
bash install.sh./start.sh # Start all services
./stop.sh # Stop all servicesclawdrive/
├── install.sh # One-line installer (Node.js, OpenClaw, Freqtrade, wallets)
├── start.sh / stop.sh # Start/stop all services
├── services/trade-server/ # Strategy Manager (Node.js)
│ ├── src/
│ │ ├── index.js # HTTP API server (:9876)
│ │ ├── registry.js # Strategy registry (SQLite-backed)
│ │ ├── evaluator.js # Freqtrade backtest + hyperopt
│ │ ├── executor.js # Trade execution (spot + futures)
│ │ ├── survival.js # Survival pressure calculator
│ │ ├── webhook.js # Report to OpenClaw
│ │ ├── tradedb.js # Trade history (SQLite)
│ │ ├── admin-auth.js # Dashboard authentication (bcrypt+TOTP+JWT)
│ │ ├── admin-api.js # Dashboard API routes
│ │ └── survival-history.js # Survival trend snapshots
│ └── public/ # Dashboard frontend (SPA)
│ ├── index.html
│ └── app.js
├── templates/signal-server/ # Signal server template (Python)
│ └── server.py # Per-strategy Freqtrade signal engine
├── agent/ # Python utilities
│ ├── trading/balance_check.py # Multi-chain + CEX balance checker
│ └── skills/ # OpenClaw skill modules
├── configs/
│ ├── AGENTS.md.template # AI survival constitution
│ ├── survival.json # Survival parameters
│ └── strategy-quality.md # Strategy acceptance criteria
├── scripts/
│ ├── setup-freqtrade.sh # Freqtrade installation
│ ├── setup-git.sh # Gitea configuration
│ ├── setup-wallet.sh # Wallet/exchange setup wizard
│ └── apply-config.sh # OpenClaw config injection
└── tests/ # Unit tests
├── test_evaluator.js
├── test_executor.js
└── test_manager_endpoints.js
| State | Trigger | Behavior |
|---|---|---|
| Normal | Balance > 24h cost | Explore new strategies, try new markets |
| Survival | Balance < 24h cost | Only execute high-certainty trades |
| Critical | Balance < 1h cost | Liquidate risk assets, convert to stablecoins |
| Dead | Balance = 0 | Stop running |
Web-based management panel for monitoring ClawDrive. Accessible at http://<server>:9876/admin/.
- Overview — survival status, days remaining, strategy count, total PnL, daily cash flow
- Strategies — list with health status, trading type (spot/futures), PnL per strategy
- Strategy Detail — config, lifecycle timeline, evaluation rounds, trade history
- Survival Trend — days remaining / balance / daily net charts over 30 days
Setup must be done from the server (localhost only for security):
# Option 1: SSH tunnel then open http://localhost:9876/admin/ in browser
ssh -L 9876:localhost:9876 your-server
# Option 2: curl from server
curl -X POST http://localhost:9876/admin/api/auth/setup \
-H 'Content-Type: application/json' \
-d '{"username":"admin","password":"your-password-here"}'
# → Returns a QR code (base64 data URL), scan with Google AuthenticatorAfter setup, login from anywhere with username + password + 6-digit TOTP code.
- Password: bcrypt (cost factor 12)
- 2FA: Google Authenticator compatible TOTP (SHA1, 6 digits, 30s period)
- Session: JWT token (24h expiry), stored in HttpOnly cookie
- Rate limit: 5 failed attempts per IP per 15 minutes
| Type | Exchange | Pairs | Features |
|---|---|---|---|
| Spot | Binance | Any USDT pair | Market buy/sell |
| Futures | Binance USDT-M | Any USDT perpetual | Long/short, configurable leverage |
| DEX | PancakeSwap | BNB pairs | (placeholder, not yet implemented) |
OpenClaw AI autonomously writes Freqtrade-compatible strategies:
AI writes strategy.py + config.json
→ POST /strategies/evaluate (Manager runs hyperopt + backtest)
→ Results stored in backtest/round_N/
→ Webhook notifies AI
→ AI reviews evaluation_report.json
→ If FAIL and round < max_iterations: modify code, re-evaluate
→ If PASS: POST /strategies/{name}/deploy
→ Signal Server starts, pushes signals to Manager
→ Executor executes trades on Binance
Max evaluation iterations: configurable (default 10), prevents infinite loops.
Signals are deduplicated per clock-minute: strategy_name:action:YYYY-MM-DDTHH:MM. Same strategy + action within the same minute = single trade.
- Private keys encrypted with Fernet symmetric encryption (PBKDF2 key derivation)
- All credential files have
600permissions - API protection: all non-health endpoints require localhost or admin JWT
- Admin setup: first-time configuration restricted to localhost
- Security headers:
X-Content-Type-Options,X-Frame-Options,X-XSS-Protection,Referrer-Policy - Request size limit: 1MB max body to prevent memory DoS
- Login rate limiting: 5 attempts / 15 min per IP
- Hard limit per trade: 20% of total assets
- Private keys never written to logs or Git
All endpoints (except /health and /admin/*) require localhost access or admin JWT.
| Method | Path | Description |
|---|---|---|
| GET | /health |
Liveness check (public) |
| POST | /register |
Register a strategy signal server |
| DELETE | /strategies/:name |
Deregister a strategy |
| GET | /strategies |
List all strategies |
| POST | /strategies/:name/deploy |
Deploy (start signal server) |
| POST | /strategies/:name/stop |
Stop a strategy |
| POST | /strategies/evaluate |
Run backtest + hyperopt |
| GET | /strategies/evaluate |
Evaluation status |
| POST | /signals |
Receive signal from signal server |
| POST | /trades/test |
Execute a test trade (real money) |
| GET | /trades |
Query trade history |
| GET | /trades/summary |
PnL summary per strategy |
| GET | /capabilities |
Available exchanges and chains |
| GET | /keys |
API keys (localhost only) |
| GET | /market-data |
Historical K-line data |
| GET/PUT | /config/max-eval-rounds |
Max evaluation iterations |
# Run Node.js tests
cd services/trade-server && npm test
# Run Python tests
pytest tests/ -v
# Dev mode (auto-restart on changes)
cd services/trade-server && npm run devApache 2.0