bbgo_origin/pkg/exchange/batch/trade.go

44 lines
1004 B
Go
Raw Normal View History

2021-12-31 05:52:16 +00:00
package batch
import (
"context"
"time"
"github.com/c9s/bbgo/pkg/types"
)
2022-05-30 16:59:33 +00:00
var closedErrChan = make(chan error)
func init() {
close(closedErrChan)
}
2021-12-31 05:52:16 +00:00
type TradeBatchQuery struct {
2022-05-30 16:59:33 +00:00
types.ExchangeTradeHistoryService
2021-12-31 05:52:16 +00:00
}
func (e TradeBatchQuery) Query(ctx context.Context, symbol string, options *types.TradeQueryOptions) (c chan types.Trade, errC chan error) {
2022-05-30 16:59:33 +00:00
startTime := *options.StartTime
endTime := *options.EndTime
query := &AsyncTimeRangedBatchQuery{
Type: types.Trade{},
2022-05-30 16:59:33 +00:00
Q: func(startTime, endTime time.Time) (interface{}, error) {
return e.ExchangeTradeHistoryService.QueryTrades(ctx, symbol, options)
},
T: func(obj interface{}) time.Time {
return time.Time(obj.(types.Trade).Time)
},
ID: func(obj interface{}) string {
trade := obj.(types.Trade)
if trade.ID > options.LastTradeID {
options.LastTradeID = trade.ID
2021-12-31 05:52:16 +00:00
}
2022-05-30 16:59:33 +00:00
return trade.Key().String()
},
}
2021-12-31 05:52:16 +00:00
2022-05-30 16:59:33 +00:00
c = make(chan types.Trade, 100)
errC = query.Query(ctx, c, startTime, endTime)
2021-12-31 05:52:16 +00:00
return c, errC
}