From 3451d7bfac87c5d38903cf6dfad4b15404a73947 Mon Sep 17 00:00:00 2001 From: Dongyan Qian Date: Thu, 13 Nov 2025 20:29:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(api):=20market/combined=5Fstreams:=20Get=20?= =?UTF-8?q?Proxy=20form=20Environment=20(#879)=20*=20fix(api):=20market/co?= =?UTF-8?q?mbined=5Fstreams:=20Get=20Proxy=20form=20Environment=20issues:?= =?UTF-8?q?=20=E2=9D=8C=20=E6=89=B9=E9=87=8F=E8=AE=A2=E9=98=85=E6=B5=81?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5:=20=E7=BB=84=E5=90=88=E6=B5=81WebSocket?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E5=A4=B1=E8=B4=A5:=20dial=20tcp=20xxxxxx:443?= =?UTF-8?q?:=20i/o=20timeout=20Make=20environment=20variables=20effective?= =?UTF-8?q?=20for=20dialer.Dial("wss://fstream.binance.com/stream",=20nil)?= =?UTF-8?q?:=20export=20HTTPS=5FPROXY=3Dhttp://ip:port=20export=20HTTP=5FP?= =?UTF-8?q?ROXY=3Dhttp://ip:port=20Signed-off-by:=20MarsDoge=20=20*=20docs(WebSocket):=20add=20proxy=20usage=20guidanc?= =?UTF-8?q?e=20for=20combined=20streams=20(#475)=20Signed-off-by:=20MarsDo?= =?UTF-8?q?ge=20=20---------=20Signed-off-by:=20MarsDog?= =?UTF-8?q?e=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 18 ++++++++++++++++++ docs/i18n/zh-CN/README.md | 18 ++++++++++++++++++ market/combined_streams.go | 2 ++ 3 files changed, 38 insertions(+) diff --git a/README.md b/README.md index ecb20de7..4be236d0 100644 --- a/README.md +++ b/README.md @@ -1285,6 +1285,24 @@ sudo apt-get install libta-lib0-dev - If API fails, system uses default mainstream coins (BTC, ETH, etc.) - ~~Check API URL and auth parameter in config.json~~ *Check configuration in web interface* +### 6. WebSocket can't connect when using an HTTP/HTTPS proxy + +**Solution**: +- Export standard proxy environment variables *before* starting the backend: + ```bash + export HTTPS_PROXY=http://: + export HTTP_PROXY=http://: + + # If your proxy requires credentials + export HTTPS_PROXY=http://user:pass@: + export HTTP_PROXY=http://user:pass@: + + # Start NOFX normally + ./start.sh + ``` +- **Docker Compose**: put the variables in `.env` or the service's `environment` block. +- NOFX relies on Go's `http.ProxyFromEnvironment`, so every outbound request—including the Binance combined streams WebSocket—follows these proxy settings automatically when the variables are present. + --- ## 📈 Performance Optimization Tips diff --git a/docs/i18n/zh-CN/README.md b/docs/i18n/zh-CN/README.md index cff89345..e992cb03 100644 --- a/docs/i18n/zh-CN/README.md +++ b/docs/i18n/zh-CN/README.md @@ -1302,6 +1302,24 @@ sudo apt-get install libta-lib0-dev - 如果API失败,系统会使用默认主流币种(BTC、ETH等) - ~~检查config.json中的API URL和auth参数~~ *检查Web界面中的配置* +### 6. 代理环境下 WebSocket 无法连接 + +**解决**: +- 启动后端前导出标准代理环境变量: + ```bash + export HTTPS_PROXY=http://<代理主机>:<端口> + export HTTP_PROXY=http://<代理主机>:<端口> + + # 如果代理需要账号密码 + export HTTPS_PROXY=http://用户名:密码@<代理主机>:<端口> + export HTTP_PROXY=http://用户名:密码@<代理主机>:<端口> + + # 正常启动 NOFX + ./start.sh + ``` +- **Docker Compose**:将变量写到 `.env` 或 `docker-compose.yml` 的 `environment` 中。 +- NOFX 使用 Go 的 `http.ProxyFromEnvironment`,只要环境变量设置正确,包括 Binance 合并流在内的所有出站请求都会自动走代理。 + --- ## 📈 性能优化建议 diff --git a/market/combined_streams.go b/market/combined_streams.go index 801d423e..2f5b0146 100644 --- a/market/combined_streams.go +++ b/market/combined_streams.go @@ -7,6 +7,7 @@ import ( "strings" "sync" "time" + "net/http" "github.com/gorilla/websocket" ) @@ -32,6 +33,7 @@ func NewCombinedStreamsClient(batchSize int) *CombinedStreamsClient { func (c *CombinedStreamsClient) Connect() error { dialer := websocket.Dialer{ HandshakeTimeout: 10 * time.Second, + Proxy : http.ProxyFromEnvironment, } // 组合流使用不同的端点