Skip to content

Commit 35bf425

Browse files
committed
feat: support binance non global
able to change api endpoint
1 parent 52be7e1 commit 35bf425

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

v2/client.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ type RateLimitInterval string
103103
type AccountType string
104104

105105
// Endpoints
106-
const (
107-
baseAPIMainURL = "https://api.binance.com"
108-
baseAPITestnetURL = "https://testnet.binance.vision"
106+
var (
107+
BaseAPIMainURL = "https://api.binance.com"
108+
BaseAPITestnetURL = "https://testnet.binance.vision"
109109
)
110110

111111
// UseTestnet switch all the API endpoints from production to the testnet
@@ -261,9 +261,9 @@ func newJSON(data []byte) (j *simplejson.Json, err error) {
261261
// getAPIEndpoint return the base endpoint of the Rest API according the UseTestnet flag
262262
func getAPIEndpoint() string {
263263
if UseTestnet {
264-
return baseAPITestnetURL
264+
return BaseAPITestnetURL
265265
}
266-
return baseAPIMainURL
266+
return BaseAPIMainURL
267267
}
268268

269269
// NewClient initialize an API client instance with API key and secret key.

v2/websocket_service.go

+12-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
package binance
22

33
import (
4+
stdjson "encoding/json"
45
"fmt"
56
"strings"
67
"time"
7-
8-
stdjson "encoding/json"
9-
)
10-
11-
// Endpoints
12-
const (
13-
baseWsMainURL = "wss://stream.binance.com:9443/ws"
14-
baseWsTestnetURL = "wss://testnet.binance.vision/ws"
15-
baseCombinedMainURL = "wss://stream.binance.com:9443/stream?streams="
16-
baseCombinedTestnetURL = "wss://testnet.binance.vision/stream?streams="
178
)
189

1910
var (
11+
// Endpoints
12+
BaseWsMainURL = "wss://stream.binance.com:9443/ws"
13+
BaseWsTestnetURL = "wss://testnet.binance.vision/ws"
14+
BaseCombinedMainURL = "wss://stream.binance.com:9443/stream?streams="
15+
BaseCombinedTestnetURL = "wss://testnet.binance.vision/stream?streams="
16+
2017
// WebsocketTimeout is an interval for sending ping/pong messages if WebsocketKeepalive is enabled
2118
WebsocketTimeout = time.Second * 60
2219
// WebsocketKeepalive enables sending ping/pong messages to check the connection stability
@@ -26,17 +23,17 @@ var (
2623
// getWsEndpoint return the base endpoint of the WS according the UseTestnet flag
2724
func getWsEndpoint() string {
2825
if UseTestnet {
29-
return baseWsTestnetURL
26+
return BaseWsTestnetURL
3027
}
31-
return baseWsMainURL
28+
return BaseWsMainURL
3229
}
3330

3431
// getCombinedEndpoint return the base endpoint of the combined stream according the UseTestnet flag
3532
func getCombinedEndpoint() string {
3633
if UseTestnet {
37-
return baseCombinedTestnetURL
34+
return BaseCombinedTestnetURL
3835
}
39-
return baseCombinedMainURL
36+
return BaseCombinedMainURL
4037
}
4138

4239
// WsPartialDepthEvent define websocket partial depth book event
@@ -797,7 +794,7 @@ func WsBookTickerServe(symbol string, handler WsBookTickerHandler, errHandler Er
797794

798795
// WsCombinedBookTickerServe is similar to WsBookTickerServe, but it is for multiple symbols
799796
func WsCombinedBookTickerServe(symbols []string, handler WsBookTickerHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error) {
800-
endpoint := baseCombinedMainURL
797+
endpoint := getCombinedEndpoint()
801798
for _, s := range symbols {
802799
endpoint += fmt.Sprintf("%s@bookTicker", strings.ToLower(s)) + "/"
803800
}

0 commit comments

Comments
 (0)