mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
Merge pull request #1144 from c9s/fix/nonce-updater
FIX: maxapi: fix nonce updater
This commit is contained in:
commit
ed74655aef
|
@ -2,6 +2,7 @@ package bbgo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -25,6 +26,8 @@ import (
|
||||||
|
|
||||||
var KLinePreloadLimit int64 = 1000
|
var KLinePreloadLimit int64 = 1000
|
||||||
|
|
||||||
|
var ErrEmptyMarketInfo = errors.New("market info should not be empty, 0 markets loaded")
|
||||||
|
|
||||||
// ExchangeSession presents the exchange connection Session
|
// ExchangeSession presents the exchange connection Session
|
||||||
// It also maintains and collects the data returned from the stream.
|
// It also maintains and collects the data returned from the stream.
|
||||||
type ExchangeSession struct {
|
type ExchangeSession struct {
|
||||||
|
@ -177,6 +180,7 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
|
||||||
var log = log.WithField("session", session.Name)
|
var log = log.WithField("session", session.Name)
|
||||||
|
|
||||||
// load markets first
|
// load markets first
|
||||||
|
log.Infof("querying market info from %s...", session.Name)
|
||||||
|
|
||||||
var disableMarketsCache = false
|
var disableMarketsCache = false
|
||||||
var markets types.MarketMap
|
var markets types.MarketMap
|
||||||
|
@ -191,7 +195,7 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(markets) == 0 {
|
if len(markets) == 0 {
|
||||||
return fmt.Errorf("market config should not be empty")
|
return ErrEmptyMarketInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
session.markets = markets
|
session.markets = markets
|
||||||
|
@ -224,6 +228,8 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
|
||||||
|
|
||||||
// query and initialize the balances
|
// query and initialize the balances
|
||||||
if !session.PublicOnly {
|
if !session.PublicOnly {
|
||||||
|
log.Infof("querying account balances...")
|
||||||
|
|
||||||
account, err := session.Exchange.QueryAccount(ctx)
|
account, err := session.Exchange.QueryAccount(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -233,7 +239,7 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
|
||||||
session.Account = account
|
session.Account = account
|
||||||
session.accountMutex.Unlock()
|
session.accountMutex.Unlock()
|
||||||
|
|
||||||
log.Infof("%s account", session.Name)
|
log.Infof("account %s balances:", session.Name)
|
||||||
account.Balances().Print()
|
account.Balances().Print()
|
||||||
|
|
||||||
// forward trade updates and order updates to the order executor
|
// forward trade updates and order updates to the order executor
|
||||||
|
|
|
@ -165,6 +165,7 @@ func (c *RestClient) queryAndUpdateServerTimestamp(ctx context.Context) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if serverTs == 0 {
|
if serverTs == 0 {
|
||||||
return errors.New("unexpected zero server timestamp")
|
return errors.New("unexpected zero server timestamp")
|
||||||
}
|
}
|
||||||
|
@ -191,6 +192,8 @@ func (c *RestClient) queryAndUpdateServerTimestamp(ctx context.Context) {
|
||||||
|
|
||||||
if err := backoff.RetryGeneral(ctx, op); err != nil {
|
if err := backoff.RetryGeneral(ctx, op); err != nil {
|
||||||
logger.WithError(err).Error("unable to sync timestamp with max")
|
logger.WithError(err).Error("unable to sync timestamp with max")
|
||||||
|
} else {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user