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