Skip to content

Commit

Permalink
Add test URL for binance
Browse files Browse the repository at this point in the history
  • Loading branch information
kislikjeka committed Jun 14, 2021
1 parent 30d598f commit df22532
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions v2/borker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/sha256"
"encoding/json"
"fmt"
"github.com/Zamzam-Technology/go-binance/v2"
"github.com/Zamzam-Technology/go-binance/v2/common"
"io"
"io/ioutil"
Expand All @@ -21,7 +22,10 @@ const (
signatureKey = "signature"
recvWindowKey = "recvWindow"

baseURL = "https://api.binance.com"
// Endpoints
baseAPIMainURL = "https://api.binance.com"
baseAPITestnetURL = "https://testnet.binance.vision"

defaultTimeout = 5 * time.Second
)

Expand All @@ -46,7 +50,7 @@ func NewClient(apiKey, secretKey string, writer io.Writer) *Client {
},
apiKey: apiKey,
secretKey: secretKey,
BaseURL: baseURL,
BaseURL: getAPIEndpoint(),
Logger: log.New(writer, "Binance-Broker", log.LstdFlags),
}
}
Expand Down Expand Up @@ -441,3 +445,11 @@ func currentTimestamp() int64 {
func FormatTimestamp(t time.Time) int64 {
return t.UnixNano() / int64(time.Millisecond)
}

// getAPIEndpoint return the base endpoint of the Rest API according the UseTestnet flag
func getAPIEndpoint() string {
if binance.UseTestnet {
return baseAPITestnetURL
}
return baseAPIMainURL
}

0 comments on commit df22532

Please sign in to comment.