mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
bbgo: call retry.QueryAccountUntilSuccessful in the startup time
This commit is contained in:
parent
7c59e3ddc4
commit
c360c6045c
|
@ -15,6 +15,7 @@ import (
|
|||
|
||||
"github.com/c9s/bbgo/pkg/cache"
|
||||
"github.com/c9s/bbgo/pkg/core"
|
||||
"github.com/c9s/bbgo/pkg/exchange/retry"
|
||||
"github.com/c9s/bbgo/pkg/util/templateutil"
|
||||
|
||||
exchange2 "github.com/c9s/bbgo/pkg/exchange"
|
||||
|
@ -267,12 +268,13 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
|
|||
session.accountMutex.Unlock()
|
||||
} else {
|
||||
logger.Infof("querying account balances...")
|
||||
account, err := session.Exchange.QueryAccount(ctx)
|
||||
account, err := retry.QueryAccountUntilSuccessful(ctx, session.Exchange)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
session.setAccount(account)
|
||||
session.metricsBalancesUpdater(account.Balances())
|
||||
logger.Infof("account %s balances:\n%s", session.Name, account.Balances().String())
|
||||
}
|
||||
|
||||
|
@ -296,7 +298,6 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
|
|||
|
||||
// if metrics mode is enabled, we bind the callbacks to update metrics
|
||||
if viper.GetBool("metrics") {
|
||||
session.metricsBalancesUpdater(account.Balances())
|
||||
session.bindUserDataStreamMetrics(session.UserDataStream)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,9 @@ type advancedOrderCancelService interface {
|
|||
CancelOrdersByGroupID(ctx context.Context, groupID uint32) ([]types.Order, error)
|
||||
}
|
||||
|
||||
func QueryOrderUntilFilled(ctx context.Context, queryOrderService types.ExchangeOrderQueryService, symbol string, orderId uint64) (o *types.Order, err error) {
|
||||
func QueryOrderUntilFilled(
|
||||
ctx context.Context, queryOrderService types.ExchangeOrderQueryService, symbol string, orderId uint64,
|
||||
) (o *types.Order, err error) {
|
||||
var op = func() (err2 error) {
|
||||
o, err2 = queryOrderService.QueryOrder(ctx, types.OrderQuery{
|
||||
Symbol: symbol,
|
||||
|
@ -56,7 +58,9 @@ func GeneralLiteBackoff(ctx context.Context, op backoff.Operation) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
func QueryOpenOrdersUntilSuccessful(ctx context.Context, ex types.Exchange, symbol string) (openOrders []types.Order, err error) {
|
||||
func QueryOpenOrdersUntilSuccessful(
|
||||
ctx context.Context, ex types.Exchange, symbol string,
|
||||
) (openOrders []types.Order, err error) {
|
||||
var op = func() (err2 error) {
|
||||
openOrders, err2 = ex.QueryOpenOrders(ctx, symbol)
|
||||
return err2
|
||||
|
@ -66,7 +70,9 @@ func QueryOpenOrdersUntilSuccessful(ctx context.Context, ex types.Exchange, symb
|
|||
return openOrders, err
|
||||
}
|
||||
|
||||
func QueryOpenOrdersUntilSuccessfulLite(ctx context.Context, ex types.Exchange, symbol string) (openOrders []types.Order, err error) {
|
||||
func QueryOpenOrdersUntilSuccessfulLite(
|
||||
ctx context.Context, ex types.Exchange, symbol string,
|
||||
) (openOrders []types.Order, err error) {
|
||||
var op = func() (err2 error) {
|
||||
openOrders, err2 = ex.QueryOpenOrders(ctx, symbol)
|
||||
return err2
|
||||
|
@ -76,7 +82,21 @@ func QueryOpenOrdersUntilSuccessfulLite(ctx context.Context, ex types.Exchange,
|
|||
return openOrders, err
|
||||
}
|
||||
|
||||
func QueryOrderUntilSuccessful(ctx context.Context, query types.ExchangeOrderQueryService, opts types.OrderQuery) (order *types.Order, err error) {
|
||||
func QueryAccountUntilSuccessful(
|
||||
ctx context.Context, ex types.ExchangeAccountService,
|
||||
) (account *types.Account, err error) {
|
||||
var op = func() (err2 error) {
|
||||
account, err2 = ex.QueryAccount(ctx)
|
||||
return err2
|
||||
}
|
||||
|
||||
err = GeneralBackoff(ctx, op)
|
||||
return account, err
|
||||
}
|
||||
|
||||
func QueryOrderUntilSuccessful(
|
||||
ctx context.Context, query types.ExchangeOrderQueryService, opts types.OrderQuery,
|
||||
) (order *types.Order, err error) {
|
||||
var op = func() (err2 error) {
|
||||
order, err2 = query.QueryOrder(ctx, opts)
|
||||
return err2
|
||||
|
|
Loading…
Reference in New Issue
Block a user