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,21 +57,21 @@ 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
_, err = client.NewSetServerTimeService().Do(context.Background()) if len(key) > 0 && len(secret) > 0 {
if err != nil { _, err = client.NewSetServerTimeService().Do(context.Background())
panic(err) if err != nil {
} panic(err)
}
_, err = futuresClient.NewSetServerTimeService().Do(context.Background()) _, err = futuresClient.NewSetServerTimeService().Do(context.Background())
if err != nil { if err != nil {
panic(err) panic(err)
}
} }
return &Exchange{ return &Exchange{