mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-14 16:26:57 +08:00
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:
@@ -12,10 +12,22 @@ type TraderConfig struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
AIModel string `json:"ai_model"` // "qwen" or "deepseek"
|
||||
BinanceAPIKey string `json:"binance_api_key"`
|
||||
BinanceSecretKey string `json:"binance_secret_key"`
|
||||
|
||||
// 交易平台选择(二选一)
|
||||
Exchange string `json:"exchange"` // "binance" or "hyperliquid"
|
||||
|
||||
// 币安配置
|
||||
BinanceAPIKey string `json:"binance_api_key,omitempty"`
|
||||
BinanceSecretKey string `json:"binance_secret_key,omitempty"`
|
||||
|
||||
// Hyperliquid配置
|
||||
HyperliquidPrivateKey string `json:"hyperliquid_private_key,omitempty"`
|
||||
HyperliquidTestnet bool `json:"hyperliquid_testnet,omitempty"`
|
||||
|
||||
// AI配置
|
||||
QwenKey string `json:"qwen_key,omitempty"`
|
||||
DeepSeekKey string `json:"deepseek_key,omitempty"`
|
||||
|
||||
InitialBalance float64 `json:"initial_balance"`
|
||||
ScanIntervalMinutes int `json:"scan_interval_minutes"`
|
||||
}
|
||||
@@ -79,9 +91,26 @@ func (c *Config) Validate() error {
|
||||
if trader.AIModel != "qwen" && trader.AIModel != "deepseek" {
|
||||
return fmt.Errorf("trader[%d]: ai_model必须是 'qwen' 或 'deepseek'", i)
|
||||
}
|
||||
if trader.BinanceAPIKey == "" || trader.BinanceSecretKey == "" {
|
||||
return fmt.Errorf("trader[%d]: 币安API密钥不能为空", i)
|
||||
|
||||
// 验证交易平台配置
|
||||
if trader.Exchange == "" {
|
||||
trader.Exchange = "binance" // 默认使用币安
|
||||
}
|
||||
if trader.Exchange != "binance" && trader.Exchange != "hyperliquid" {
|
||||
return fmt.Errorf("trader[%d]: exchange必须是 'binance' 或 'hyperliquid'", i)
|
||||
}
|
||||
|
||||
// 根据平台验证对应的密钥
|
||||
if trader.Exchange == "binance" {
|
||||
if trader.BinanceAPIKey == "" || trader.BinanceSecretKey == "" {
|
||||
return fmt.Errorf("trader[%d]: 使用币安时必须配置binance_api_key和binance_secret_key", i)
|
||||
}
|
||||
} else if trader.Exchange == "hyperliquid" {
|
||||
if trader.HyperliquidPrivateKey == "" {
|
||||
return fmt.Errorf("trader[%d]: 使用Hyperliquid时必须配置hyperliquid_private_key", i)
|
||||
}
|
||||
}
|
||||
|
||||
if trader.AIModel == "qwen" && trader.QwenKey == "" {
|
||||
return fmt.Errorf("trader[%d]: 使用Qwen时必须配置qwen_key", i)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user