Skip to content

Commit

Permalink
add UseProtectedPriceRange support
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed May 11, 2024
1 parent b752e5e commit b9c77c1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/strategy/liquiditymaker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}

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

Expand Down

0 comments on commit b9c77c1

Please sign in to comment.