bbgo_origin/pkg/strategy/grid2/debug.go

57 lines
1.2 KiB
Go
Raw Permalink Normal View History

2022-12-25 17:04:17 +00:00
package grid2
import (
"fmt"
"strings"
2022-12-25 17:04:17 +00:00
2023-02-22 07:16:47 +00:00
"github.com/sirupsen/logrus"
2022-12-25 17:04:17 +00:00
"github.com/c9s/bbgo/pkg/bbgo"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
)
2023-02-22 07:16:47 +00:00
func debugGrid(logger logrus.FieldLogger, grid *Grid, book *bbgo.ActiveOrderBook) {
var sb strings.Builder
sb.WriteString("================== GRID ORDERS ==================\n")
2022-12-25 17:04:17 +00:00
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()))
2022-12-25 17:04:17 +00:00
existingOrder := book.Lookup(func(o types.Order) bool {
return o.Price.Eq(price)
})
if existingOrder != nil {
2023-02-22 07:45:33 +00:00
sb.WriteString(existingOrder.String())
2022-12-25 17:04:17 +00:00
switch existingOrder.Status {
case types.OrderStatusFilled:
sb.WriteString(" | 🔧")
2022-12-25 17:04:17 +00:00
case types.OrderStatusCanceled:
sb.WriteString(" | 🔄")
2022-12-25 17:04:17 +00:00
default:
sb.WriteString(" | ✅")
2022-12-25 17:04:17 +00:00
}
} else {
sb.WriteString("ORDER MISSING ⚠️ ")
2022-12-25 17:04:17 +00:00
if missing == 1 {
sb.WriteString(" COULD BE EMPTY SLOT")
2022-12-25 17:04:17 +00:00
}
}
sb.WriteString("\n")
2022-12-25 17:04:17 +00:00
}
sb.WriteString("================== END OF GRID ORDERS ===================")
2023-02-22 07:16:47 +00:00
logger.Infoln(sb.String())
2022-12-25 17:04:17 +00:00
}