grid2: log grid info

This commit is contained in:
c9s 2022-12-03 14:58:53 +08:00
parent 54ffc8cbcc
commit c0573210b3
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
3 changed files with 14 additions and 5 deletions

View File

@ -23,9 +23,9 @@ exchangeStrategies:
- on: max - on: max
grid2: grid2:
symbol: BTCUSDT symbol: BTCUSDT
upperPrice: 20_000.0 upperPrice: 18_000.0
lowerPrice: 10_000.0 lowerPrice: 12_000.0
gridNumber: 50 gridNumber: 100
## profitSpread is the profit spread of the arbitrage order (sell order) ## 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. ## greater the profitSpread, greater the profit you make when the sell order is filled.

View File

@ -1,6 +1,7 @@
package grid2 package grid2
import ( import (
"fmt"
"math" "math"
"sort" "sort"
@ -185,3 +186,7 @@ func (g *Grid) addPins(pins []Pin) {
func (g *Grid) updatePinsCache() { func (g *Grid) updatePinsCache() {
g.pinsCache = buildPinCache(g.Pins) 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())
}

View File

@ -126,6 +126,8 @@ func (s *Strategy) InstanceID() string {
} }
func (s *Strategy) handleOrderFilled(o types.Order) { func (s *Strategy) handleOrderFilled(o types.Order) {
s.logger.Infof("order filled: %s", o.String())
// check order fee // check order fee
newSide := types.SideTypeSell newSide := types.SideTypeSell
newPrice := o.Price 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 = NewGrid(s.LowerPrice, s.UpperPrice, fixedpoint.NewFromInt(s.GridNum), s.Market.TickSize)
s.grid.CalculateArithmeticPins() s.grid.CalculateArithmeticPins()
s.logger.Info(s.grid.String())
bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) { bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
@ -407,9 +411,9 @@ func (s *Strategy) calculateQuoteBaseInvestmentQuantity(quoteInvestment, baseInv
maxNumberOfSellOrders-- maxNumberOfSellOrders--
maxBaseQuantity = baseInvestment.Div(fixedpoint.NewFromInt(int64(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 { 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 buyPlacedPrice := fixedpoint.Zero