mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-14 16:26:57 +08:00
perf: reuse shared HTTP client in Hyperliquid trader
Previously each direct API call (orders, sync, account) created a new http.Client, preventing TCP/TLS connection reuse. Now all calls share a single client on the HyperliquidTrader struct (30s timeout).
This commit is contained in:
@@ -4,10 +4,12 @@ import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"nofx/logger"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/sonirico/go-hyperliquid"
|
||||
@@ -17,6 +19,7 @@ import (
|
||||
type HyperliquidTrader struct {
|
||||
exchange *hyperliquid.Exchange
|
||||
ctx context.Context
|
||||
httpClient *http.Client // Shared HTTP client for direct API calls (connection reuse)
|
||||
walletAddr string
|
||||
meta *hyperliquid.Meta // Cache meta information (including precision)
|
||||
metaMutex sync.RWMutex // Protect concurrent access to meta field
|
||||
@@ -220,6 +223,7 @@ func NewHyperliquidTrader(privateKeyHex string, walletAddr string, testnet bool,
|
||||
return &HyperliquidTrader{
|
||||
exchange: exchange,
|
||||
ctx: ctx,
|
||||
httpClient: &http.Client{Timeout: 30 * time.Second},
|
||||
walletAddr: walletAddr,
|
||||
meta: meta,
|
||||
isCrossMargin: true, // Use cross margin mode by default
|
||||
|
||||
Reference in New Issue
Block a user