batch: add funding fee batch query

This commit is contained in:
c9s 2023-03-26 00:53:29 +08:00
parent 12ec3fd87f
commit 265b69a0ee
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 50 additions and 3 deletions

View File

@ -0,0 +1,41 @@
package batch
import (
"context"
"time"
"golang.org/x/time/rate"
"github.com/c9s/bbgo/pkg/exchange/binance/binanceapi"
"github.com/c9s/bbgo/pkg/types"
)
type BinanceFuturesIncomeHistoryService interface {
QueryFuturesIncomeHistory(ctx context.Context, symbol string, incomeType binanceapi.FuturesIncomeType, startTime, endTime *time.Time) ([]binanceapi.FuturesIncome, error)
}
type FuturesFundingFeeBatchQuery struct {
BinanceFuturesIncomeHistoryService
}
func (e *FuturesFundingFeeBatchQuery) Query(ctx context.Context, symbol string, startTime, endTime time.Time) (c chan types.MarginInterest, 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, binanceapi.FuturesIncomeFundingFee, &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 types.MarginInterest, 100)
errC = query.Query(ctx, c, startTime, endTime)
return c, errC
}

View File

@ -369,12 +369,18 @@ func (e *Exchange) queryFuturesDepth(ctx context.Context, symbol string) (snapsh
// QueryFuturesIncomeHistory queries the income history on the binance futures account
// This is more binance futures specific API, the convert function is not designed yet.
// TODO: consider other futures platforms and design the common data structure for this
func (e *Exchange) QueryFuturesIncomeHistory(ctx context.Context, symbol string, incomeType binanceapi.FuturesIncomeType, startTime, endTime time.Time) ([]binanceapi.FuturesIncome, error) {
func (e *Exchange) QueryFuturesIncomeHistory(ctx context.Context, symbol string, incomeType binanceapi.FuturesIncomeType, startTime, endTime *time.Time) ([]binanceapi.FuturesIncome, error) {
req := e.futuresClient2.NewFuturesGetIncomeHistoryRequest()
req.Symbol(symbol)
req.IncomeType(incomeType)
req.StartTime(startTime)
req.EndTime(endTime)
if startTime != nil {
req.StartTime(*startTime)
}
if endTime != nil {
req.EndTime(*endTime)
}
resp, err := req.Do(ctx)
return resp, err
}