Skip to content

Commit 9939b5c

Browse files
committed
xmaker: improve bid/ask pricing when UseDepthPrice and DepthQuantity are on
1 parent a740ef1 commit 9939b5c

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

pkg/strategy/xmaker/strategy.go

+31-10
Original file line numberDiff line numberDiff line change
@@ -498,21 +498,32 @@ func (s *Strategy) updateQuote(ctx context.Context) {
498498
}
499499

500500
accumulativeBidQuantity = accumulativeBidQuantity.Add(bidQuantity)
501+
501502
if s.UseDepthPrice {
502503
sideBook := sourceBook.SideBook(types.SideTypeBuy)
503504
if s.DepthQuantity.Sign() > 0 {
504-
bidPrice = aggregatePrice(sideBook, s.DepthQuantity)
505+
if i == 0 {
506+
bidPrice = aggregatePrice(sideBook, s.DepthQuantity)
507+
bidPrice = bidPrice.Mul(fixedpoint.One.Sub(quote.BidMargin))
508+
} else if i > 0 && quote.BidLayerPips.Sign() > 0 {
509+
pips := quote.BidLayerPips.Mul(s.makerMarket.TickSize)
510+
bidPrice = bidPrice.Sub(pips)
511+
}
505512
} else {
506513
bidPrice = aggregatePrice(sideBook, accumulativeBidQuantity)
514+
bidPrice = bidPrice.Mul(fixedpoint.One.Sub(quote.BidMargin))
515+
}
516+
} else {
517+
if i == 0 {
518+
bidPrice = bidPrice.Mul(fixedpoint.One.Sub(quote.BidMargin))
519+
} else if i > 0 && quote.BidLayerPips.Sign() > 0 {
520+
pips := quote.BidLayerPips.Mul(s.makerMarket.TickSize)
521+
bidPrice = bidPrice.Sub(pips)
507522
}
508523
}
509524

510525
if i == 0 {
511-
bidPrice = bidPrice.Mul(fixedpoint.One.Sub(quote.BidMargin))
512526
makerBestBidPriceMetrics.With(labels).Set(bidPrice.Float64())
513-
} else if i > 0 && quote.BidLayerPips.Sign() > 0 {
514-
pips := quote.BidLayerPips.Mul(s.makerMarket.TickSize)
515-
bidPrice = bidPrice.Sub(pips)
516527
}
517528

518529
if makerQuota.QuoteAsset.Lock(bidQuantity.Mul(bidPrice)) && hedgeQuota.BaseAsset.Lock(bidQuantity) {
@@ -558,18 +569,28 @@ func (s *Strategy) updateQuote(ctx context.Context) {
558569

559570
if s.UseDepthPrice {
560571
if s.DepthQuantity.Sign() > 0 {
561-
askPrice = aggregatePrice(sourceBook.SideBook(types.SideTypeSell), s.DepthQuantity)
572+
if i == 0 {
573+
askPrice = aggregatePrice(sourceBook.SideBook(types.SideTypeSell), s.DepthQuantity)
574+
askPrice = askPrice.Mul(fixedpoint.One.Add(quote.AskMargin))
575+
} else if i > 0 && quote.AskLayerPips.Sign() > 0 {
576+
pips := quote.AskLayerPips.Mul(s.makerMarket.TickSize)
577+
askPrice = askPrice.Add(pips)
578+
}
562579
} else {
563580
askPrice = aggregatePrice(sourceBook.SideBook(types.SideTypeSell), accumulativeAskQuantity)
581+
askPrice = askPrice.Mul(fixedpoint.One.Add(quote.AskMargin))
582+
}
583+
} else {
584+
if i == 0 {
585+
askPrice = askPrice.Mul(fixedpoint.One.Add(quote.AskMargin))
586+
} else if i > 0 && quote.AskLayerPips.Sign() > 0 {
587+
pips := quote.AskLayerPips.Mul(s.makerMarket.TickSize)
588+
askPrice = askPrice.Add(pips)
564589
}
565590
}
566591

567592
if i == 0 {
568-
askPrice = askPrice.Mul(fixedpoint.One.Add(quote.AskMargin))
569593
makerBestAskPriceMetrics.With(labels).Set(askPrice.Float64())
570-
} else if i > 0 && quote.AskLayerPips.Sign() > 0 {
571-
pips := quote.AskLayerPips.Mul(s.makerMarket.TickSize)
572-
askPrice = askPrice.Add(pips)
573594
}
574595

575596
if makerQuota.BaseAsset.Lock(askQuantity) && hedgeQuota.QuoteAsset.Lock(askQuantity.Mul(askPrice)) {

0 commit comments

Comments
 (0)