Skip to content

Commit

Permalink
round down quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
narumiruna committed Jun 25, 2024
1 parent ad5674d commit edfeaab
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 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 @@ -255,9 +256,9 @@ func (s *Strategy) generateOrder(ctx context.Context) (*types.SubmitOrder, error
}

if side == types.SideTypeBuy {
quantity = fixedpoint.Min(quantity, balances[s.QuoteCurrency].Available.Div(ticker.Sell))
quantity = fixedpoint.Min(quantity, balances[s.QuoteCurrency].Available.Div(ticker.Sell)).Round(market.VolumePrecision, fixedpoint.Down)
} else if side == types.SideTypeSell {
quantity = fixedpoint.Min(quantity, balances[market.BaseCurrency].Available)
quantity = fixedpoint.Min(quantity, balances[market.BaseCurrency].Available).Round(market.VolumePrecision, fixedpoint.Down)
}

price := s.PriceType.Map(ticker, side)
Expand Down

0 comments on commit edfeaab

Please sign in to comment.