bbgo: rename standard indicator receiver name

This commit is contained in:
c9s 2022-07-26 17:57:42 +08:00
parent 46afc54559
commit 1d6b1de8ba
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -43,70 +43,70 @@ func NewStandardIndicatorSet(symbol string, stream types.Stream, store *MarketDa
} }
} }
func (set *StandardIndicatorSet) initAndBind(inc indicator.KLinePusher, iw types.IntervalWindow) { func (s *StandardIndicatorSet) initAndBind(inc indicator.KLinePusher, iw types.IntervalWindow) {
if klines, ok := set.store.KLinesOfInterval(iw.Interval); ok { if klines, ok := s.store.KLinesOfInterval(iw.Interval); ok {
for _, k := range *klines { for _, k := range *klines {
inc.PushK(k) inc.PushK(k)
} }
} }
set.stream.OnKLineClosed(types.KLineWith(set.Symbol, iw.Interval, inc.PushK)) s.stream.OnKLineClosed(types.KLineWith(s.Symbol, iw.Interval, inc.PushK))
} }
func (set *StandardIndicatorSet) allocateSimpleIndicator(t indicator.Simple, iw types.IntervalWindow) indicator.Simple { func (s *StandardIndicatorSet) allocateSimpleIndicator(t indicator.Simple, iw types.IntervalWindow) indicator.Simple {
inc, ok := set.simples[iw] inc, ok := s.simples[iw]
if ok { if ok {
return inc return inc
} }
inc = t inc = t
set.initAndBind(inc, iw) s.initAndBind(inc, iw)
set.simples[iw] = inc s.simples[iw] = inc
return t return t
} }
// SMA is a helper function that returns the simple moving average indicator of the given interval and the window size. // SMA is a helper function that returns the simple moving average indicator of the given interval and the window size.
func (set *StandardIndicatorSet) SMA(iw types.IntervalWindow) *indicator.SMA { func (s *StandardIndicatorSet) SMA(iw types.IntervalWindow) *indicator.SMA {
inc := set.allocateSimpleIndicator(&indicator.SMA{IntervalWindow: iw}, iw) inc := s.allocateSimpleIndicator(&indicator.SMA{IntervalWindow: iw}, iw)
return inc.(*indicator.SMA) return inc.(*indicator.SMA)
} }
// EWMA is a helper function that returns the exponential weighed moving average indicator of the given interval and the window size. // EWMA is a helper function that returns the exponential weighed moving average indicator of the given interval and the window size.
func (set *StandardIndicatorSet) EWMA(iw types.IntervalWindow) *indicator.EWMA { func (s *StandardIndicatorSet) EWMA(iw types.IntervalWindow) *indicator.EWMA {
inc := set.allocateSimpleIndicator(&indicator.EWMA{IntervalWindow: iw}, iw) inc := s.allocateSimpleIndicator(&indicator.EWMA{IntervalWindow: iw}, iw)
return inc.(*indicator.EWMA) return inc.(*indicator.EWMA)
} }
func (set *StandardIndicatorSet) PivotLow(iw types.IntervalWindow) *indicator.PivotLow { func (s *StandardIndicatorSet) PivotLow(iw types.IntervalWindow) *indicator.PivotLow {
inc := set.allocateSimpleIndicator(&indicator.PivotLow{IntervalWindow: iw}, iw) inc := s.allocateSimpleIndicator(&indicator.PivotLow{IntervalWindow: iw}, iw)
return inc.(*indicator.PivotLow) return inc.(*indicator.PivotLow)
} }
func (set *StandardIndicatorSet) STOCH(iw types.IntervalWindow) *indicator.STOCH { func (s *StandardIndicatorSet) STOCH(iw types.IntervalWindow) *indicator.STOCH {
inc, ok := set.stoch[iw] inc, ok := s.stoch[iw]
if !ok { if !ok {
inc = &indicator.STOCH{IntervalWindow: iw} inc = &indicator.STOCH{IntervalWindow: iw}
set.initAndBind(inc, iw) s.initAndBind(inc, iw)
set.stoch[iw] = inc s.stoch[iw] = inc
} }
return inc return inc
} }
// BOLL returns the bollinger band indicator of the given interval, the window and bandwidth // BOLL returns the bollinger band indicator of the given interval, the window and bandwidth
func (set *StandardIndicatorSet) BOLL(iw types.IntervalWindow, bandWidth float64) *indicator.BOLL { func (s *StandardIndicatorSet) BOLL(iw types.IntervalWindow, bandWidth float64) *indicator.BOLL {
iwb := types.IntervalWindowBandWidth{IntervalWindow: iw, BandWidth: bandWidth} iwb := types.IntervalWindowBandWidth{IntervalWindow: iw, BandWidth: bandWidth}
inc, ok := set.boll[iwb] inc, ok := s.boll[iwb]
if !ok { if !ok {
inc = &indicator.BOLL{IntervalWindow: iw, K: bandWidth} inc = &indicator.BOLL{IntervalWindow: iw, K: bandWidth}
set.initAndBind(inc, iw) s.initAndBind(inc, iw)
if debugBOLL { if debugBOLL {
inc.OnUpdate(func(sma float64, upBand float64, downBand float64) { inc.OnUpdate(func(sma float64, upBand float64, downBand float64) {
logrus.Infof("%s BOLL %s: sma=%f up=%f down=%f", set.Symbol, iw.String(), sma, upBand, downBand) logrus.Infof("%s BOLL %s: sma=%f up=%f down=%f", s.Symbol, iw.String(), sma, upBand, downBand)
}) })
} }
set.boll[iwb] = inc s.boll[iwb] = inc
} }
return inc return inc