You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.4 KiB
60 lines
1.4 KiB
package indicator |
|
|
|
import ( |
|
"fmt" |
|
"sig-pub/pkg/utils/collect" |
|
) |
|
|
|
// 指标注册器 |
|
type IndicatorRegistry struct { |
|
indicators *collect.SyncMap[string, IIndicator] // 注册窗口指标 |
|
} |
|
|
|
func NewIndicatorRegistry() *IndicatorRegistry { |
|
return &IndicatorRegistry{ |
|
indicators: collect.NewSyncMap[string, IIndicator](), |
|
} |
|
} |
|
|
|
func (r *IndicatorRegistry) Init() (err error) { |
|
// indicator regist |
|
r.MustRegistIndicator(&RSI{}) |
|
r.MustRegistIndicator(&SMA{}) |
|
r.MustRegistIndicator(&ATR{}) |
|
r.MustRegistIndicator(&EMA{}) |
|
r.MustRegistIndicator(&MACD{}) |
|
r.MustRegistIndicator(&OBV{}) |
|
r.MustRegistIndicator(&WOBV{}) |
|
r.MustRegistIndicator(&BOLL{}) |
|
r.MustRegistIndicator(&SuperTrend{}) |
|
r.MustRegistIndicator(&ADX{}) |
|
r.MustRegistIndicator(&KDJ{}) |
|
r.MustRegistIndicator(&RVI{}) |
|
return |
|
} |
|
|
|
// RegistIndicator |
|
func (r *IndicatorRegistry) RegistIndicator(ind IIndicator) (err error) { |
|
indName := ind.Meta().Name |
|
_, loaded := r.indicators.LoadOrStore(indName, ind) |
|
if loaded { |
|
err = fmt.Errorf("window indicator name %s already duplicated", indName) |
|
return |
|
} |
|
return |
|
} |
|
|
|
func (r *IndicatorRegistry) MustRegistIndicator(ind IIndicator) { |
|
if err := r.RegistIndicator(ind); err != nil { |
|
panic(err) |
|
} |
|
} |
|
|
|
// Indicator |
|
func (r *IndicatorRegistry) Indicator(name string) (indW IIndicator, ok bool) { |
|
return r.indicators.Load(name) |
|
} |
|
|
|
func (r *IndicatorRegistry) RangeIndicators(fn func(k string, v IIndicator) bool) { |
|
r.indicators.Range(fn) |
|
}
|
|
|