pkg/exchange: add a jumpIfEmpty to batch trade option

This commit is contained in:
Edwin 2023-10-25 21:30:54 +08:00
parent 7860bff379
commit c611cfe73b
2 changed files with 17 additions and 1 deletions

View 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
}
}

View File

@ -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