Skip to content
forked from c9s/bbgo

Commit

Permalink
Merge pull request c9s#1663 from c9s/narumi/rebalance-round-down-qty
Browse files Browse the repository at this point in the history
FIX: [rebalance] round down quantity
  • Loading branch information
narumiruna authored Jul 9, 2024
2 parents e7a20db + 0eb3856 commit be27d32
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/strategy/rebalance/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit be27d32

Please sign in to comment.