From 0eb38569065c2c03cdd35fa562c2d0070dd7e9f4 Mon Sep 17 00:00:00 2001 From: narumi Date: Tue, 25 Jun 2024 22:14:49 +0800 Subject: [PATCH] round down quantity --- pkg/strategy/rebalance/strategy.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/strategy/rebalance/strategy.go b/pkg/strategy/rebalance/strategy.go index 0b0ccef4c..eab1de87c 100644 --- a/pkg/strategy/rebalance/strategy.go +++ b/pkg/strategy/rebalance/strategy.go @@ -136,8 +136,9 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo. // the shutdown handler, you can cancel all orders bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) { defer wg.Done() - _ = s.OrderExecutorMap.GracefulCancel(ctx) - bbgo.Sync(ctx, s) + if err := s.activeOrderBook.GracefulCancel(ctx, s.Session.Exchange); err != nil { + log.WithError(err).Errorf("failed to cancel orders") + } }) s.cron = cron.New() @@ -174,7 +175,7 @@ func (s *Strategy) rebalance(ctx context.Context) { createdOrders, err := s.OrderExecutorMap.SubmitOrders(ctx, *order) if err != nil { - log.WithError(err).Error("failed to submit orders") + log.WithError(err).Errorf("failed to submit order: %s", order.String()) return } s.activeOrderBook.Add(createdOrders...) @@ -259,6 +260,7 @@ func (s *Strategy) generateOrder(ctx context.Context) (*types.SubmitOrder, error } else if side == types.SideTypeSell { quantity = fixedpoint.Min(quantity, balances[market.BaseCurrency].Available) } + quantity = market.RoundDownQuantityByPrecision(quantity) price := s.PriceType.Map(ticker, side)