2022-12-25 17:04:17 +00:00
|
|
|
package grid2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-02-22 07:11:47 +00:00
|
|
|
"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) {
|
2023-02-22 07:11:47 +00:00
|
|
|
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)
|
|
|
|
|
2023-02-22 07:11:47 +00:00
|
|
|
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:
|
2023-02-22 07:11:47 +00:00
|
|
|
sb.WriteString(" | 🔧")
|
2022-12-25 17:04:17 +00:00
|
|
|
case types.OrderStatusCanceled:
|
2023-02-22 07:11:47 +00:00
|
|
|
sb.WriteString(" | 🔄")
|
2022-12-25 17:04:17 +00:00
|
|
|
default:
|
2023-02-22 07:11:47 +00:00
|
|
|
sb.WriteString(" | ✅")
|
2022-12-25 17:04:17 +00:00
|
|
|
}
|
|
|
|
} else {
|
2023-02-22 07:11:47 +00:00
|
|
|
sb.WriteString("ORDER MISSING ⚠️ ")
|
2022-12-25 17:04:17 +00:00
|
|
|
if missing == 1 {
|
2023-02-22 07:11:47 +00:00
|
|
|
sb.WriteString(" COULD BE EMPTY SLOT")
|
2022-12-25 17:04:17 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-22 07:11:47 +00:00
|
|
|
sb.WriteString("\n")
|
2022-12-25 17:04:17 +00:00
|
|
|
}
|
2023-02-22 07:11:47 +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
|
|
|
}
|