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.9 KiB
50 lines
1.9 KiB
package strategy |
|
|
|
import ( |
|
"fmt" |
|
"sig-pub/api/pb" |
|
"sig-pub/pkg/types" |
|
"sig-pub/pkg/utils/collect" |
|
"sig-pub/pkg/utils/lang" |
|
"strings" |
|
) |
|
|
|
type SigStrategyType int32 |
|
|
|
const ( |
|
_ SigStrategyType = iota |
|
SigStrategyTypeSingle // 单周期策略 |
|
SigStrategyTypeInterval // 多周期策略 |
|
SigStrategyTypeInstance // 多币种策略 |
|
SigStrategyTypeInstanceInterval // 多币种多周期策略 |
|
) |
|
|
|
type StrategyType int32 |
|
|
|
const ( |
|
_ StrategyType = iota |
|
StrategyTypeSig // 交易信号策略 |
|
StrategyTypeTrade // 交易下单策略 |
|
StrategyTypeClose // 交易平仓策略 |
|
) |
|
|
|
// DriverIntervalKey 生成周期驱动事件key |
|
// interval/BTC_USDT/OKX/1m,3m,5m/1 |
|
// completed 同一时刻的所有其他周期都完成 |
|
func DriverIntervalKey(instId string, exchange pb.ExchangeType, completed bool, intervals ...types.Interval) string { |
|
types.IntervalsSort(intervals) |
|
strIntervals := collect.Mapping0(intervals, func(_ int, interval types.Interval) string { return string(interval) }) |
|
pubKey := fmt.Sprintf("/interval/%s/%s/%s/%d", instId, exchange.String(), strings.Join(strIntervals, ","), lang.Ternary(completed, 1, 0)) |
|
return pubKey |
|
} |
|
|
|
// DriverIntervalKey 生成周期驱动事件key |
|
// interval/BTC_USDT/OKX,BINANCE/1m,3m,5m |
|
func MulExchangeDriverIntervalKey(instId string, exchanges []pb.ExchangeType, intervals ...types.Interval) string { |
|
types.IntervalsSort(intervals) |
|
types.ExchangesSort(exchanges) |
|
strIntervals := collect.Mapping0(intervals, func(_ int, interval types.Interval) string { return string(interval) }) |
|
strExchanges := collect.Mapping0(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 |
|
}
|
|
|