xfunding: pull out interval option

This commit is contained in:
c9s 2023-03-26 02:09:21 +08:00
parent 6349566ce9
commit ff35fd06c4
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -94,7 +94,9 @@ type Strategy struct {
Environment *bbgo.Environment Environment *bbgo.Environment
// These fields will be filled from the config file (it translates YAML to JSON) // 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:"-"` Market types.Market `json:"-"`
// Leverage is the leverage of the futures position // 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] spotSession := sessions[s.SpotSession]
futuresSession := sessions[s.FuturesSession] futuresSession := sessions[s.FuturesSession]
spotSession.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{ spotSession.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval})
Interval: types.Interval1m, futuresSession.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval})
})
futuresSession.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{
Interval: types.Interval1m,
})
} }
func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {} func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {}
@ -178,6 +175,10 @@ func (s *Strategy) Defaults() error {
s.MinHoldingPeriod = types.Duration(3 * 24 * time.Hour) s.MinHoldingPeriod = types.Duration(3 * 24 * time.Hour)
} }
if s.Interval == "" {
s.Interval = types.Interval1m
}
s.positionType = types.PositionShort s.positionType = types.PositionShort
return nil 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) s.queryAndDetectPremiumIndex(ctx, binanceFutures)
})) }))