fix pk prefix handle

This commit is contained in:
tangmengqiu
2025-11-04 00:03:56 -05:00
parent 3ca9669cfc
commit 2fec4ca347
2 changed files with 6 additions and 3 deletions

View File

@@ -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 {

View File

@@ -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