From b752e5ec60a88c3bde6113847254fc3b4ef15504 Mon Sep 17 00:00:00 2001 From: c9s Date: Sat, 11 May 2024 22:47:29 +0800 Subject: [PATCH 1/2] Fix cancel all orders --- pkg/strategy/liquiditymaker/strategy.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/strategy/liquiditymaker/strategy.go b/pkg/strategy/liquiditymaker/strategy.go index 47588a87e3..bb669dd472 100644 --- a/pkg/strategy/liquiditymaker/strategy.go +++ b/pkg/strategy/liquiditymaker/strategy.go @@ -13,6 +13,7 @@ import ( "github.com/c9s/bbgo/pkg/strategy/common" "github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/util" + "github.com/c9s/bbgo/pkg/util/tradingutil" ) const ID = "liquiditymaker" @@ -145,6 +146,10 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo. if err := s.adjustmentOrderBook.GracefulCancel(ctx, s.Session.Exchange); err != nil { util.LogErr(err, "unable to cancel adjustment orders") } + + if err := tradingutil.UniversalCancelAllOrders(ctx, s.Session.Exchange, nil); err != nil { + util.LogErr(err, "unable to cancel all orders") + } }) return nil From b9c77c1584bb2fc7da1160f7733d7beb88e9401e Mon Sep 17 00:00:00 2001 From: c9s Date: Sat, 11 May 2024 23:00:37 +0800 Subject: [PATCH 2/2] add UseProtectedPriceRange support --- pkg/strategy/liquiditymaker/strategy.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/strategy/liquiditymaker/strategy.go b/pkg/strategy/liquiditymaker/strategy.go index bb669dd472..9f1d68d062 100644 --- a/pkg/strategy/liquiditymaker/strategy.go +++ b/pkg/strategy/liquiditymaker/strategy.go @@ -52,6 +52,8 @@ type Strategy struct { AskLiquidityAmount fixedpoint.Value `json:"askLiquidityAmount"` BidLiquidityAmount fixedpoint.Value `json:"bidLiquidityAmount"` + UseProtectedPriceRange bool `json:"useProtectedPriceRange"` + UseLastTradePrice bool `json:"useLastTradePrice"` Spread fixedpoint.Value `json:"spread"` MaxPrice fixedpoint.Value `json:"maxPrice"` @@ -270,7 +272,7 @@ func (s *Strategy) placeLiquidityOrders(ctx context.Context) { currentSpread := ticker.Sell.Sub(ticker.Buy) sideSpread := s.Spread.Div(fixedpoint.Two) - if s.UseLastTradePrice { + if s.UseLastTradePrice && !lastTradedPrice.IsZero() { midPrice = lastTradedPrice } @@ -297,9 +299,17 @@ func (s *Strategy) placeLiquidityOrders(ctx context.Context) { if s.Position.IsLong() { availableBase = availableBase.Sub(s.Position.Base) availableBase = s.Market.RoundDownQuantityByPrecision(availableBase) + + if s.UseProtectedPriceRange { + ask1Price = profitProtectedPrice(types.SideTypeSell, s.Position.AverageCost, ask1Price, s.Session.MakerFeeRate, s.MinProfit) + } } else if s.Position.IsShort() { posSizeInQuote := s.Position.Base.Mul(ticker.Sell) availableQuote = availableQuote.Sub(posSizeInQuote) + + if s.UseProtectedPriceRange { + bid1Price = profitProtectedPrice(types.SideTypeBuy, s.Position.AverageCost, bid1Price, s.Session.MakerFeeRate, s.MinProfit) + } } }