57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package grid2
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"git.qtrade.icu/lychiyu/qbtrade/pkg/fixedpoint"
|
|
"git.qtrade.icu/lychiyu/qbtrade/pkg/qbtrade"
|
|
"git.qtrade.icu/lychiyu/qbtrade/pkg/types"
|
|
)
|
|
|
|
func debugGrid(logger logrus.FieldLogger, grid *Grid, book *qbtrade.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())
|
|
}
|