From 0c6ef38ea3640ae584788c20eb972a104182aeb2 Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 22 May 2023 18:07:40 +0800 Subject: [PATCH] grid2: apply baseGridNumber --- pkg/strategy/grid2/strategy.go | 39 ++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/pkg/strategy/grid2/strategy.go b/pkg/strategy/grid2/strategy.go index 7cd54af6d..0549e19de 100644 --- a/pkg/strategy/grid2/strategy.go +++ b/pkg/strategy/grid2/strategy.go @@ -91,6 +91,9 @@ type Strategy struct { // GridNum is the grid number, how many orders you want to post on the orderbook. GridNum int64 `json:"gridNumber"` + // BaseGridNum is an optional field used for base investment sell orders + BaseGridNum int `json:"baseGridNumber,omitempty"` + AutoRange *types.SimpleDuration `json:"autoRange"` UpperPrice fixedpoint.Value `json:"upperPrice"` @@ -761,25 +764,29 @@ func (s *Strategy) calculateBaseQuoteInvestmentQuantity(quoteInvestment, baseInv // maxBaseQuantity = baseInvestment / numberOfSellOrders // if maxBaseQuantity < minQuantity or maxBaseQuantity * priceLowest < minNotional // then reduce the numberOfSellOrders - numberOfSellOrders := 0 - for i := len(pins) - 1; i >= 0; i-- { - pin := pins[i] - price := fixedpoint.Value(pin) - sellPrice := price - if s.ProfitSpread.Sign() > 0 { - sellPrice = sellPrice.Add(s.ProfitSpread) + numberOfSellOrders := s.BaseGridNum + + // if it's not configured + if numberOfSellOrders == 0 { + for i := len(pins) - 1; i >= 0; i-- { + pin := pins[i] + price := fixedpoint.Value(pin) + sellPrice := price + if s.ProfitSpread.Sign() > 0 { + sellPrice = sellPrice.Add(s.ProfitSpread) + } + + if sellPrice.Compare(lastPrice) < 0 { + break + } + + numberOfSellOrders++ } - if sellPrice.Compare(lastPrice) < 0 { - break + // avoid placing a sell order above the last price + if numberOfSellOrders > 0 { + numberOfSellOrders-- } - - numberOfSellOrders++ - } - - // avoid placing a sell order above the last price - if numberOfSellOrders > 0 { - numberOfSellOrders-- } // if the maxBaseQuantity is less than minQuantity, then we need to reduce the number of the sell orders