From c0573210b31b0c08711d9396b3a3d10a3670539b Mon Sep 17 00:00:00 2001 From: c9s Date: Sat, 3 Dec 2022 14:58:53 +0800 Subject: [PATCH] grid2: log grid info --- config/grid2-max.yaml | 6 +++--- pkg/strategy/grid2/grid.go | 5 +++++ pkg/strategy/grid2/strategy.go | 8 ++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/config/grid2-max.yaml b/config/grid2-max.yaml index fb5416da9..224c09f12 100644 --- a/config/grid2-max.yaml +++ b/config/grid2-max.yaml @@ -23,9 +23,9 @@ exchangeStrategies: - on: max grid2: symbol: BTCUSDT - upperPrice: 20_000.0 - lowerPrice: 10_000.0 - gridNumber: 50 + upperPrice: 18_000.0 + lowerPrice: 12_000.0 + gridNumber: 100 ## profitSpread is the profit spread of the arbitrage order (sell order) ## greater the profitSpread, greater the profit you make when the sell order is filled. diff --git a/pkg/strategy/grid2/grid.go b/pkg/strategy/grid2/grid.go index b2939e223..c533e7421 100644 --- a/pkg/strategy/grid2/grid.go +++ b/pkg/strategy/grid2/grid.go @@ -1,6 +1,7 @@ package grid2 import ( + "fmt" "math" "sort" @@ -185,3 +186,7 @@ func (g *Grid) addPins(pins []Pin) { func (g *Grid) updatePinsCache() { g.pinsCache = buildPinCache(g.Pins) } + +func (g *Grid) String() string { + return fmt.Sprintf("grid: priceRange: %f <=> %f size: %f spread: %f", g.LowerPrice.Float64(), g.UpperPrice.Float64(), g.Size.Float64(), g.Spread.Float64()) +} diff --git a/pkg/strategy/grid2/strategy.go b/pkg/strategy/grid2/strategy.go index 7ac8bf1bd..be15a8463 100644 --- a/pkg/strategy/grid2/strategy.go +++ b/pkg/strategy/grid2/strategy.go @@ -126,6 +126,8 @@ func (s *Strategy) InstanceID() string { } func (s *Strategy) handleOrderFilled(o types.Order) { + s.logger.Infof("order filled: %s", o.String()) + // check order fee newSide := types.SideTypeSell newPrice := o.Price @@ -196,6 +198,8 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se s.grid = NewGrid(s.LowerPrice, s.UpperPrice, fixedpoint.NewFromInt(s.GridNum), s.Market.TickSize) s.grid.CalculateArithmeticPins() + s.logger.Info(s.grid.String()) + bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) { defer wg.Done() @@ -407,9 +411,9 @@ func (s *Strategy) calculateQuoteBaseInvestmentQuantity(quoteInvestment, baseInv maxNumberOfSellOrders-- maxBaseQuantity = baseInvestment.Div(fixedpoint.NewFromInt(int64(maxNumberOfSellOrders))) } - s.logger.Infof("grid %s base investment sell orders: %d", s.Symbol, maxNumberOfSellOrders) + s.logger.Infof("grid base investment sell orders: %d", maxNumberOfSellOrders) if maxNumberOfSellOrders > 0 { - s.logger.Infof("grid %s base investment quantity range: %f <=> %f", s.Symbol, minBaseQuantity.Float64(), maxBaseQuantity.Float64()) + s.logger.Infof("grid base investment quantity range: %f <=> %f", minBaseQuantity.Float64(), maxBaseQuantity.Float64()) } buyPlacedPrice := fixedpoint.Zero