mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
Merge pull request #1088 from c9s/fix/grid2/recover
This commit is contained in:
commit
93dc8e3147
|
@ -1413,9 +1413,10 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService
|
|||
// before we re-play the orders,
|
||||
// we need to add these open orders to the active order book
|
||||
s.addOrdersToActiveOrderBook(gridOrders)
|
||||
|
||||
s.setGrid(grid)
|
||||
s.EmitGridReady()
|
||||
s.updateGridNumOfOrdersMetrics()
|
||||
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
|
||||
|
||||
for i := range filledOrders {
|
||||
// avoid using the iterator
|
||||
|
@ -1523,14 +1524,11 @@ func (s *Strategy) replayOrderHistory(ctx context.Context, grid *Grid, orderBook
|
|||
return nil
|
||||
}
|
||||
|
||||
// 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()
|
||||
|
||||
if len(tmpOrders) == int(gridNum) && types.OrdersAll(tmpOrders, types.IsActiveOrder) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
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