mirror of
https://github.com/laoxong/nofx.git
synced 2026-06-04 09:58:22 +08:00
fix: use http.DefaultClient for OKX trader
- Use http.DefaultClient instead of custom client, consistent with Binance/Bybit SDKs - Remove unnecessary noProxyFunc and net/url import - All exchanges now use the same HTTP client behavior
This commit is contained in:
@@ -199,8 +199,9 @@ func (tm *TraderManager) GetCompetitionData() (map[string]interface{}, error) {
|
||||
|
||||
// 获取所有交易员列表
|
||||
allTraders := make([]*trader.AutoTrader, 0, len(tm.traders))
|
||||
for _, t := range tm.traders {
|
||||
for id, t := range tm.traders {
|
||||
allTraders = append(allTraders, t)
|
||||
logger.Infof("📋 竞赛数据包含交易员: %s (%s)", t.GetName(), id)
|
||||
}
|
||||
tm.mu.RUnlock()
|
||||
|
||||
|
||||
+3
-17
@@ -11,7 +11,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
neturl "net/url"
|
||||
"nofx/logger"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -96,28 +95,15 @@ func genOkxClOrdID() string {
|
||||
return orderID
|
||||
}
|
||||
|
||||
// noProxyFunc 返回一个始终返回 nil 的代理函数,用于禁用代理
|
||||
func noProxyFunc(req *http.Request) (*neturl.URL, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// NewOKXTrader 创建OKX交易器
|
||||
func NewOKXTrader(apiKey, secretKey, passphrase string) *OKXTrader {
|
||||
// 创建完全禁用代理的 HTTP 客户端
|
||||
// 这对于 Docker 容器环境很重要,因为容器可能继承宿主机的代理环境变量
|
||||
transport := &http.Transport{
|
||||
Proxy: noProxyFunc,
|
||||
}
|
||||
httpClient := &http.Client{
|
||||
Timeout: 30 * time.Second,
|
||||
Transport: transport,
|
||||
}
|
||||
|
||||
// 使用 http.DefaultClient,与 Binance/Bybit SDK 保持一致
|
||||
// DefaultClient 使用 DefaultTransport,会读取环境变量代理设置
|
||||
trader := &OKXTrader{
|
||||
apiKey: apiKey,
|
||||
secretKey: secretKey,
|
||||
passphrase: passphrase,
|
||||
httpClient: httpClient,
|
||||
httpClient: http.DefaultClient,
|
||||
cacheDuration: 15 * time.Second,
|
||||
instrumentsCache: make(map[string]*OKXInstrument),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user