2023-03-14 05:46:46 +00:00
|
|
|
package grid2
|
|
|
|
|
|
|
|
import (
|
2023-03-16 08:43:56 +00:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2023-03-16 13:58:41 +00:00
|
|
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
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
|
2023-03-16 13:58:41 +00:00
|
|
|
type PinOrderMap map[fixedpoint.Value]types.Order
|
2023-03-14 05:46:46 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2023-03-14 06:35:15 +00:00
|
|
|
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 {
|
2023-03-16 09:32:56 +00:00
|
|
|
sb.WriteString(fmt.Sprintf("%+v -> %s\n", pin, order.String()))
|
2023-03-16 08:43:56 +00:00
|
|
|
}
|
|
|
|
sb.WriteString("================== END OF PIN ORDER MAP ==================\n")
|
|
|
|
return sb.String()
|
|
|
|
}
|