xmaker: add MaxHedgeAccountLeverage option

This commit is contained in:
c9s 2024-09-01 15:42:36 +08:00
parent ad6056834e
commit ed073264f1
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -119,6 +119,8 @@ type Strategy struct {
// MaxExposurePosition defines the unhedged quantity of stop // MaxExposurePosition defines the unhedged quantity of stop
MaxExposurePosition fixedpoint.Value `json:"maxExposurePosition"` MaxExposurePosition fixedpoint.Value `json:"maxExposurePosition"`
MaxHedgeAccountLeverage fixedpoint.Value `json:"maxHedgeAccountLeverage"`
DisableHedge bool `json:"disableHedge"` DisableHedge bool `json:"disableHedge"`
NotifyTrade bool `json:"notifyTrade"` NotifyTrade bool `json:"notifyTrade"`
@ -532,10 +534,9 @@ func (s *Strategy) updateQuote(ctx context.Context) {
// calculate credit buffer // calculate credit buffer
s.logger.Infof("hedge account net value in usd: %f", netValueInUsd.Float64()) s.logger.Infof("hedge account net value in usd: %f", netValueInUsd.Float64())
maximumHedgeAccountLeverage := fixedpoint.NewFromFloat(1.2) maximumValueInUsd := netValueInUsd.Mul(s.MaxHedgeAccountLeverage)
maximumValueInUsd := netValueInUsd.Mul(maximumHedgeAccountLeverage)
s.logger.Infof("hedge account maximum leveraged value in usd: %f", maximumValueInUsd.Float64()) s.logger.Infof("hedge account maximum leveraged value in usd: %f (%f x)", maximumValueInUsd.Float64(), s.MaxHedgeAccountLeverage.Float64())
if quote, ok := hedgeAccount.Balance(s.sourceMarket.QuoteCurrency); ok { if quote, ok := hedgeAccount.Balance(s.sourceMarket.QuoteCurrency); ok {
debt := quote.Debt() debt := quote.Debt()
@ -562,7 +563,6 @@ func (s *Strategy) updateQuote(ctx context.Context) {
} }
} }
} }
} else { } else {
if b, ok := hedgeBalances[s.sourceMarket.BaseCurrency]; ok { if b, ok := hedgeBalances[s.sourceMarket.BaseCurrency]; ok {
// to make bid orders, we need enough base asset in the foreign exchange, // to make bid orders, we need enough base asset in the foreign exchange,
@ -1037,6 +1037,10 @@ func (s *Strategy) Defaults() error {
s.MinMarginLevel = fixedpoint.NewFromFloat(3.0) s.MinMarginLevel = fixedpoint.NewFromFloat(3.0)
} }
if s.MaxHedgeAccountLeverage.IsZero() {
s.MaxHedgeAccountLeverage = fixedpoint.NewFromFloat(1.2)
}
if s.BidMargin.IsZero() { if s.BidMargin.IsZero() {
if !s.Margin.IsZero() { if !s.Margin.IsZero() {
s.BidMargin = s.Margin s.BidMargin = s.Margin