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:
shinchan-zhai
2026-03-23 10:56:54 +08:00
parent 982ee668c9
commit 3c698e3fc5
4 changed files with 11 additions and 8 deletions

View File

@@ -8,7 +8,6 @@ import (
"net/http"
"nofx/logger"
"strings"
"time"
)
// refreshMetaIfNeeded refreshes meta information when invalid (triggered when Asset ID is 0)
@@ -67,7 +66,7 @@ func (t *HyperliquidTrader) fetchXyzMeta() error {
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{Timeout: 30 * time.Second}
client := t.httpClient
resp, err := client.Do(req)
if err != nil {
return fmt.Errorf("failed to execute request: %w", err)