Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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"
Expand Down Expand Up @@ -368,6 +372,9 @@ func getAPIEndpoint() string {
if UseDemo {
return BaseAPIDemoURL
}
if UseUSDomain {
return BaseAPIMainUSURL
}
return BaseAPIMainURL
}

Expand Down
5 changes: 5 additions & 0 deletions v2/futures/websocket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions v2/options/websocket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions v2/websocket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -58,6 +61,9 @@ func getWsEndpoint() string {
if UseDemo {
return BaseWsDemoURL
}
if UseUSDomain {
return BaseUSWsMainURL
}
return BaseWsMainURL
}

Expand All @@ -69,6 +75,9 @@ func getCombinedEndpoint() string {
if UseDemo {
return BaseCombinedDemoURL
}
if UseUSDomain {
return BaseUSCombinedMainURL
}
return BaseCombinedMainURL
}

Expand Down Expand Up @@ -1189,5 +1198,8 @@ func getWsApiEndpoint() string {
if UseDemo {
return BaseWsApiDemoURL
}
if UseUSDomain {
return BaseUSWsApiMainURL
}
return BaseWsApiMainURL
}