liqmaker: add AdjustmentOrderPriceType

This commit is contained in:
c9s 2024-10-25 12:20:59 +08:00
parent 0036a57904
commit ced8b5f742
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -41,7 +41,8 @@ type Strategy struct {
LiquidityUpdateInterval types.Interval `json:"liquidityUpdateInterval"` LiquidityUpdateInterval types.Interval `json:"liquidityUpdateInterval"`
AdjustmentUpdateInterval types.Interval `json:"adjustmentUpdateInterval"` AdjustmentUpdateInterval types.Interval `json:"adjustmentUpdateInterval"`
MaxAdjustmentOrderQuantity fixedpoint.Value `json:"maxAdjustmentOrderQuantity"` AdjustmentOrderMaxQuantity fixedpoint.Value `json:"adjustmentOrderMaxQuantity"`
AdjustmentOrderPriceType types.PriceType `json:"adjustmentOrderPriceType"`
NumOfLiquidityLayers int `json:"numOfLiquidityLayers"` NumOfLiquidityLayers int `json:"numOfLiquidityLayers"`
LiquiditySlideRule *bbgo.SlideRule `json:"liquidityScale"` LiquiditySlideRule *bbgo.SlideRule `json:"liquidityScale"`
@ -92,6 +93,22 @@ func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.LiquidityUpdateInterval}) session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.LiquidityUpdateInterval})
} }
func (s *Strategy) Defaults() error {
if s.AdjustmentOrderPriceType == "" {
s.AdjustmentOrderPriceType = types.PriceTypeMaker
}
if s.LiquidityUpdateInterval == "" {
s.LiquidityUpdateInterval = types.Interval1h
}
if s.AdjustmentUpdateInterval == "" {
s.AdjustmentUpdateInterval = types.Interval5m
}
return nil
}
func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error { func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
if s.ProfitFixerBundle.ProfitFixerConfig != nil { if s.ProfitFixerBundle.ProfitFixerConfig != nil {
market, _ := session.Market(s.Symbol) market, _ := session.Market(s.Symbol)
@ -193,14 +210,15 @@ func (s *Strategy) placeAdjustmentOrders(ctx context.Context) {
posSize := s.Position.Base.Abs() posSize := s.Position.Base.Abs()
if !s.MaxAdjustmentOrderQuantity.IsZero() { if !s.AdjustmentOrderMaxQuantity.IsZero() {
posSize = fixedpoint.Min(posSize, s.MaxAdjustmentOrderQuantity) posSize = fixedpoint.Min(posSize, s.AdjustmentOrderMaxQuantity)
} }
tickSize := s.Market.TickSize tickSize := s.Market.TickSize
if s.Position.IsShort() { if s.Position.IsShort() {
price := profitProtectedPrice(types.SideTypeBuy, s.Position.AverageCost, ticker.Sell.Add(tickSize.Neg()), s.Session.MakerFeeRate, s.MinProfit) price := s.AdjustmentOrderPriceType.GetPrice(ticker, types.SideTypeBuy)
price = profitProtectedPrice(types.SideTypeBuy, s.Position.AverageCost, price.Add(tickSize.Neg()), s.Session.MakerFeeRate, s.MinProfit)
quoteQuantity := fixedpoint.Min(price.Mul(posSize), quoteBal.Available) quoteQuantity := fixedpoint.Min(price.Mul(posSize), quoteBal.Available)
bidQuantity := quoteQuantity.Div(price) bidQuantity := quoteQuantity.Div(price)
@ -218,7 +236,8 @@ func (s *Strategy) placeAdjustmentOrders(ctx context.Context) {
TimeInForce: types.TimeInForceGTC, TimeInForce: types.TimeInForceGTC,
}) })
} else if s.Position.IsLong() { } else if s.Position.IsLong() {
price := profitProtectedPrice(types.SideTypeSell, s.Position.AverageCost, ticker.Buy.Add(tickSize), s.Session.MakerFeeRate, s.MinProfit) price := s.AdjustmentOrderPriceType.GetPrice(ticker, types.SideTypeSell)
price = profitProtectedPrice(types.SideTypeSell, s.Position.AverageCost, price.Add(tickSize), s.Session.MakerFeeRate, s.MinProfit)
askQuantity := fixedpoint.Min(posSize, baseBal.Available) askQuantity := fixedpoint.Min(posSize, baseBal.Available)
if s.Market.IsDustQuantity(askQuantity, price) { if s.Market.IsDustQuantity(askQuantity, price) {