mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 16:55:15 +00:00
grid2: add scanOrderCreationTimeRange func
This commit is contained in:
parent
606b4650b3
commit
ae20cef8f4
|
@ -1006,23 +1006,11 @@ func (s *Strategy) recoverGrid(ctx context.Context, historyService types.Exchang
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
firstOrderTime := now.AddDate(0, -1, 0)
|
firstOrderTime := now.AddDate(0, -1, 0)
|
||||||
lastOrderTime := firstOrderTime
|
lastOrderTime := firstOrderTime
|
||||||
if len(openOrders) > 0 {
|
if since, until, ok := scanOrderCreationTimeRange(openOrders); ok {
|
||||||
lastOrderID = openOrders[0].OrderID
|
firstOrderTime = since
|
||||||
firstOrderTime = openOrders[0].CreationTime.Time()
|
lastOrderTime = until
|
||||||
lastOrderTime = firstOrderTime
|
|
||||||
for _, o := range openOrders {
|
|
||||||
if o.OrderID < lastOrderID {
|
|
||||||
lastOrderID = o.OrderID
|
|
||||||
}
|
|
||||||
|
|
||||||
createTime := o.CreationTime.Time()
|
|
||||||
if createTime.Before(firstOrderTime) {
|
|
||||||
firstOrderTime = createTime
|
|
||||||
} else if createTime.After(lastOrderTime) {
|
|
||||||
lastOrderTime = createTime
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
_ = lastOrderTime
|
||||||
|
|
||||||
// Allocate a local order book
|
// Allocate a local order book
|
||||||
orderBook := bbgo.NewActiveOrderBook(s.Symbol)
|
orderBook := bbgo.NewActiveOrderBook(s.Symbol)
|
||||||
|
@ -1132,6 +1120,26 @@ func ordersFilled(in []types.Order) (out []types.Order) {
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// scanOrderCreationTimeRange finds the earliest creation time and the latest creation time from the given orders
|
||||||
|
func scanOrderCreationTimeRange(orders []types.Order) (time.Time, time.Time, bool) {
|
||||||
|
if len(orders) == 0 {
|
||||||
|
return time.Time{}, time.Time{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
firstOrderTime := orders[0].CreationTime.Time()
|
||||||
|
lastOrderTime := firstOrderTime
|
||||||
|
for _, o := range orders {
|
||||||
|
createTime := o.CreationTime.Time()
|
||||||
|
if createTime.Before(firstOrderTime) {
|
||||||
|
firstOrderTime = createTime
|
||||||
|
} else if createTime.After(lastOrderTime) {
|
||||||
|
lastOrderTime = createTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return firstOrderTime, lastOrderTime, true
|
||||||
|
}
|
||||||
|
|
||||||
// scanMissingGridOrders finds the missing grid order prices
|
// scanMissingGridOrders finds the missing grid order prices
|
||||||
func scanMissingGridOrders(orderBook *bbgo.ActiveOrderBook, grid *Grid) PriceMap {
|
func scanMissingGridOrders(orderBook *bbgo.ActiveOrderBook, grid *Grid) PriceMap {
|
||||||
// Add all open orders to the local order book
|
// Add all open orders to the local order book
|
||||||
|
|
Loading…
Reference in New Issue
Block a user