From c6d977da4a23ef76e7bed5f3b1514ecd10c9e541 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 5 Dec 2024 09:58:13 +0800 Subject: [PATCH] xmaker: add MaxHedgeQuoteQuantityPerOrder option --- pkg/strategy/xmaker/strategy.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/strategy/xmaker/strategy.go b/pkg/strategy/xmaker/strategy.go index a6962d13fd..eae3085d17 100644 --- a/pkg/strategy/xmaker/strategy.go +++ b/pkg/strategy/xmaker/strategy.go @@ -203,7 +203,8 @@ type Strategy struct { // MaxExposurePosition defines the unhedged quantity of stop MaxExposurePosition fixedpoint.Value `json:"maxExposurePosition"` - MaxHedgeAccountLeverage fixedpoint.Value `json:"maxHedgeAccountLeverage"` + MaxHedgeAccountLeverage fixedpoint.Value `json:"maxHedgeAccountLeverage"` + MaxHedgeQuoteQuantityPerOrder fixedpoint.Value `json:"maxHedgeQuoteQuantityPerOrder"` DisableHedge bool `json:"disableHedge"` @@ -1407,8 +1408,12 @@ func (s *Strategy) Hedge(ctx context.Context, pos fixedpoint.Value) { account, s.sourceMarket, side, quantity, lastPrice) } - // truncate quantity for the supported precision - quantity = s.sourceMarket.TruncateQuantity(quantity) + if s.MaxHedgeQuoteQuantityPerOrder.Sign() > 0 && !lastPrice.IsZero() { + quantity = s.sourceMarket.AdjustQuantityByMaxAmount(quantity, lastPrice, s.MaxHedgeQuoteQuantityPerOrder) + } else { + // truncate quantity for the supported precision + quantity = s.sourceMarket.TruncateQuantity(quantity) + } if s.sourceMarket.IsDustQuantity(quantity, lastPrice) { s.logger.Warnf("skip dust quantity: %s @ price %f", quantity.String(), lastPrice.Float64())