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.
 
 

47 lines
1.1 KiB

package indicator
import (
"fmt"
"sig-pub/pkg/utils/collect"
)
// 指标注册器
type IndicatorRegistry struct {
indicatorsW *collect.SyncMap[string, IWindowIndicator] // 注册窗口指标
}
func NewIndicatorRegistry() *IndicatorRegistry {
return &IndicatorRegistry{
indicatorsW: collect.NewSyncMap[string, IWindowIndicator](),
}
}
func (r *IndicatorRegistry) Init() (err error) {
// indicator regist
r.MustRegistIndicatorW(&RSI{})
r.MustRegistIndicatorW(&SMA{})
r.MustRegistIndicatorW(&ATR{})
return
}
// RegistIndicatorW
func (r *IndicatorRegistry) RegistIndicatorW(ind IWindowIndicator) (err error) {
indName := ind.Name()
_, loaded := r.indicatorsW.LoadOrStore(indName, ind)
if loaded {
err = fmt.Errorf("window indicator name %s already duplicated", indName)
return
}
return
}
func (r *IndicatorRegistry) MustRegistIndicatorW(ind IWindowIndicator) {
if err := r.RegistIndicatorW(ind); err != nil {
panic(err)
}
}
// IndicatorW
func (r *IndicatorRegistry) IndicatorW(name string) (indW IWindowIndicator, ok bool) {
return r.indicatorsW.Load(name)
}