move convertPremiumIndex to convert.go

This commit is contained in:
c9s 2021-12-09 00:08:25 +08:00
parent fbae368e6c
commit 71e043e4b2
2 changed files with 23 additions and 23 deletions

View File

@ -7,6 +7,7 @@ import (
"time"
"github.com/adshao/go-binance/v2"
"github.com/adshao/go-binance/v2/futures"
"github.com/pkg/errors"
"github.com/c9s/bbgo/pkg/fixedpoint"
@ -341,4 +342,26 @@ func convertSubscription(s types.Subscription) string {
return fmt.Sprintf("%s@%s", strings.ToLower(s.Symbol), s.Channel)
}
func convertPremiumIndex(index *futures.PremiumIndex) (*PremiumIndex, error) {
markPrice, err := fixedpoint.NewFromString(index.MarkPrice)
if err != nil {
return nil, err
}
lastFundingRate, err := fixedpoint.NewFromString(index.LastFundingRate)
if err != nil {
return nil, err
}
nextFundingTime := time.Unix(0, index.NextFundingTime*int64(time.Millisecond))
t := time.Unix(0, index.Time*int64(time.Millisecond))
return &PremiumIndex{
Symbol: index.Symbol,
MarkPrice: markPrice,
NextFundingTime: nextFundingTime,
LastFundingRate: lastFundingRate,
Time: t,
}, nil
}

View File

@ -9,7 +9,6 @@ import (
"strings"
"time"
"github.com/adshao/go-binance/v2/futures"
"golang.org/x/time/rate"
"github.com/adshao/go-binance/v2"
@ -900,28 +899,6 @@ type PremiumIndex struct {
Time time.Time `json:"time"`
}
func convertPremiumIndex(index *futures.PremiumIndex) (*PremiumIndex, error) {
markPrice, err := fixedpoint.NewFromString(index.MarkPrice)
if err != nil {
return nil, err
}
lastFundingRate, err := fixedpoint.NewFromString(index.LastFundingRate)
if err != nil {
return nil, err
}
nextFundingTime := time.Unix(0, index.NextFundingTime*int64(time.Millisecond))
t := time.Unix(0, index.Time*int64(time.Millisecond))
return &PremiumIndex{
Symbol: index.Symbol,
MarkPrice: markPrice,
NextFundingTime: nextFundingTime,
LastFundingRate: lastFundingRate,
Time: t,
}, nil
}
func (e *Exchange) QueryPremiumIndex(ctx context.Context, symbol string) (*PremiumIndex, error) {
futuresClient := binance.NewFuturesClient(e.key, e.secret)