feat: Add Hyperliquid exchange support with unified trader interface

Major changes:
- Add full Hyperliquid trading support (long/short, leverage, SL/TP)
- Create unified Trader interface for multi-exchange support
- Implement automatic precision handling for orders and prices
- Fix balance calculation and unrealized P&L display
- Add comprehensive configuration guide in README

New features:
- Support for both Binance and Hyperliquid exchanges
- Automatic order size precision based on szDecimals
- Price formatting with 5 significant figures
- Non-custodial trading with Ethereum private key
- Seamless exchange switching via configuration

Technical details:
- Add trader/interface.go for unified trader interface
- Add trader/hyperliquid_trader.go for Hyperliquid implementation
- Update manager and auto_trader to support multiple exchanges
- Add go-hyperliquid SDK dependency
- Fix precision errors (float_to_wire, invalid price)

Fixes:
- Correct calculation of wallet balance and unrealized P&L
- Proper handling of AccountValue vs TotalRawUsd
- Frontend display issues for total equity and P&L

Documentation:
- Add Hyperliquid setup guide in README
- Update config.json.example with both exchanges
- Add troubleshooting section for common errors

Tested with live trading on Hyperliquid mainnet.
No breaking changes - backward compatible with existing configs.
This commit is contained in:
nobody
2025-10-29 20:00:30 +08:00
parent fefb2b7424
commit 896fc2ed3a
9 changed files with 1073 additions and 70 deletions

View File

@@ -1,4 +1,4 @@
# 🤖 NOFX - AI-Driven Binance Futures Auto Trading Competition System
# 🤖 NOFX - AI-Driven Crypto Futures Auto Trading Competition System
[![Go Version](https://img.shields.io/badge/Go-1.21+-00ADD8?style=flat&logo=go)](https://golang.org/)
[![React](https://img.shields.io/badge/React-18+-61DAFB?style=flat&logo=react)](https://reactjs.org/)
@@ -9,7 +9,7 @@
---
An automated Binance futures trading system powered by **DeepSeek/Qwen AI**, supporting **multi-AI model live trading competition**, featuring comprehensive market analysis, AI decision-making, **self-learning mechanism**, and professional Web monitoring interface.
An automated crypto futures trading system powered by **DeepSeek/Qwen AI**, supporting **Binance and Hyperliquid exchanges**, **multi-AI model live trading competition**, featuring comprehensive market analysis, AI decision-making, **self-learning mechanism**, and professional Web monitoring interface.
> ⚠️ **Risk Warning**: This system is experimental. AI auto-trading carries significant risks. Strongly recommended for learning/research purposes or testing with small amounts only!
@@ -21,6 +21,35 @@ Join our Telegram developer community to discuss, share ideas, and get support:
---
## 🆕 What's New (Latest Update)
### 🚀 Hyperliquid Exchange Support Added!
NOFX now supports **Hyperliquid** - a high-performance decentralized perpetual futures exchange!
**Key Features:**
- ✅ Full trading support (long/short, leverage, stop-loss/take-profit)
- ✅ Automatic precision handling (order size & price)
- ✅ Unified trader interface (seamless exchange switching)
- ✅ Support for both mainnet and testnet
- ✅ No API keys needed - just your Ethereum private key
**Why Hyperliquid?**
- 🔥 Lower fees than centralized exchanges
- 🔒 Non-custodial - you control your funds
- ⚡ Fast execution with on-chain settlement
- 🌍 No KYC required
**Quick Start:**
1. Get your MetaMask private key (remove `0x` prefix)
2. Set `"exchange": "hyperliquid"` in config.json
3. Add `"hyperliquid_private_key": "your_key"`
4. Start trading!
See [Configuration Guide](#-alternative-using-hyperliquid-exchange) for details.
---
## ✨ Core Features
### 🏆 Multi-AI Competition Mode
@@ -363,6 +392,48 @@ cp config.json.example config.json
---
#### 🔷 Alternative: Using Hyperliquid Exchange
**NOFX also supports Hyperliquid** - a decentralized perpetual futures exchange. To use Hyperliquid instead of Binance:
**Step 1**: Get your Ethereum private key (for Hyperliquid authentication)
1. Open **MetaMask** (or any Ethereum wallet)
2. Export your private key
3. **Remove the `0x` prefix** from the key
4. Fund your wallet on [Hyperliquid](https://hyperliquid.xyz)
**Step 2**: Configure `config.json` for Hyperliquid
```json
{
"traders": [
{
"id": "hyperliquid_trader",
"name": "My Hyperliquid Trader",
"ai_model": "deepseek",
"exchange": "hyperliquid",
"hyperliquid_private_key": "your_private_key_without_0x",
"hyperliquid_testnet": false,
"deepseek_key": "sk-xxxxxxxxxxxxx",
"initial_balance": 1000.0,
"scan_interval_minutes": 3
}
],
"use_default_coins": true,
"api_server_port": 8080
}
```
**Key Differences from Binance Config:**
- Replace `binance_api_key` + `binance_secret_key` with `hyperliquid_private_key`
- Add `"exchange": "hyperliquid"` field
- Set `hyperliquid_testnet: false` for mainnet (or `true` for testnet)
** Security Warning**: Never share your private key! Use a dedicated wallet for trading, not your main wallet.
---
#### ⚔️ Expert Mode: Multi-Trader Competition
For running multiple AI traders competing against each other: