mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
batch: add funding fee batch query
This commit is contained in:
parent
12ec3fd87f
commit
265b69a0ee
41
pkg/exchange/batch/funding_fee.go
Normal file
41
pkg/exchange/batch/funding_fee.go
Normal 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
|
||||||
|
}
|
|
@ -369,12 +369,18 @@ func (e *Exchange) queryFuturesDepth(ctx context.Context, symbol string) (snapsh
|
||||||
// QueryFuturesIncomeHistory queries the income history on the binance futures account
|
// QueryFuturesIncomeHistory queries the income history on the binance futures account
|
||||||
// This is more binance futures specific API, the convert function is not designed yet.
|
// 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
|
// 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 := e.futuresClient2.NewFuturesGetIncomeHistoryRequest()
|
||||||
req.Symbol(symbol)
|
req.Symbol(symbol)
|
||||||
req.IncomeType(incomeType)
|
req.IncomeType(incomeType)
|
||||||
req.StartTime(startTime)
|
if startTime != nil {
|
||||||
req.EndTime(endTime)
|
req.StartTime(*startTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
if endTime != nil {
|
||||||
|
req.EndTime(*endTime)
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := req.Do(ctx)
|
resp, err := req.Do(ctx)
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user