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.
54 lines
1.7 KiB
54 lines
1.7 KiB
package strategy |
|
|
|
import ( |
|
"sig-pub/pkg/indicator" |
|
"sig-pub/pkg/types" |
|
"sig-pub/pkg/types/series" |
|
) |
|
|
|
// ISigStrategy 交易信号策略接口(单周期单交易所) |
|
type ISigStrategy interface { |
|
New() ISigStrategy |
|
Meta() StrategyMeta |
|
Init(param StrategyParam) (err error) // 校验参数, 并根据参数初始化策略 |
|
} |
|
|
|
type StrategyMeta struct { |
|
Name string `json:"name"` |
|
Desc string `json:"desc"` |
|
Args []Param `json:"args"` // 参数定义 |
|
} |
|
|
|
// ISingleSigStrategy 单周期单交易所策略 |
|
type ISingleSigStrategy interface { |
|
ISigStrategy |
|
RequiredSeries() int16 // 需要的最小数据k线数, 回测时用, 若不定义则取最大窗口值 |
|
Update(ctx ISingleSigStrategyContext) (side types.Side) |
|
} |
|
|
|
// ISingleSigStrategyContext 策略上下文 |
|
type ISingleSigStrategyContext interface { |
|
// Get [0]当前k线 |
|
Get(offset int16) types.Kline |
|
// Series [offset...end] |
|
Series(offset, count int16) (klines series.Klines) |
|
// 获取窗口类型指标 |
|
IndicatorW(name string, window int16) indicator.IIndicatorSeries |
|
} |
|
|
|
// 多周期k线策略接口 |
|
type IIntervalSigStrategy interface { |
|
ISigStrategy |
|
RequiredIntervalSeries() (iss *types.IntervalState[int16]) // 需要的各周期最小数据k线数, 回测时用, 若不定义则取最大窗口值 |
|
Update(ctx IIntervalSigStrategyContext) (side types.Side) |
|
} |
|
|
|
// IIntervalSigStrategyContext 多周期策略上下文 |
|
type IIntervalSigStrategyContext interface { |
|
// Get [0]当前k线 |
|
Get(interval types.Interval, offset int16) types.Kline |
|
// Series [offset...end] |
|
Series(interval types.Interval, offset, count int16) (klines series.Klines) |
|
// 获取窗口类型指标 |
|
IndicatorW(interval types.Interval, name string, window int16) indicator.IIndicatorSeries |
|
}
|
|
|