diff --git a/README.md b/README.md index f07e68370..8adbb43d7 100644 --- a/README.md +++ b/README.md @@ -354,6 +354,17 @@ binance.UseTestnet = true client := binance.NewClient(apiKey, secretKey) ``` +Use the `binance.UseUSDomain` flag to switch domain to binance.us, including both client creation and the wesockets methods. +```go +import ( + "github.com/adshao/go-binance/v2" +) + +binance.UseUSDomain = true +client := binance.NewClient(apiKey, secretKey) +``` + + #### Futures (usd(s)-m futures) Use the `futures.UseTestnet` flag before calling the client creation and the websockets methods diff --git a/v2/client.go b/v2/client.go index 90faa0cd7..3e0e72489 100644 --- a/v2/client.go +++ b/v2/client.go @@ -125,6 +125,7 @@ type FuturesAlgoOrderStatusType string // Endpoints var ( BaseAPIMainURL = "https://api.binance.com" + BaseAPIMainUSURL = "https://api.binance.us" BaseAPITestnetURL = "https://testnet.binance.vision" ) @@ -134,6 +135,9 @@ type SelfTradePreventionMode string // UseTestnet switch all the API endpoints from production to the testnet var UseTestnet = false +// UseUSDomain switch all the API endpoints from production to the binance.us +var UseUSDomain = false + // Global enums const ( SideTypeBuy SideType = "BUY" @@ -345,6 +349,9 @@ func getAPIEndpoint() string { if UseTestnet { return BaseAPITestnetURL } + if UseUSDomain { + return BaseAPIMainUSURL + } return BaseAPIMainURL } diff --git a/v2/futures/websocket_service.go b/v2/futures/websocket_service.go index b208060e2..1ca4386c8 100644 --- a/v2/futures/websocket_service.go +++ b/v2/futures/websocket_service.go @@ -34,6 +34,11 @@ var ( ProxyUrl = "" ) +// UseUSDomain switch all the WS streams from production to the binance.us +// currently future websocket streams are not supported on US domain, so this is set to constantly false +const UseUSDomain = false + + func getWsProxyUrl() *string { if ProxyUrl == "" { return nil diff --git a/v2/options/websocket_service.go b/v2/options/websocket_service.go index 2c80cdcdb..8aff74a37 100644 --- a/v2/options/websocket_service.go +++ b/v2/options/websocket_service.go @@ -27,6 +27,10 @@ var ( ProxyUrl = "" ) +// UseUSDomain switch all the WS streams from production to the binance.us +// currently option websocket streams are not supported on US domain, so this is set to constantly false +const UseUSDomain = false + // getWsEndpoint return the base endpoint of the WS according the UseTestnet flag func getWsEndpoint() string { if UseTestnet { diff --git a/v2/websocket_service.go b/v2/websocket_service.go index 5b64ff4fc..6bb1a83f4 100644 --- a/v2/websocket_service.go +++ b/v2/websocket_service.go @@ -12,10 +12,13 @@ import ( var ( // Endpoints BaseWsMainURL = "wss://stream.binance.com:9443/ws" + BaseUSWsMainURL = "wss://stream.binance.us:9443/ws" BaseWsTestnetURL = "wss://testnet.binance.vision/ws" BaseCombinedMainURL = "wss://stream.binance.com:9443/stream?streams=" + BaseUSCombinedMainURL = "wss://stream.binance.us:9443/stream?streams=" BaseCombinedTestnetURL = "wss://testnet.binance.vision/stream?streams=" BaseWsApiMainURL = "wss://ws-api.binance.com:443/ws-api/v3" + BaseUSWsApiMainURL = "wss://ws-api.binance.us:443/ws-api/v3" BaseWsApiTestnetURL = "wss://testnet.binance.vision/ws-api/v3" // WebsocketTimeout is an interval for sending ping/pong messages if WebsocketKeepalive is enabled @@ -45,6 +48,9 @@ func getWsEndpoint() string { if UseTestnet { return BaseWsTestnetURL } + if UseUSDomain { + return BaseUSWsMainURL + } return BaseWsMainURL } @@ -53,6 +59,9 @@ func getCombinedEndpoint() string { if UseTestnet { return BaseCombinedTestnetURL } + if UseUSDomain { + return BaseUSCombinedMainURL + } return BaseCombinedMainURL } @@ -876,5 +885,8 @@ func getWsApiEndpoint() string { if UseTestnet { return BaseWsApiTestnetURL } + if UseUSDomain { + return BaseUSWsApiMainURL + } return BaseWsApiMainURL }