mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
add QueryLastFundingRate api to binance exchange
This commit is contained in:
parent
c1e1c89cb0
commit
b9584117d6
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user