mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
binance: refactor set server time go routine
This commit is contained in:
parent
abf967ac93
commit
cf5e81c848
|
@ -108,40 +108,38 @@ func New(key, secret string) *Exchange {
|
|||
if len(key) > 0 && len(secret) > 0 {
|
||||
client2.Auth(key, secret)
|
||||
|
||||
timeSetter.Do(func() {
|
||||
_, err = client.NewSetServerTimeService().Do(context.Background())
|
||||
setServerTime := func(ctx context.Context) {
|
||||
_, err = client.NewSetServerTimeService().Do(ctx)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("can not set server time")
|
||||
}
|
||||
|
||||
_, err = futuresClient.NewSetServerTimeService().Do(context.Background())
|
||||
_, err = futuresClient.NewSetServerTimeService().Do(ctx)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("can not set server time")
|
||||
}
|
||||
|
||||
if err = client2.SetTimeOffsetFromServer(context.Background()); err != nil {
|
||||
if err = client2.SetTimeOffsetFromServer(ctx); err != nil {
|
||||
log.WithError(err).Error("can not set server time")
|
||||
}
|
||||
})
|
||||
go func() {
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
go timeSetter.Do(func() {
|
||||
setServerTime(ctx)
|
||||
|
||||
ticker := time.NewTicker(time.Hour)
|
||||
defer ticker.Stop()
|
||||
for _ = range ticker.C {
|
||||
_, err = client.NewSetServerTimeService().Do(context.Background())
|
||||
if err != nil {
|
||||
log.WithError(err).Error("can not set server time")
|
||||
}
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
|
||||
_, err = futuresClient.NewSetServerTimeService().Do(context.Background())
|
||||
if err != nil {
|
||||
log.WithError(err).Error("can not set server time")
|
||||
}
|
||||
|
||||
if err = client2.SetTimeOffsetFromServer(context.Background()); err != nil {
|
||||
log.WithError(err).Error("can not set server time")
|
||||
case <-ticker.C:
|
||||
setServerTime(ctx)
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
return &Exchange{
|
||||
|
|
Loading…
Reference in New Issue
Block a user