mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Merge pull request #1611 from c9s/kbearXD/dca2/not-place-orders-under-mq
FEATURE: [dca2] new flag EnableQuoteInvestmentReallocate to decide if…
This commit is contained in:
commit
7c604a5d51
|
@ -21,7 +21,7 @@ func (s *Strategy) placeOpenPositionOrders(ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
orders, err := generateOpenPositionOrders(s.Market, s.QuoteInvestment, s.ProfitStats.TotalProfit, price, s.PriceDeviation, s.MaxOrderCount, s.OrderGroupID)
|
||||
orders, err := generateOpenPositionOrders(s.Market, s.EnableQuoteInvestmentReallocate, s.QuoteInvestment, s.ProfitStats.TotalProfit, price, s.PriceDeviation, s.MaxOrderCount, s.OrderGroupID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ func getBestPriceUntilSuccess(ctx context.Context, ex types.Exchange, symbol str
|
|||
return ticker.Sell, nil
|
||||
}
|
||||
|
||||
func generateOpenPositionOrders(market types.Market, quoteInvestment, profit, price, priceDeviation fixedpoint.Value, maxOrderCount int64, orderGroupID uint32) ([]types.SubmitOrder, error) {
|
||||
func generateOpenPositionOrders(market types.Market, enableQuoteInvestmentReallocate bool, quoteInvestment, profit, price, priceDeviation fixedpoint.Value, maxOrderCount int64, orderGroupID uint32) ([]types.SubmitOrder, error) {
|
||||
factor := fixedpoint.One.Sub(priceDeviation)
|
||||
profit = market.TruncatePrice(profit)
|
||||
|
||||
|
@ -83,6 +83,10 @@ func generateOpenPositionOrders(market types.Market, quoteInvestment, profit, pr
|
|||
return nil, fmt.Errorf("failed to calculate notional and num of open position orders, 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")
|
||||
}
|
||||
|
||||
side := types.SideTypeBuy
|
||||
|
||||
var submitOrders []types.SubmitOrder
|
||||
|
|
|
@ -150,8 +150,13 @@ func (s *Strategy) runPositionOpening(ctx context.Context, next State) {
|
|||
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 dca orders, please check it.")
|
||||
|
||||
// try after 1 minute when failed to placing orders
|
||||
s.startTimeOfNextRound = s.startTimeOfNextRound.Add(1 * time.Minute)
|
||||
s.updateState(WaitToOpenPosition)
|
||||
return
|
||||
}
|
||||
|
||||
s.updateState(OpenPositionReady)
|
||||
s.logger.Info("[State] PositionOpening -> OpenPositionReady")
|
||||
}
|
||||
|
|
|
@ -70,6 +70,9 @@ type Strategy struct {
|
|||
DisableProfitStatsRecover bool `json:"disableProfitStatsRecover"`
|
||||
DisablePositionRecover bool `json:"disablePositionRecover"`
|
||||
|
||||
// EnableQuoteInvestmentReallocate set to true, the quote investment will be reallocated when the notional or quantity is under minimum.
|
||||
EnableQuoteInvestmentReallocate bool `json:"enableQuoteInvestmentReallocate"`
|
||||
|
||||
// KeepOrdersWhenShutdown option is used for keeping the grid orders when shutting down bbgo
|
||||
KeepOrdersWhenShutdown bool `json:"keepOrdersWhenShutdown"`
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user