diff --git a/README.md b/README.md index 1c5e5edd..a0fb6125 100644 --- a/README.md +++ b/README.md @@ -396,6 +396,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 377e603f..04d79662 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" BaseAPIDemoURL = "https://demo-api.binance.com" ) @@ -143,6 +144,9 @@ var UseTestnet = false // UseDemo switch all the API endpoints from production to the demo var UseDemo = false +// UseUSDomain switch all the API endpoints from production to the binance.us +var UseUSDomain = false + // Global enums const ( SideTypeBuy SideType = "BUY" @@ -368,6 +372,9 @@ func getAPIEndpoint() string { if UseDemo { return BaseAPIDemoURL } + if UseUSDomain { + return BaseAPIMainUSURL + } return BaseAPIMainURL } diff --git a/v2/futures/websocket_service.go b/v2/futures/websocket_service.go index a0160073..c03be9da 100644 --- a/v2/futures/websocket_service.go +++ b/v2/futures/websocket_service.go @@ -61,6 +61,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 87b42249..22bc57e6 100644 --- a/v2/options/websocket_service.go +++ b/v2/options/websocket_service.go @@ -33,6 +33,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 15ca0728..e3821ef5 100644 --- a/v2/websocket_service.go +++ b/v2/websocket_service.go @@ -15,12 +15,15 @@ import ( var ( // Endpoints BaseWsMainURL = "wss://stream.binance.com:9443/ws" + BaseUSWsMainURL = "wss://stream.binance.us:9443/ws" BaseWsTestnetURL = "wss://stream.testnet.binance.vision/ws" BaseWsDemoURL = "wss://demo-stream.binance.com/ws" BaseCombinedMainURL = "wss://stream.binance.com:9443/stream?streams=" + BaseUSCombinedMainURL = "wss://stream.binance.us:9443/stream?streams=" BaseCombinedTestnetURL = "wss://stream.testnet.binance.vision/stream?streams=" BaseCombinedDemoURL = "wss://demo-stream.binance.com/stream?streams=" BaseWsApiMainURL = "wss://ws-api.binance.com:443/ws-api/v3" + BaseUSWsApiMainURL = "wss://ws-api.binance.us:443/ws-api/v3" BaseWsApiTestnetURL = "wss://ws-api.testnet.binance.vision/ws-api/v3" BaseWsApiDemoURL = "wss://demo-ws-api.binance.com/ws-api/v3" BaseWsAnnouncementURL = "wss://api.binance.com/sapi/wss" @@ -58,6 +61,9 @@ func getWsEndpoint() string { if UseDemo { return BaseWsDemoURL } + if UseUSDomain { + return BaseUSWsMainURL + } return BaseWsMainURL } @@ -69,6 +75,9 @@ func getCombinedEndpoint() string { if UseDemo { return BaseCombinedDemoURL } + if UseUSDomain { + return BaseUSCombinedMainURL + } return BaseCombinedMainURL } @@ -1189,5 +1198,8 @@ func getWsApiEndpoint() string { if UseDemo { return BaseWsApiDemoURL } + if UseUSDomain { + return BaseUSWsApiMainURL + } return BaseWsApiMainURL }