Skip to content

Commit e1d5a64

Browse files
committed
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.
1 parent 81475eb commit e1d5a64

9 files changed

Lines changed: 1072 additions & 69 deletions

File tree

README.md

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 🤖 NOFX - AI-Driven Binance Futures Auto Trading Competition System
1+
# 🤖 NOFX - AI-Driven Crypto Futures Auto Trading Competition System
22

33
[![Go Version](https://img.shields.io/badge/Go-1.21+-00ADD8?style=flat&logo=go)](https://golang.org/)
44
[![React](https://img.shields.io/badge/React-18+-61DAFB?style=flat&logo=react)](https://reactjs.org/)
@@ -9,7 +9,7 @@
99

1010
---
1111

12-
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.
12+
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.
1313

1414
> ⚠️ **Risk Warning**: This system is experimental. AI auto-trading carries significant risks. Strongly recommended for learning/research purposes or testing with small amounts only!
1515
@@ -21,6 +21,35 @@ Join our Telegram developer community to discuss, share ideas, and get support:
2121

2222
---
2323

24+
## 🆕 What's New (Latest Update)
25+
26+
### 🚀 Hyperliquid Exchange Support Added!
27+
28+
NOFX now supports **Hyperliquid** - a high-performance decentralized perpetual futures exchange!
29+
30+
**Key Features:**
31+
- ✅ Full trading support (long/short, leverage, stop-loss/take-profit)
32+
- ✅ Automatic precision handling (order size & price)
33+
- ✅ Unified trader interface (seamless exchange switching)
34+
- ✅ Support for both mainnet and testnet
35+
- ✅ No API keys needed - just your Ethereum private key
36+
37+
**Why Hyperliquid?**
38+
- 🔥 Lower fees than centralized exchanges
39+
- 🔒 Non-custodial - you control your funds
40+
- ⚡ Fast execution with on-chain settlement
41+
- 🌍 No KYC required
42+
43+
**Quick Start:**
44+
1. Get your MetaMask private key (remove `0x` prefix)
45+
2. Set `"exchange": "hyperliquid"` in config.json
46+
3. Add `"hyperliquid_private_key": "your_key"`
47+
4. Start trading!
48+
49+
See [Configuration Guide](#-alternative-using-hyperliquid-exchange) for details.
50+
51+
---
52+
2453
## ✨ Core Features
2554

2655
### 🏆 Multi-AI Competition Mode
@@ -363,6 +392,48 @@ cp config.json.example config.json
363392

364393
---
365394

395+
#### 🔷 Alternative: Using Hyperliquid Exchange
396+
397+
**NOFX also supports Hyperliquid** - a decentralized perpetual futures exchange. To use Hyperliquid instead of Binance:
398+
399+
**Step 1**: Get your Ethereum private key (for Hyperliquid authentication)
400+
401+
1. Open **MetaMask** (or any Ethereum wallet)
402+
2. Export your private key
403+
3. **Remove the `0x` prefix** from the key
404+
4. Fund your wallet on [Hyperliquid](https://hyperliquid.xyz)
405+
406+
**Step 2**: Configure `config.json` for Hyperliquid
407+
408+
```json
409+
{
410+
"traders": [
411+
{
412+
"id": "hyperliquid_trader",
413+
"name": "My Hyperliquid Trader",
414+
"ai_model": "deepseek",
415+
"exchange": "hyperliquid",
416+
"hyperliquid_private_key": "your_private_key_without_0x",
417+
"hyperliquid_testnet": false,
418+
"deepseek_key": "sk-xxxxxxxxxxxxx",
419+
"initial_balance": 1000.0,
420+
"scan_interval_minutes": 3
421+
}
422+
],
423+
"use_default_coins": true,
424+
"api_server_port": 8080
425+
}
426+
```
427+
428+
**Key Differences from Binance Config:**
429+
- Replace `binance_api_key` + `binance_secret_key` with `hyperliquid_private_key`
430+
- Add `"exchange": "hyperliquid"` field
431+
- Set `hyperliquid_testnet: false` for mainnet (or `true` for testnet)
432+
433+
**⚠️ Security Warning**: Never share your private key! Use a dedicated wallet for trading, not your main wallet.
434+
435+
---
436+
366437
#### ⚔️ Expert Mode: Multi-Trader Competition
367438

368439
For running multiple AI traders competing against each other:

config.json.example

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
{
22
"traders": [
33
{
4-
"id": "my_trader",
5-
"name": "My AI Trader",
4+
"id": "hyperliquid_deepseek",
5+
"name": "Hyperliquid DeepSeek Trader",
66
"ai_model": "deepseek",
7-
"binance_api_key": "YOUR_BINANCE_API_KEY",
8-
"binance_secret_key": "YOUR_BINANCE_SECRET_KEY",
9-
"use_qwen": false,
10-
"deepseek_key": "YOUR_DEEPSEEK_API_KEY",
11-
"qwen_key": "",
12-
"initial_balance": 1000.0,
7+
"exchange": "hyperliquid",
8+
"hyperliquid_private_key": "your_ethereum_private_key_without_0x_prefix",
9+
"hyperliquid_testnet": false,
10+
"deepseek_key": "your_deepseek_api_key",
11+
"initial_balance": 1000,
12+
"scan_interval_minutes": 3
13+
},
14+
{
15+
"id": "binance_qwen",
16+
"name": "Binance Qwen Trader",
17+
"ai_model": "qwen",
18+
"exchange": "binance",
19+
"binance_api_key": "your_binance_api_key",
20+
"binance_secret_key": "your_binance_secret_key",
21+
"qwen_key": "your_qwen_api_key",
22+
"initial_balance": 1000,
1323
"scan_interval_minutes": 3
1424
}
1525
],
1626
"use_default_coins": true,
1727
"coin_pool_api_url": "",
1828
"oi_top_api_url": "",
1929
"api_server_port": 8080,
20-
"max_daily_loss": 5.0,
21-
"max_drawdown": 10.0,
22-
"stop_trading_minutes": 30
30+
"max_daily_loss": 10.0,
31+
"max_drawdown": 20.0,
32+
"stop_trading_minutes": 60
2333
}

config/config.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,22 @@ type TraderConfig struct {
1212
ID string `json:"id"`
1313
Name string `json:"name"`
1414
AIModel string `json:"ai_model"` // "qwen" or "deepseek"
15-
BinanceAPIKey string `json:"binance_api_key"`
16-
BinanceSecretKey string `json:"binance_secret_key"`
15+
16+
// 交易平台选择(二选一)
17+
Exchange string `json:"exchange"` // "binance" or "hyperliquid"
18+
19+
// 币安配置
20+
BinanceAPIKey string `json:"binance_api_key,omitempty"`
21+
BinanceSecretKey string `json:"binance_secret_key,omitempty"`
22+
23+
// Hyperliquid配置
24+
HyperliquidPrivateKey string `json:"hyperliquid_private_key,omitempty"`
25+
HyperliquidTestnet bool `json:"hyperliquid_testnet,omitempty"`
26+
27+
// AI配置
1728
QwenKey string `json:"qwen_key,omitempty"`
1829
DeepSeekKey string `json:"deepseek_key,omitempty"`
30+
1931
InitialBalance float64 `json:"initial_balance"`
2032
ScanIntervalMinutes int `json:"scan_interval_minutes"`
2133
}
@@ -79,9 +91,26 @@ func (c *Config) Validate() error {
7991
if trader.AIModel != "qwen" && trader.AIModel != "deepseek" {
8092
return fmt.Errorf("trader[%d]: ai_model必须是 'qwen' 或 'deepseek'", i)
8193
}
82-
if trader.BinanceAPIKey == "" || trader.BinanceSecretKey == "" {
83-
return fmt.Errorf("trader[%d]: 币安API密钥不能为空", i)
94+
95+
// 验证交易平台配置
96+
if trader.Exchange == "" {
97+
trader.Exchange = "binance" // 默认使用币安
98+
}
99+
if trader.Exchange != "binance" && trader.Exchange != "hyperliquid" {
100+
return fmt.Errorf("trader[%d]: exchange必须是 'binance' 或 'hyperliquid'", i)
84101
}
102+
103+
// 根据平台验证对应的密钥
104+
if trader.Exchange == "binance" {
105+
if trader.BinanceAPIKey == "" || trader.BinanceSecretKey == "" {
106+
return fmt.Errorf("trader[%d]: 使用币安时必须配置binance_api_key和binance_secret_key", i)
107+
}
108+
} else if trader.Exchange == "hyperliquid" {
109+
if trader.HyperliquidPrivateKey == "" {
110+
return fmt.Errorf("trader[%d]: 使用Hyperliquid时必须配置hyperliquid_private_key", i)
111+
}
112+
}
113+
85114
if trader.AIModel == "qwen" && trader.QwenKey == "" {
86115
return fmt.Errorf("trader[%d]: 使用Qwen时必须配置qwen_key", i)
87116
}

go.mod

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,77 @@
11
module nofx
22

3-
go 1.24
3+
go 1.25.0
44

5-
require github.com/adshao/go-binance/v2 v2.8.7
5+
require (
6+
github.com/adshao/go-binance/v2 v2.8.7
7+
github.com/ethereum/go-ethereum v1.16.5
8+
github.com/gin-gonic/gin v1.11.0
9+
github.com/sonirico/go-hyperliquid v0.17.0
10+
)
611

712
require (
13+
github.com/armon/go-radix v1.0.0 // indirect
814
github.com/bitly/go-simplejson v0.5.0 // indirect
15+
github.com/bits-and-blooms/bitset v1.24.0 // indirect
916
github.com/bytedance/sonic v1.14.0 // indirect
1017
github.com/bytedance/sonic/loader v0.3.0 // indirect
1118
github.com/cloudwego/base64x v0.1.6 // indirect
19+
github.com/consensys/gnark-crypto v0.19.0 // indirect
20+
github.com/crate-crypto/go-eth-kzg v1.4.0 // indirect
21+
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
22+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
23+
github.com/elastic/go-sysinfo v1.15.4 // indirect
24+
github.com/elastic/go-windows v1.0.2 // indirect
25+
github.com/ethereum/c-kzg-4844/v2 v2.1.5 // indirect
26+
github.com/ethereum/go-verkle v0.2.2 // indirect
1227
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
1328
github.com/gin-contrib/sse v1.1.0 // indirect
14-
github.com/gin-gonic/gin v1.11.0 // indirect
1529
github.com/go-playground/locales v0.14.1 // indirect
1630
github.com/go-playground/universal-translator v0.18.1 // indirect
1731
github.com/go-playground/validator/v10 v10.27.0 // indirect
18-
github.com/goccy/go-json v0.10.2 // indirect
32+
github.com/goccy/go-json v0.10.4 // indirect
1933
github.com/goccy/go-yaml v1.18.0 // indirect
2034
github.com/google/uuid v1.6.0 // indirect
2135
github.com/gorilla/websocket v1.5.3 // indirect
36+
github.com/holiman/uint256 v1.3.2 // indirect
37+
github.com/joho/godotenv v1.5.1 // indirect
38+
github.com/josharian/intern v1.0.0 // indirect
2239
github.com/jpillora/backoff v1.0.0 // indirect
2340
github.com/json-iterator/go v1.1.12 // indirect
2441
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
25-
github.com/kr/text v0.2.0 // indirect
2642
github.com/leodido/go-urn v1.4.0 // indirect
43+
github.com/mailru/easyjson v0.9.1 // indirect
44+
github.com/mattn/go-colorable v0.1.14 // indirect
2745
github.com/mattn/go-isatty v0.0.20 // indirect
2846
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
2947
github.com/modern-go/reflect2 v1.0.2 // indirect
3048
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
49+
github.com/pkg/errors v0.9.1 // indirect
50+
github.com/prometheus/procfs v0.17.0 // indirect
3151
github.com/quic-go/qpack v0.5.1 // indirect
3252
github.com/quic-go/quic-go v0.54.0 // indirect
53+
github.com/rs/zerolog v1.34.0 // indirect
3354
github.com/shopspring/decimal v1.4.0 // indirect
55+
github.com/sonirico/vago v0.9.0 // indirect
56+
github.com/sonirico/vago/lol v0.0.0-20250901170347-2d1d82c510bd // indirect
57+
github.com/supranational/blst v0.3.16 // indirect
3458
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
3559
github.com/ugorji/go/codec v1.3.0 // indirect
60+
github.com/valyala/fastjson v1.6.4 // indirect
61+
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
62+
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
63+
go.elastic.co/apm/module/apmzerolog/v2 v2.7.1 // indirect
64+
go.elastic.co/apm/v2 v2.7.1 // indirect
65+
go.elastic.co/fastjson v1.5.1 // indirect
3666
go.uber.org/mock v0.5.0 // indirect
3767
golang.org/x/arch v0.20.0 // indirect
38-
golang.org/x/crypto v0.40.0 // indirect
39-
golang.org/x/mod v0.25.0 // indirect
40-
golang.org/x/net v0.42.0 // indirect
41-
golang.org/x/sync v0.16.0 // indirect
42-
golang.org/x/sys v0.35.0 // indirect
43-
golang.org/x/text v0.27.0 // indirect
44-
golang.org/x/tools v0.34.0 // indirect
68+
golang.org/x/crypto v0.42.0 // indirect
69+
golang.org/x/mod v0.27.0 // indirect
70+
golang.org/x/net v0.43.0 // indirect
71+
golang.org/x/sync v0.17.0 // indirect
72+
golang.org/x/sys v0.36.0 // indirect
73+
golang.org/x/text v0.29.0 // indirect
74+
golang.org/x/tools v0.36.0 // indirect
4575
google.golang.org/protobuf v1.36.9 // indirect
76+
howett.net/plist v1.0.1 // indirect
4677
)

0 commit comments

Comments
 (0)