grid2: use string builder for debugGrid

This commit is contained in:
c9s 2023-02-22 15:11:47 +08:00
parent 67d84b9716
commit 9d218d93ac
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -2,6 +2,7 @@ package grid2
import (
"fmt"
"strings"
"github.com/c9s/bbgo/pkg/bbgo"
"github.com/c9s/bbgo/pkg/fixedpoint"
@ -9,7 +10,9 @@ import (
)
func debugGrid(grid *Grid, book *bbgo.ActiveOrderBook) {
fmt.Println("================== GRID ORDERS ==================")
var sb strings.Builder
sb.WriteString("================== GRID ORDERS ==================\n")
pins := grid.Pins
missingPins := scanMissingPinPrices(book, pins)
@ -19,30 +22,33 @@ func debugGrid(grid *Grid, book *bbgo.ActiveOrderBook) {
pin := pins[i]
price := fixedpoint.Value(pin)
fmt.Printf("%s -> ", price.String())
sb.WriteString(fmt.Sprintf("%s -> ", price.String()))
existingOrder := book.Lookup(func(o types.Order) bool {
return o.Price.Eq(price)
})
if existingOrder != nil {
fmt.Printf("%s", existingOrder.String())
sb.WriteString(fmt.Sprintf("%s", existingOrder.String()))
switch existingOrder.Status {
case types.OrderStatusFilled:
fmt.Printf(" | 🔧")
sb.WriteString(" | 🔧")
case types.OrderStatusCanceled:
fmt.Printf(" | 🔄")
sb.WriteString(" | 🔄")
default:
fmt.Printf(" | ✅")
sb.WriteString(" | ✅")
}
} else {
fmt.Printf("ORDER MISSING ⚠️ ")
sb.WriteString("ORDER MISSING ⚠️ ")
if missing == 1 {
fmt.Printf(" COULD BE EMPTY SLOT")
sb.WriteString(" COULD BE EMPTY SLOT")
}
}
fmt.Printf("\n")
sb.WriteString("\n")
}
fmt.Println("================== END OF GRID ORDERS ===================")
sb.WriteString("================== END OF GRID ORDERS ===================")
fmt.Println(sb.String())
}