qbtrade/pkg/exchange/batch/funding_fee.go

42 lines
1.3 KiB
Go
Raw Normal View History

2024-06-27 14:42:38 +00:00
package batch
import (
"context"
"time"
"golang.org/x/time/rate"
"git.qtrade.icu/lychiyu/qbtrade/pkg/exchange/binance/binanceapi"
"git.qtrade.icu/lychiyu/qbtrade/pkg/types"
)
type BinanceFuturesIncomeHistoryService interface {
QueryFuturesIncomeHistory(ctx context.Context, symbol string, incomeType binanceapi.FuturesIncomeType, startTime, endTime *time.Time) ([]binanceapi.FuturesIncome, error)
}
type BinanceFuturesIncomeBatchQuery struct {
BinanceFuturesIncomeHistoryService
}
func (e *BinanceFuturesIncomeBatchQuery) Query(ctx context.Context, symbol string, incomeType binanceapi.FuturesIncomeType, startTime, endTime time.Time) (c chan binanceapi.FuturesIncome, errC chan error) {
query := &AsyncTimeRangedBatchQuery{
Type: types.MarginInterest{},
Limiter: rate.NewLimiter(rate.Every(3*time.Second), 1),
JumpIfEmpty: time.Hour * 24 * 30,
Q: func(startTime, endTime time.Time) (interface{}, error) {
return e.QueryFuturesIncomeHistory(ctx, symbol, incomeType, &startTime, &endTime)
},
T: func(obj interface{}) time.Time {
return time.Time(obj.(binanceapi.FuturesIncome).Time)
},
ID: func(obj interface{}) string {
interest := obj.(binanceapi.FuturesIncome)
return interest.Time.String()
},
}
c = make(chan binanceapi.FuturesIncome, 100)
errC = query.Query(ctx, c, startTime, endTime)
return c, errC
}