Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support US #652

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 @@ -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
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"
)

Expand All @@ -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"
Expand Down Expand Up @@ -345,6 +349,9 @@ func getAPIEndpoint() string {
if UseTestnet {
return BaseAPITestnetURL
}
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 @@ -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
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 @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions v2/websocket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,6 +48,9 @@ func getWsEndpoint() string {
if UseTestnet {
return BaseWsTestnetURL
}
if UseUSDomain {
return BaseUSWsMainURL
}
return BaseWsMainURL
}

Expand All @@ -53,6 +59,9 @@ func getCombinedEndpoint() string {
if UseTestnet {
return BaseCombinedTestnetURL
}
if UseUSDomain {
return BaseUSCombinedMainURL
}
return BaseCombinedMainURL
}

Expand Down Expand Up @@ -876,5 +885,8 @@ func getWsApiEndpoint() string {
if UseTestnet {
return BaseWsApiTestnetURL
}
if UseUSDomain {
return BaseUSWsApiMainURL
}
return BaseWsApiMainURL
}