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.9 KiB
60 lines
1.9 KiB
package indicator |
|
|
|
import ( |
|
"sig-pub/pkg/types" |
|
"sig-pub/pkg/types/series" |
|
) |
|
|
|
const ( |
|
MaxWindow = 256 // 最大窗口引用大小 |
|
ApproCandles = 64 // 递归指标近似计算k线数 |
|
) |
|
|
|
type IndicatorMeta struct { |
|
Name string `json:"name"` // 指标名称 |
|
Desc string `json:"desc"` // 指标描述 |
|
Input []types.InputArg `json:"input"` // 输入参数 |
|
State []string `json:"state"` // 向外暴露状态 |
|
Plot Plot `json:"plot"` // 指标绘图属性 |
|
} |
|
|
|
// IIndicator 指标基础计算接口 |
|
type IIndicator interface { |
|
// Meta 指标元信息 |
|
Meta() IndicatorMeta |
|
// CandlePeriods 计算窗口大小的指标值需要的K线数量 |
|
CandlePeriods(ctx IIndicatorContext) int16 |
|
// Calculate 计算窗口大小的指标值 |
|
Calculate(ctx IIndicatorContext) (vector float64) |
|
} |
|
|
|
// IIndicatorContext k线序列, trading服务提供 |
|
type IIndicatorContext interface { |
|
Get(offset int16) (kline types.Kline) |
|
Series(offset, count int16) (klines series.Klines) |
|
// Input 获取输入参数 |
|
Input() types.Input |
|
// State 存储指标运行中状态 |
|
State() IIndicatorState |
|
// IndicatorW 获取其他指标 |
|
Indicator(name string, args ...any) (series IIndicatorSeries) |
|
} |
|
|
|
// IIndicatorSeries 指标序列, 供策略读取, trading服务提供 |
|
type IIndicatorSeries interface { |
|
CandlePeriods() int16 |
|
Get(offset int16) (vector float64) |
|
Series(offset, count int16) (matrix series.Floats) |
|
// 获取指标计算过程中的状态值 |
|
State(k string, offset int16) (state float64) |
|
StateSeries(k string, offset, count int16) (matrix series.Floats) |
|
} |
|
|
|
type IIndicatorState interface { |
|
// Set 存储指标当前状态 |
|
Set(k string, v float64) |
|
// Get 获取指标之前存储的状态 offset >= 1 |
|
Get(k string, offset int16) (v float64, ok bool) |
|
// Series 获取指标之前存储的状态序列 offset >= 1, count >= 1 |
|
Series(k string, offset, count int16) (v series.Floats, ok bool) |
|
}
|
|
|