bbgo_origin/pkg/strategy/grid2/pin_order_map.go

49 lines
1.1 KiB
Go
Raw Normal View History

2023-03-14 05:46:46 +00:00
package grid2
import (
2023-03-16 08:43:56 +00:00
"fmt"
"strings"
2023-03-14 05:46:46 +00:00
"github.com/c9s/bbgo/pkg/types"
)
// PinOrderMap store the pin-order's relation, we will change key from string to fixedpoint.Value when FormatString fixed
type PinOrderMap map[string]types.Order
// AscendingOrders get the orders from pin order map and sort it in asc order
func (m PinOrderMap) AscendingOrders() []types.Order {
var orders []types.Order
for _, order := range m {
// skip empty order
if order.OrderID == 0 {
continue
}
orders = append(orders, order)
}
types.SortOrdersUpdateTimeAscending(orders)
return orders
}
func (m PinOrderMap) SyncOrderMap() *types.SyncOrderMap {
2023-03-14 05:46:46 +00:00
orderMap := types.NewSyncOrderMap()
for _, order := range m {
orderMap.Add(order)
}
return orderMap
}
2023-03-16 08:43:56 +00:00
func (m PinOrderMap) String() string {
var sb strings.Builder
sb.WriteString("================== PIN ORDER MAP ==================\n")
for pin, order := range m {
sb.WriteString(fmt.Sprintf("%s -> %s\n", pin, order.String()))
}
sb.WriteString("================== END OF PIN ORDER MAP ==================\n")
return sb.String()
}