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.
 
 

55 lines
1.6 KiB

package strategy
import (
"fmt"
"sig-pub/api/pb"
"sig-pub/pkg/indicator"
"sig-pub/pkg/types"
"sig-pub/pkg/types/series"
"sig-pub/pkg/utils/collect"
"strings"
)
// todo Exit 止盈止损策略(trading service 管理)
type IStrategy interface {
New() IStrategy
Meta() StrategyMeta
Update(ctx IStrategyContext)
}
// todo Meta 策略调参, 回测引擎自动调参回测(最佳参数) argGenerator.next() (arg, ok)
type IStrategyAdjustable interface {
IStrategy
NextParams() map[string]any // 根据当前策略参数, 返回下一批策略参数(并行回测 stateless)
AdjustParams(map[string]any) // 重置策略设置策略参数
}
type StrategyMeta struct {
// Id string `json:"id"` // 策略注册/执行器系统分配
Name string
Desc string
}
// IStrategyContext 策略外部访问能力
// klineSeries, Indicator
type IStrategyContext interface {
Buy() // 发出多信号
Sell() // 发出空信号
// Get [0]当前k线
Get(offset int16) types.Kline
// Series [offset...end]
Series(offset, count int16) (klines series.Klines)
// 获取窗口类型指标
IndicatorW(name string, window int) indicator.IIndicatorSeries
}
// DriverIntervalKey 生成周期驱动事件key
// interval/okx/BTC_USDT/1m,3m,5m
func DriverIntervalKey(exchangeType pb.ExchangeType, instId string, intervals ...types.Interval) string {
types.IntervalsSort(intervals)
strIntervals := collect.Mapping(intervals, func(_ int, interval types.Interval) string { return string(interval) })
pubKey := fmt.Sprintf("/interval/%s/%s/%s", exchangeType.String(), instId, strings.Join(strIntervals, ","))
return pubKey
}