mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
pkg/exchange: add a jumpIfEmpty to batch trade option
This commit is contained in:
parent
7860bff379
commit
c611cfe73b
12
pkg/exchange/batch/option.go
Normal file
12
pkg/exchange/batch/option.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package batch
|
||||
|
||||
import "time"
|
||||
|
||||
type Option func(query *AsyncTimeRangedBatchQuery)
|
||||
|
||||
// JumpIfEmpty jump the startTime + duration when the result is empty
|
||||
func JumpIfEmpty(duration time.Duration) Option {
|
||||
return func(query *AsyncTimeRangedBatchQuery) {
|
||||
query.JumpIfEmpty = duration
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@ type TradeBatchQuery struct {
|
|||
types.ExchangeTradeHistoryService
|
||||
}
|
||||
|
||||
func (e TradeBatchQuery) Query(ctx context.Context, symbol string, options *types.TradeQueryOptions) (c chan types.Trade, errC chan error) {
|
||||
func (e TradeBatchQuery) Query(ctx context.Context, symbol string, options *types.TradeQueryOptions, opts ...Option) (c chan types.Trade, errC chan error) {
|
||||
if options.EndTime == nil {
|
||||
now := time.Now()
|
||||
options.EndTime = &now
|
||||
|
@ -45,6 +45,10 @@ func (e TradeBatchQuery) Query(ctx context.Context, symbol string, options *type
|
|||
JumpIfEmpty: 24 * time.Hour,
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
|
||||
c = make(chan types.Trade, 100)
|
||||
errC = query.Query(ctx, c, startTime, endTime)
|
||||
return c, errC
|
||||
|
|
Loading…
Reference in New Issue
Block a user