mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-14 00:07:01 +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))
|
allTraders := make([]*trader.AutoTrader, 0, len(tm.traders))
|
||||||
for _, t := range tm.traders {
|
for id, t := range tm.traders {
|
||||||
allTraders = append(allTraders, t)
|
allTraders = append(allTraders, t)
|
||||||
|
logger.Infof("📋 竞赛数据包含交易员: %s (%s)", t.GetName(), id)
|
||||||
}
|
}
|
||||||
tm.mu.RUnlock()
|
tm.mu.RUnlock()
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
neturl "net/url"
|
|
||||||
"nofx/logger"
|
"nofx/logger"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -96,28 +95,15 @@ func genOkxClOrdID() string {
|
|||||||
return orderID
|
return orderID
|
||||||
}
|
}
|
||||||
|
|
||||||
// noProxyFunc 返回一个始终返回 nil 的代理函数,用于禁用代理
|
|
||||||
func noProxyFunc(req *http.Request) (*neturl.URL, error) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewOKXTrader 创建OKX交易器
|
// NewOKXTrader 创建OKX交易器
|
||||||
func NewOKXTrader(apiKey, secretKey, passphrase string) *OKXTrader {
|
func NewOKXTrader(apiKey, secretKey, passphrase string) *OKXTrader {
|
||||||
// 创建完全禁用代理的 HTTP 客户端
|
// 使用 http.DefaultClient,与 Binance/Bybit SDK 保持一致
|
||||||
// 这对于 Docker 容器环境很重要,因为容器可能继承宿主机的代理环境变量
|
// DefaultClient 使用 DefaultTransport,会读取环境变量代理设置
|
||||||
transport := &http.Transport{
|
|
||||||
Proxy: noProxyFunc,
|
|
||||||
}
|
|
||||||
httpClient := &http.Client{
|
|
||||||
Timeout: 30 * time.Second,
|
|
||||||
Transport: transport,
|
|
||||||
}
|
|
||||||
|
|
||||||
trader := &OKXTrader{
|
trader := &OKXTrader{
|
||||||
apiKey: apiKey,
|
apiKey: apiKey,
|
||||||
secretKey: secretKey,
|
secretKey: secretKey,
|
||||||
passphrase: passphrase,
|
passphrase: passphrase,
|
||||||
httpClient: httpClient,
|
httpClient: http.DefaultClient,
|
||||||
cacheDuration: 15 * time.Second,
|
cacheDuration: 15 * time.Second,
|
||||||
instrumentsCache: make(map[string]*OKXInstrument),
|
instrumentsCache: make(map[string]*OKXInstrument),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user