add QueryLastFundingRate api to binance exchange

This commit is contained in:
c9s 2021-06-01 03:15:19 +08:00
parent c1e1c89cb0
commit b9584117d6

View File

@ -37,13 +37,17 @@ func init() {
type Exchange struct {
types.MarginSettings
Client *binance.Client
key, secret string
Client *binance.Client
}
func New(key, secret string) *Exchange {
var client = binance.NewClient(key, secret)
_, _ = client.NewSetServerTimeService().Do(context.Background())
return &Exchange{
key: key,
secret: secret,
Client: client,
}
}
@ -900,3 +904,20 @@ func (e *Exchange) BatchQueryKLines(ctx context.Context, symbol string, interval
return allKLines, nil
}
func (e *Exchange) QueryLastFundingRate(ctx context.Context, symbol string) (fixedpoint.Value, error) {
futuresClient := binance.NewFuturesClient(e.key, e.secret)
rates, err := futuresClient.NewFundingRateService().
Symbol(symbol).
Limit(1).
Do(ctx)
if err != nil {
return 0, err
}
if len(rates) == 0 {
return 0, errors.New("empty funding rate data")
}
return fixedpoint.NewFromString(rates[0].FundingRate)
}