From e187614179f79c4d7e21d851f08173f6861bb439 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 28 Aug 2024 22:32:41 +0800 Subject: [PATCH 1/2] xmaker: log best bid and best ask --- pkg/strategy/xmaker/strategy.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/strategy/xmaker/strategy.go b/pkg/strategy/xmaker/strategy.go index 89ec6e22f..c5a3608aa 100644 --- a/pkg/strategy/xmaker/strategy.go +++ b/pkg/strategy/xmaker/strategy.go @@ -573,6 +573,7 @@ func (s *Strategy) updateQuote(ctx context.Context) { } if i == 0 { + s.logger.Infof("maker best bid price %f", bidPrice.Float64()) makerBestBidPriceMetrics.With(labels).Set(bidPrice.Float64()) } @@ -640,6 +641,7 @@ func (s *Strategy) updateQuote(ctx context.Context) { } if i == 0 { + s.logger.Infof("maker best ask price %f", askPrice.Float64()) makerBestAskPriceMetrics.With(labels).Set(askPrice.Float64()) } From 8de0c6750387df5e22834207c9c7ad2e049a2dc0 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 28 Aug 2024 22:32:27 +0800 Subject: [PATCH 2/2] xmaker: fix aggregatePrice function --- pkg/strategy/xmaker/strategy.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/pkg/strategy/xmaker/strategy.go b/pkg/strategy/xmaker/strategy.go index c5a3608aa..5280738b8 100644 --- a/pkg/strategy/xmaker/strategy.go +++ b/pkg/strategy/xmaker/strategy.go @@ -167,29 +167,23 @@ func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession) { } func aggregatePrice(pvs types.PriceVolumeSlice, requiredQuantity fixedpoint.Value) (price fixedpoint.Value) { - q := requiredQuantity - totalAmount := fixedpoint.Zero - if len(pvs) == 0 { price = fixedpoint.Zero return price - } else if pvs[0].Volume.Compare(requiredQuantity) >= 0 { - return pvs[0].Price } + sumAmount := fixedpoint.Zero + sumQty := fixedpoint.Zero for i := 0; i < len(pvs); i++ { pv := pvs[i] - if pv.Volume.Compare(q) >= 0 { - totalAmount = totalAmount.Add(q.Mul(pv.Price)) + sumQty = sumQty.Add(pv.Volume) + sumAmount = sumAmount.Add(pv.Volume.Mul(pv.Price)) + if sumQty.Compare(requiredQuantity) >= 0 { break } - - q = q.Sub(pv.Volume) - totalAmount = totalAmount.Add(pv.Volume.Mul(pv.Price)) } - price = totalAmount.Div(requiredQuantity) - return price + return sumAmount.Div(sumQty) } func (s *Strategy) Initialize() error {