From ff35fd06c4ea1c803b1d2930d7c585771c65e52a Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 26 Mar 2023 02:09:21 +0800 Subject: [PATCH] xfunding: pull out interval option --- pkg/strategy/xfunding/strategy.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/strategy/xfunding/strategy.go b/pkg/strategy/xfunding/strategy.go index 9d0d57279..3f32b1eac 100644 --- a/pkg/strategy/xfunding/strategy.go +++ b/pkg/strategy/xfunding/strategy.go @@ -94,7 +94,9 @@ type Strategy struct { Environment *bbgo.Environment // These fields will be filled from the config file (it translates YAML to JSON) - Symbol string `json:"symbol"` + Symbol string `json:"symbol"` + Interval types.Interval `json:"interval"` + Market types.Market `json:"-"` // Leverage is the leverage of the futures position @@ -158,13 +160,8 @@ func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession) { spotSession := sessions[s.SpotSession] futuresSession := sessions[s.FuturesSession] - spotSession.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{ - Interval: types.Interval1m, - }) - - futuresSession.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{ - Interval: types.Interval1m, - }) + spotSession.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval}) + futuresSession.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval}) } func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {} @@ -178,6 +175,10 @@ func (s *Strategy) Defaults() error { s.MinHoldingPeriod = types.Duration(3 * 24 * time.Hour) } + if s.Interval == "" { + s.Interval = types.Interval1m + } + s.positionType = types.PositionShort return nil @@ -364,7 +365,7 @@ func (s *Strategy) CrossRun(ctx context.Context, orderExecutionRouter bbgo.Order } }) - s.futuresSession.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, types.Interval1m, func(kline types.KLine) { + s.futuresSession.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, s.Interval, func(kline types.KLine) { s.queryAndDetectPremiumIndex(ctx, binanceFutures) }))