mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
rename and simplify import
This commit is contained in:
parent
671772a767
commit
d33240ec83
|
@ -5,10 +5,9 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
backoff2 "github.com/cenkalti/backoff/v4"
|
"github.com/cenkalti/backoff/v4"
|
||||||
|
|
||||||
"github.com/c9s/bbgo/pkg/types"
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
"github.com/c9s/bbgo/pkg/util/backoff"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type advancedOrderCancelService interface {
|
type advancedOrderCancelService interface {
|
||||||
|
@ -18,7 +17,7 @@ type advancedOrderCancelService interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
err = backoff.RetryGeneral(ctx, func() (err2 error) {
|
var op = func() (err2 error) {
|
||||||
o, err2 = queryOrderService.QueryOrder(ctx, types.OrderQuery{
|
o, err2 = queryOrderService.QueryOrder(ctx, types.OrderQuery{
|
||||||
Symbol: symbol,
|
Symbol: symbol,
|
||||||
OrderID: strconv.FormatUint(orderId, 10),
|
OrderID: strconv.FormatUint(orderId, 10),
|
||||||
|
@ -33,24 +32,25 @@ func QueryOrderUntilFilled(ctx context.Context, queryOrderService types.Exchange
|
||||||
}
|
}
|
||||||
|
|
||||||
return err2
|
return err2
|
||||||
})
|
}
|
||||||
|
|
||||||
|
err = GeneralBackoff(ctx, op)
|
||||||
return o, err
|
return o, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GeneralBackoff(ctx context.Context, op backoff2.Operation) (err error) {
|
func GeneralBackoff(ctx context.Context, op backoff.Operation) (err error) {
|
||||||
err = backoff2.Retry(op, backoff2.WithContext(
|
err = backoff.Retry(op, backoff.WithContext(
|
||||||
backoff2.WithMaxRetries(
|
backoff.WithMaxRetries(
|
||||||
backoff2.NewExponentialBackOff(),
|
backoff.NewExponentialBackOff(),
|
||||||
101),
|
101),
|
||||||
ctx))
|
ctx))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GeneralBackoffLite(ctx context.Context, op backoff2.Operation) (err error) {
|
func GeneralLiteBackoff(ctx context.Context, op backoff.Operation) (err error) {
|
||||||
err = backoff2.Retry(op, backoff2.WithContext(
|
err = backoff.Retry(op, backoff.WithContext(
|
||||||
backoff2.WithMaxRetries(
|
backoff.WithMaxRetries(
|
||||||
backoff2.NewExponentialBackOff(),
|
backoff.NewExponentialBackOff(),
|
||||||
5),
|
5),
|
||||||
ctx))
|
ctx))
|
||||||
return err
|
return err
|
||||||
|
@ -72,7 +72,7 @@ func QueryOpenOrdersUntilSuccessfulLite(ctx context.Context, ex types.Exchange,
|
||||||
return err2
|
return err2
|
||||||
}
|
}
|
||||||
|
|
||||||
err = GeneralBackoffLite(ctx, op)
|
err = GeneralLiteBackoff(ctx, op)
|
||||||
return openOrders, err
|
return openOrders, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,8 +89,8 @@ func (s *Strategy) recoverActiveOrdersPeriodically(ctx context.Context) {
|
||||||
func syncActiveOrders(ctx context.Context, opts SyncActiveOrdersOpts) error {
|
func syncActiveOrders(ctx context.Context, opts SyncActiveOrdersOpts) error {
|
||||||
opts.logger.Infof("[ActiveOrderRecover] syncActiveOrders")
|
opts.logger.Infof("[ActiveOrderRecover] syncActiveOrders")
|
||||||
|
|
||||||
// do not sync orders which is updated in 3 min, because we may receive from websocket and handle it twice
|
// only sync orders which is updated over 3 min, because we may receive from websocket and handle it twice
|
||||||
doNotSyncAfter := time.Now().Add(-3 * time.Minute)
|
syncBefore := time.Now().Add(-3 * time.Minute)
|
||||||
|
|
||||||
openOrders, err := retry.QueryOpenOrdersUntilSuccessfulLite(ctx, opts.exchange, opts.activeOrderBook.Symbol)
|
openOrders, err := retry.QueryOpenOrdersUntilSuccessfulLite(ctx, opts.exchange, opts.activeOrderBook.Symbol)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -117,7 +117,7 @@ func syncActiveOrders(ctx context.Context, opts SyncActiveOrdersOpts) error {
|
||||||
delete(openOrdersMap, activeOrder.OrderID)
|
delete(openOrdersMap, activeOrder.OrderID)
|
||||||
} else {
|
} else {
|
||||||
opts.logger.Infof("found active order #%d is not in the open orders, updating...", activeOrder.OrderID)
|
opts.logger.Infof("found active order #%d is not in the open orders, updating...", activeOrder.OrderID)
|
||||||
if activeOrder.UpdateTime.After(doNotSyncAfter) {
|
if activeOrder.UpdateTime.After(syncBefore) {
|
||||||
opts.logger.Infof("active order #%d is updated in 3 min, skip updating...", activeOrder.OrderID)
|
opts.logger.Infof("active order #%d is updated in 3 min, skip updating...", activeOrder.OrderID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ func syncActiveOrders(ctx context.Context, opts SyncActiveOrdersOpts) error {
|
||||||
for _, openOrder := range openOrdersMap {
|
for _, openOrder := range openOrdersMap {
|
||||||
opts.logger.Infof("found open order #%d is not in active orderbook, updating...", openOrder.OrderID)
|
opts.logger.Infof("found open order #%d is not in active orderbook, updating...", openOrder.OrderID)
|
||||||
// we don't add open orders into active orderbook if updated in 3 min, because we may receive message from websocket and add it twice.
|
// we don't add open orders into active orderbook if updated in 3 min, because we may receive message from websocket and add it twice.
|
||||||
if openOrder.UpdateTime.After(doNotSyncAfter) {
|
if openOrder.UpdateTime.After(syncBefore) {
|
||||||
opts.logger.Infof("open order #%d is updated in 3 min, skip updating...", openOrder.OrderID)
|
opts.logger.Infof("open order #%d is updated in 3 min, skip updating...", openOrder.OrderID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user