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.
53 lines
1.2 KiB
53 lines
1.2 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.MustRegistIndicatorW(&RSI{}) |
|
r.MustRegistIndicatorW(&SMA{}) |
|
r.MustRegistIndicatorW(&ATR{}) |
|
r.MustRegistIndicatorW(&EMA{}) |
|
r.MustRegistIndicatorW(&MacdDIF{}) |
|
r.MustRegistIndicatorW(&MacdDEA{}) |
|
r.MustRegistIndicatorW(&Macd{}) |
|
r.MustRegistIndicatorW(&OBV{}) |
|
r.MustRegistIndicatorW(&WOBV{}) |
|
return |
|
} |
|
|
|
// RegistIndicatorW |
|
func (r *IndicatorRegistry) RegistIndicatorW(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) MustRegistIndicatorW(ind IIndicator) { |
|
if err := r.RegistIndicatorW(ind); err != nil { |
|
panic(err) |
|
} |
|
} |
|
|
|
// Indicator |
|
func (r *IndicatorRegistry) Indicator(name string) (indW IIndicator, ok bool) { |
|
return r.indicators.Load(name) |
|
}
|
|
|