Files
nofx/trader/interface.go
nobody 0164ac6cc0 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.
2025-10-29 20:00:30 +08:00

42 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package trader
// Trader 交易器统一接口
// 支持多个交易平台币安、Hyperliquid等
type Trader interface {
// GetBalance 获取账户余额
GetBalance() (map[string]interface{}, error)
// GetPositions 获取所有持仓
GetPositions() ([]map[string]interface{}, error)
// OpenLong 开多仓
OpenLong(symbol string, quantity float64, leverage int) (map[string]interface{}, error)
// OpenShort 开空仓
OpenShort(symbol string, quantity float64, leverage int) (map[string]interface{}, error)
// CloseLong 平多仓quantity=0表示全部平仓
CloseLong(symbol string, quantity float64) (map[string]interface{}, error)
// CloseShort 平空仓quantity=0表示全部平仓
CloseShort(symbol string, quantity float64) (map[string]interface{}, error)
// SetLeverage 设置杠杆
SetLeverage(symbol string, leverage int) error
// GetMarketPrice 获取市场价格
GetMarketPrice(symbol string) (float64, error)
// SetStopLoss 设置止损单
SetStopLoss(symbol string, positionSide string, quantity, stopPrice float64) error
// SetTakeProfit 设置止盈单
SetTakeProfit(symbol string, positionSide string, quantity, takeProfitPrice float64) error
// CancelAllOrders 取消该币种的所有挂单
CancelAllOrders(symbol string) error
// FormatQuantity 格式化数量到正确的精度
FormatQuantity(symbol string, quantity float64) (string, error)
}