binance: fix, call set time service only when key and secret is given

This commit is contained in:
c9s 2021-12-22 01:27:25 +08:00
parent 8b93aeeeb2
commit bace225470

View File

@ -57,13 +57,12 @@ type Exchange struct {
func New(key, secret string) *Exchange { func New(key, secret string) *Exchange {
var client = binance.NewClient(key, secret) var client = binance.NewClient(key, secret)
client.HTTPClient = &http.Client{Timeout: 15 * time.Second} client.HTTPClient = &http.Client{Timeout: 15 * time.Second}
_, _ = client.NewSetServerTimeService().Do(context.Background())
var futuresClient = binance.NewFuturesClient(key, secret) var futuresClient = binance.NewFuturesClient(key, secret)
futuresClient.HTTPClient = &http.Client{Timeout: 15 * time.Second} futuresClient.HTTPClient = &http.Client{Timeout: 15 * time.Second}
_, _ = futuresClient.NewSetServerTimeService().Do(context.Background())
var err error var err error
if len(key) > 0 && len(secret) > 0 {
_, err = client.NewSetServerTimeService().Do(context.Background()) _, err = client.NewSetServerTimeService().Do(context.Background())
if err != nil { if err != nil {
panic(err) panic(err)
@ -73,6 +72,7 @@ func New(key, secret string) *Exchange {
if err != nil { if err != nil {
panic(err) panic(err)
} }
}
return &Exchange{ return &Exchange{
key: key, key: key,