From 2fec4ca347db34e238ad7f8a2b3e80a55225943c Mon Sep 17 00:00:00 2001 From: tangmengqiu <1124090103@qq.com> Date: Tue, 4 Nov 2025 00:03:56 -0500 Subject: [PATCH] fix pk prefix handle --- trader/hyperliquid_trader.go | 4 ++++ web/src/components/AITradersPage.tsx | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/trader/hyperliquid_trader.go b/trader/hyperliquid_trader.go index 0c7684d3..5ae48a16 100644 --- a/trader/hyperliquid_trader.go +++ b/trader/hyperliquid_trader.go @@ -7,6 +7,7 @@ import ( "fmt" "log" "strconv" + "strings" "github.com/ethereum/go-ethereum/crypto" "github.com/sonirico/go-hyperliquid" @@ -23,6 +24,9 @@ type HyperliquidTrader struct { // NewHyperliquidTrader 创建Hyperliquid交易器 func NewHyperliquidTrader(privateKeyHex string, walletAddr string, testnet bool) (*HyperliquidTrader, error) { + // 去掉私钥的 0x 前缀(如果有,不区分大小写) + privateKeyHex = strings.TrimPrefix(strings.ToLower(privateKeyHex), "0x") + // 解析私钥 privateKey, err := crypto.HexToECDSA(privateKeyHex) if err != nil { diff --git a/web/src/components/AITradersPage.tsx b/web/src/components/AITradersPage.tsx index c1a2fc5a..b2563ef3 100644 --- a/web/src/components/AITradersPage.tsx +++ b/web/src/components/AITradersPage.tsx @@ -123,10 +123,9 @@ export function AITradersPage({ onTraderSelect }: AITradersPageProps) { e.asterPrivateKey && e.asterPrivateKey.trim() !== ''; } - // Hyperliquid 只需要私钥(作为apiKey)和钱包地址 + // Hyperliquid 只需要私钥(作为apiKey),钱包地址会自动从私钥生成 if (e.id === 'hyperliquid') { - return e.apiKey && e.apiKey.trim() !== '' && - e.hyperliquidWalletAddr && e.hyperliquidWalletAddr.trim() !== ''; + return e.apiKey && e.apiKey.trim() !== ''; } // Binance 等其他交易所需要 apiKey 和 secretKey