Skip to content

Commit

Permalink
Merge pull request #1630 from c9s/c9s-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s authored May 11, 2024
2 parents 002151b + b9c77c1 commit 1e41645
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/strategy/liquiditymaker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -51,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"`
Expand Down Expand Up @@ -145,6 +148,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
Expand Down Expand Up @@ -265,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
}

Expand All @@ -292,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)
}
}
}

Expand Down

0 comments on commit 1e41645

Please sign in to comment.