Merge pull request #1630 from c9s/c9s-patch-1

This commit is contained in:
c9s 2024-05-12 00:06:13 +08:00 committed by GitHub
commit 1e41645384
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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"
@ -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"`
@ -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
@ -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
}
@ -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)
}
}
}