mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-27 17:25:16 +00:00
37 lines
949 B
Go
37 lines
949 B
Go
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{},
|
|
Limiter: nil, // the rate limiter is handled in the exchange query method
|
|
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 {
|
|
return time.Time(obj.(types.KLine).StartTime).UTC()
|
|
},
|
|
ID: func(obj interface{}) string {
|
|
kline := obj.(types.KLine)
|
|
return kline.StartTime.String()
|
|
},
|
|
}
|
|
|
|
c = make(chan types.KLine, 3000)
|
|
errC = query.Query(ctx, c, startTime, endTime)
|
|
return c, errC
|
|
}
|