Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: [dca2] update message log level #1854

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkg/strategy/dca2/open_position.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ func (s *Strategy) placeOpenPositionOrders(ctx context.Context) error {
s.logger.Infof("start placing open position orders")
price, err := getBestPriceUntilSuccess(ctx, s.ExchangeSession.Exchange, s.Symbol)
if err != nil {
return err
return fmt.Errorf("failed to get best price: %w", err)
}

orders, err := generateOpenPositionOrders(s.Market, s.EnableQuoteInvestmentReallocate, s.QuoteInvestment, s.ProfitStats.TotalProfit, price, s.PriceDeviation, s.MaxOrderCount, s.OrderGroupID)
if err != nil {
return err
return fmt.Errorf("failed to generate open position orders: %w", err)
}

createdOrders, err := s.OrderExecutor.SubmitOrders(ctx, orders...)
if err != nil {
return err
return fmt.Errorf("failed to submit open position orders: %w", err)
}

s.debugOrders(createdOrders)
Expand Down Expand Up @@ -75,11 +75,11 @@ func generateOpenPositionOrders(market types.Market, enableQuoteInvestmentReallo

notional, orderNum := calculateNotionalAndNumOrders(market, quoteInvestment, prices)
if orderNum == 0 {
return nil, fmt.Errorf("failed to calculate notional and num of open position orders, price: %s, quote investment: %s", price, quoteInvestment)
return nil, fmt.Errorf("notional and num of open position orders can't be calculated, price: %s, quote investment: %s", price, quoteInvestment)
}

if !enableQuoteInvestmentReallocate && orderNum != int(maxOrderCount) {
return nil, fmt.Errorf("failed to generate open-position orders due to the orders may be under min notional or quantity")
return nil, fmt.Errorf("the orders may be under min notional or quantity")
}

side := types.SideTypeBuy
Expand Down
8 changes: 7 additions & 1 deletion pkg/strategy/dca2/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dca2

import (
"context"
"strings"
"time"

"github.com/c9s/bbgo/pkg/bbgo"
Expand Down Expand Up @@ -169,7 +170,12 @@ func (s *Strategy) runPositionOpening(ctx context.Context, next State) bool {
s.logger.Info("[State] PositionOpening - start placing open-position orders")

if err := s.placeOpenPositionOrders(ctx); err != nil {
s.logger.WithError(err).Error("failed to place open-position orders, please check it.")
if strings.Contains(err.Error(), "failed to generate open position orders") {
s.logger.WithError(err).Warn("failed to place open-position orders, please check it.")
} else {
s.logger.WithError(err).Error("failed to place open-position orders, please check it.")
}

return false
}

Expand Down
Loading