diff --git a/pkg/strategy/xmaker/metrics.go b/pkg/strategy/xmaker/metrics.go index bb2c157dc..a05743d19 100644 --- a/pkg/strategy/xmaker/metrics.go +++ b/pkg/strategy/xmaker/metrics.go @@ -26,6 +26,18 @@ var makerBestAskPriceMetrics = prometheus.NewGaugeVec( Help: "", }, []string{"strategy_type", "strategy_id", "exchange", "symbol"}) +var bidMarginMetrics = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "xmaker_bid_margin", + Help: "the current bid margin (dynamic)", + }, []string{"strategy_type", "strategy_id", "exchange", "symbol"}) + +var askMarginMetrics = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "xmaker_ask_margin", + Help: "the current ask margin (dynamic)", + }, []string{"strategy_type", "strategy_id", "exchange", "symbol"}) + var configNumOfLayersMetrics = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "xmaker_config_num_of_layers", @@ -56,6 +68,8 @@ func init() { openOrderAskExposureInUsdMetrics, makerBestBidPriceMetrics, makerBestAskPriceMetrics, + bidMarginMetrics, + askMarginMetrics, configNumOfLayersMetrics, configMaxExposureMetrics, configBidMarginMetrics, diff --git a/pkg/strategy/xmaker/strategy.go b/pkg/strategy/xmaker/strategy.go index 2d88eda74..6354bedc3 100644 --- a/pkg/strategy/xmaker/strategy.go +++ b/pkg/strategy/xmaker/strategy.go @@ -401,9 +401,12 @@ func (s *Strategy) updateQuote(ctx context.Context) { bidExposureInUsd := fixedpoint.Zero askExposureInUsd := fixedpoint.Zero - bidPrice := bestBidPrice askPrice := bestAskPrice + + bidMarginMetrics.With(labels).Set(bidMargin.Float64()) + askMarginMetrics.With(labels).Set(askMargin.Float64()) + for i := 0; i < s.NumLayers; i++ { // for maker bid orders if !disableMakerBid { @@ -430,13 +433,13 @@ func (s *Strategy) updateQuote(ctx context.Context) { } bidPrice = bidPrice.Mul(fixedpoint.One.Sub(bidMargin)) - if i > 0 && pips.Sign() > 0 { + if i == 0 { + makerBestBidPriceMetrics.With(labels).Set(bidPrice.Float64()) + } else if i > 0 && pips.Sign() > 0 { bidPrice = bidPrice.Sub(pips.Mul(fixedpoint.NewFromInt(int64(i)). Mul(s.makerMarket.TickSize))) } - makerBestBidPriceMetrics.With(labels).Set(bidPrice.Float64()) - if makerQuota.QuoteAsset.Lock(bidQuantity.Mul(bidPrice)) && hedgeQuota.BaseAsset.Lock(bidQuantity) { // if we bought, then we need to sell the base from the hedge session submitOrders = append(submitOrders, types.SubmitOrder{ @@ -487,12 +490,12 @@ func (s *Strategy) updateQuote(ctx context.Context) { } askPrice = askPrice.Mul(fixedpoint.One.Add(askMargin)) - if i > 0 && pips.Sign() > 0 { + if i == 0 { + makerBestAskPriceMetrics.With(labels).Set(askPrice.Float64()) + } else if i > 0 && pips.Sign() > 0 { askPrice = askPrice.Add(pips.Mul(fixedpoint.NewFromInt(int64(i)).Mul(s.makerMarket.TickSize))) } - makerBestAskPriceMetrics.With(labels).Set(askPrice.Float64()) - if makerQuota.BaseAsset.Lock(askQuantity) && hedgeQuota.QuoteAsset.Lock(askQuantity.Mul(askPrice)) { // if we bought, then we need to sell the base from the hedge session