2021-12-31 05:52:16 +00:00
|
|
|
package batch
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-05-30 16:59:33 +00:00
|
|
|
"strconv"
|
2021-12-31 05:52:16 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/c9s/bbgo/pkg/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ClosedOrderBatchQuery struct {
|
2022-05-30 16:59:33 +00:00
|
|
|
types.ExchangeTradeHistoryService
|
2021-12-31 05:52:16 +00:00
|
|
|
}
|
|
|
|
|
2022-05-30 16:59:33 +00:00
|
|
|
func (q *ClosedOrderBatchQuery) Query(ctx context.Context, symbol string, startTime, endTime time.Time, lastOrderID uint64) (c chan types.Order, errC chan error) {
|
|
|
|
query := &AsyncTimeRangedBatchQuery{
|
2022-06-02 08:42:18 +00:00
|
|
|
Type: types.Order{},
|
2022-05-30 16:59:33 +00:00
|
|
|
Q: func(startTime, endTime time.Time) (interface{}, error) {
|
|
|
|
orders, err := q.ExchangeTradeHistoryService.QueryClosedOrders(ctx, symbol, startTime, endTime, lastOrderID)
|
|
|
|
return orders, err
|
|
|
|
},
|
|
|
|
T: func(obj interface{}) time.Time {
|
|
|
|
return time.Time(obj.(types.Order).CreationTime)
|
|
|
|
},
|
|
|
|
ID: func(obj interface{}) string {
|
|
|
|
order := obj.(types.Order)
|
|
|
|
if order.OrderID > lastOrderID {
|
|
|
|
lastOrderID = order.OrderID
|
2021-12-31 05:52:16 +00:00
|
|
|
}
|
2022-05-30 16:59:33 +00:00
|
|
|
return strconv.FormatUint(order.OrderID, 10)
|
|
|
|
},
|
|
|
|
}
|
2021-12-31 05:52:16 +00:00
|
|
|
|
2022-05-30 16:59:33 +00:00
|
|
|
c = make(chan types.Order, 100)
|
|
|
|
errC = query.Query(ctx, c, startTime, endTime)
|
2021-12-31 05:52:16 +00:00
|
|
|
return c, errC
|
|
|
|
}
|