diff --git a/pkg/exchange/binance/convert.go b/pkg/exchange/binance/convert.go index bb6a09a92..0385ac338 100644 --- a/pkg/exchange/binance/convert.go +++ b/pkg/exchange/binance/convert.go @@ -342,7 +342,7 @@ func convertSubscription(s types.Subscription) string { return fmt.Sprintf("%s@%s", strings.ToLower(s.Symbol), s.Channel) } -func convertPremiumIndex(index *futures.PremiumIndex) (*PremiumIndex, error) { +func convertPremiumIndex(index *futures.PremiumIndex) (*types.PremiumIndex, error) { markPrice, err := fixedpoint.NewFromString(index.MarkPrice) if err != nil { return nil, err @@ -356,7 +356,7 @@ func convertPremiumIndex(index *futures.PremiumIndex) (*PremiumIndex, error) { nextFundingTime := time.Unix(0, index.NextFundingTime*int64(time.Millisecond)) t := time.Unix(0, index.Time*int64(time.Millisecond)) - return &PremiumIndex{ + return &types.PremiumIndex{ Symbol: index.Symbol, MarkPrice: markPrice, NextFundingTime: nextFundingTime, diff --git a/pkg/exchange/binance/exchange.go b/pkg/exchange/binance/exchange.go index 3caaba14a..e136dd12b 100644 --- a/pkg/exchange/binance/exchange.go +++ b/pkg/exchange/binance/exchange.go @@ -885,22 +885,7 @@ func (e *Exchange) BatchQueryKLines(ctx context.Context, symbol string, interval return allKLines, nil } -type FundingRate struct { - FundingRate fixedpoint.Value - FundingTime time.Time - Time time.Time -} - -type PremiumIndex struct { - Symbol string `json:"symbol"` - MarkPrice fixedpoint.Value `json:"markPrice"` - LastFundingRate fixedpoint.Value `json:"lastFundingRate"` - NextFundingTime time.Time `json:"nextFundingTime"` - Time time.Time `json:"time"` -} - - -func (e *Exchange) QueryPremiumIndex(ctx context.Context, symbol string) (*PremiumIndex, error) { +func (e *Exchange) QueryPremiumIndex(ctx context.Context, symbol string) (*types.PremiumIndex, error) { futuresClient := binance.NewFuturesClient(e.key, e.secret) // when symbol is set, only one index will be returned. @@ -912,7 +897,7 @@ func (e *Exchange) QueryPremiumIndex(ctx context.Context, symbol string) (*Premi return convertPremiumIndex(indexes[0]) } -func (e *Exchange) QueryFundingRateHistory(ctx context.Context, symbol string) (*FundingRate, error) { +func (e *Exchange) QueryFundingRateHistory(ctx context.Context, symbol string) (*types.FundingRate, error) { futuresClient := binance.NewFuturesClient(e.key, e.secret) rates, err := futuresClient.NewFundingRateService(). Symbol(symbol). @@ -932,7 +917,7 @@ func (e *Exchange) QueryFundingRateHistory(ctx context.Context, symbol string) ( return nil, err } - return &FundingRate{ + return &types.FundingRate{ FundingRate: fundingRate, FundingTime: time.Unix(0, rate.FundingTime*int64(time.Millisecond)), Time: time.Unix(0, rate.Time*int64(time.Millisecond)), diff --git a/pkg/strategy/techsignal/strategy.go b/pkg/strategy/techsignal/strategy.go index 6f6d4d2fe..53c23d56e 100644 --- a/pkg/strategy/techsignal/strategy.go +++ b/pkg/strategy/techsignal/strategy.go @@ -4,13 +4,14 @@ import ( "context" "errors" "fmt" - "github.com/c9s/bbgo/pkg/exchange/binance" - "github.com/c9s/bbgo/pkg/fixedpoint" - "github.com/sirupsen/logrus" "math" "strings" "time" + "github.com/c9s/bbgo/pkg/exchange/binance" + "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/sirupsen/logrus" + "github.com/c9s/bbgo/pkg/bbgo" "github.com/c9s/bbgo/pkg/types" ) @@ -87,7 +88,7 @@ func (s *Strategy) Validate() error { } func (s *Strategy) listenToFundingRate(ctx context.Context, exchange *binance.Exchange) { - var previousIndex, fundingRate24HoursLowIndex *binance.PremiumIndex + var previousIndex, fundingRate24HoursLowIndex *types.PremiumIndex fundingRateTicker := time.NewTicker(1 * time.Hour) defer fundingRateTicker.Stop() diff --git a/pkg/types/fundingrate.go b/pkg/types/fundingrate.go new file mode 100644 index 000000000..3b99bc739 --- /dev/null +++ b/pkg/types/fundingrate.go @@ -0,0 +1,13 @@ +package types + +import ( + "time" + + "github.com/c9s/bbgo/pkg/fixedpoint" +) + +type FundingRate struct { + FundingRate fixedpoint.Value + FundingTime time.Time + Time time.Time +} diff --git a/pkg/types/premiumindex.go b/pkg/types/premiumindex.go new file mode 100644 index 000000000..c9ffcd0aa --- /dev/null +++ b/pkg/types/premiumindex.go @@ -0,0 +1,15 @@ +package types + +import ( + "time" + + "github.com/c9s/bbgo/pkg/fixedpoint" +) + +type PremiumIndex struct { + Symbol string `json:"symbol"` + MarkPrice fixedpoint.Value `json:"markPrice"` + LastFundingRate fixedpoint.Value `json:"lastFundingRate"` + NextFundingTime time.Time `json:"nextFundingTime"` + Time time.Time `json:"time"` +}