bbgo/pkg/strategy/grid2/debug.go

57 lines
1.2 KiB
Go

package grid2
import (
"fmt"
"strings"
"github.com/sirupsen/logrus"
"git.qtrade.icu/lychiyu/bbgo/pkg/bbgo"
"git.qtrade.icu/lychiyu/bbgo/pkg/fixedpoint"
"git.qtrade.icu/lychiyu/bbgo/pkg/types"
)
func debugGrid(logger logrus.FieldLogger, grid *Grid, book *bbgo.ActiveOrderBook) {
var sb strings.Builder
sb.WriteString("================== GRID ORDERS ==================\n")
pins := grid.Pins
missingPins := scanMissingPinPrices(book, pins)
missing := len(missingPins)
for i := len(pins) - 1; i >= 0; i-- {
pin := pins[i]
price := fixedpoint.Value(pin)
sb.WriteString(fmt.Sprintf("%s -> ", price.String()))
existingOrder := book.Lookup(func(o types.Order) bool {
return o.Price.Eq(price)
})
if existingOrder != nil {
sb.WriteString(existingOrder.String())
switch existingOrder.Status {
case types.OrderStatusFilled:
sb.WriteString(" | 🔧")
case types.OrderStatusCanceled:
sb.WriteString(" | 🔄")
default:
sb.WriteString(" | ✅")
}
} else {
sb.WriteString("ORDER MISSING ⚠️ ")
if missing == 1 {
sb.WriteString(" COULD BE EMPTY SLOT")
}
}
sb.WriteString("\n")
}
sb.WriteString("================== END OF GRID ORDERS ===================")
logger.Infoln(sb.String())
}