Skip to content

Commit

Permalink
xmaker: add MaxHedgeQuoteQuantityPerOrder option
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Dec 5, 2024
1 parent 5d03744 commit c6d977d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/strategy/xmaker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit c6d977d

Please sign in to comment.