mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
grid2: simplify isCompleteGridOrderBook
This commit is contained in:
parent
a75bc2e590
commit
c860e45c34
|
@ -1527,7 +1527,8 @@ func (s *Strategy) replayOrderHistory(ctx context.Context, grid *Grid, orderBook
|
|||
// isCompleteGridOrderBook checks if the number of open orders == gridNum - 1 and all orders are active order
|
||||
func isCompleteGridOrderBook(orderBook *bbgo.ActiveOrderBook, gridNum int64) bool {
|
||||
tmpOrders := orderBook.Orders()
|
||||
return len(tmpOrders) == int(gridNum)-1 && types.OrdersAll(tmpOrders, types.IsActiveOrder)
|
||||
activeOrders := types.OrdersActive(tmpOrders)
|
||||
return len(activeOrders) == int(gridNum)-1
|
||||
}
|
||||
|
||||
func findEarliestOrderID(orders []types.Order) (uint64, bool) {
|
||||
|
|
|
@ -395,17 +395,25 @@ func (o Order) SlackAttachment() slack.Attachment {
|
|||
}
|
||||
}
|
||||
|
||||
func OrdersFilled(in []Order) (out []Order) {
|
||||
func OrdersFilter(in []Order, f func(o Order) bool) (out []Order) {
|
||||
for _, o := range in {
|
||||
switch o.Status {
|
||||
case OrderStatusFilled:
|
||||
o2 := o
|
||||
out = append(out, o2)
|
||||
if f(o) {
|
||||
out = append(out, o)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func OrdersActive(in []Order) []Order {
|
||||
return OrdersFilter(in, IsActiveOrder)
|
||||
}
|
||||
|
||||
func OrdersFilled(in []Order) (out []Order) {
|
||||
return OrdersFilter(in, func(o Order) bool {
|
||||
return o.Status == OrderStatusFilled
|
||||
})
|
||||
}
|
||||
|
||||
func OrdersAll(orders []Order, f func(o Order) bool) bool {
|
||||
for _, o := range orders {
|
||||
if !f(o) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user