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.
50 lines
1.5 KiB
50 lines
1.5 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" |
|
) |
|
|
|
// ISigStrategy 交易信号策略接口(单周期单交易所) |
|
type ISigStrategy interface { |
|
New() ISigStrategy |
|
Meta() StrategyMeta |
|
Init(param SigStrategyParam) (err error) // 校验参数, 并根据参数初始化策略 |
|
Update(ctx ISigStrategyContext) |
|
} |
|
|
|
type StrategyMeta struct { |
|
Name string `json:"name"` |
|
Desc string `json:"desc"` |
|
Args []Param `json:"args"` // 参数定义 |
|
} |
|
|
|
// ISigStrategyContext 策略外部访问能力 |
|
// klineSeries, Indicator |
|
type ISigStrategyContext 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 int16) indicator.IIndicatorSeries |
|
} |
|
|
|
// DriverIntervalKey 生成周期驱动事件key |
|
// interval/BTC_USDT/OKX,BINANCE/1m,3m,5m |
|
func DriverIntervalKey(instId string, intervals []types.Interval, exchanges ...pb.ExchangeType) string { |
|
types.IntervalsSort(intervals) |
|
types.ExchangesSort(exchanges) |
|
strIntervals := collect.Mapping(intervals, func(_ int, interval types.Interval) string { return string(interval) }) |
|
strExchanges := collect.Mapping(exchanges, func(_ int, exchange pb.ExchangeType) string { return exchange.String() }) |
|
pubKey := fmt.Sprintf("/interval/%s/%s/%s", instId, strings.Join(strExchanges, ","), strings.Join(strIntervals, ",")) |
|
return pubKey |
|
}
|
|
|