2022-05-30 16:59:33 +00:00
|
|
|
package batch
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/c9s/bbgo/pkg/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type KLineBatchQuery struct {
|
|
|
|
types.Exchange
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *KLineBatchQuery) Query(ctx context.Context, symbol string, interval types.Interval, startTime, endTime time.Time) (c chan types.KLine, errC chan error) {
|
|
|
|
query := &AsyncTimeRangedBatchQuery{
|
|
|
|
Type: types.KLine{},
|
2022-06-02 08:40:24 +00:00
|
|
|
Limiter: nil, // the rate limiter is handled in the exchange query method
|
2022-05-30 16:59:33 +00:00
|
|
|
Q: func(startTime, endTime time.Time) (interface{}, error) {
|
|
|
|
return e.Exchange.QueryKLines(ctx, symbol, interval, types.KLineQueryOptions{
|
|
|
|
StartTime: &startTime,
|
|
|
|
EndTime: &endTime,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
T: func(obj interface{}) time.Time {
|
2022-06-02 08:12:17 +00:00
|
|
|
return time.Time(obj.(types.KLine).StartTime).UTC()
|
2022-05-30 16:59:33 +00:00
|
|
|
},
|
|
|
|
ID: func(obj interface{}) string {
|
|
|
|
kline := obj.(types.KLine)
|
|
|
|
return kline.StartTime.String()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-06-02 08:40:24 +00:00
|
|
|
c = make(chan types.KLine, 3000)
|
2022-05-30 16:59:33 +00:00
|
|
|
errC = query.Query(ctx, c, startTime, endTime)
|
|
|
|
return c, errC
|
|
|
|
}
|