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.
61 lines
1.4 KiB
61 lines
1.4 KiB
package trading |
|
|
|
import ( |
|
"fmt" |
|
"sig-pub/pkg/data/entity" |
|
"sig-pub/pkg/indicator" |
|
"sig-pub/pkg/publish" |
|
"sig-pub/pkg/strategy" |
|
) |
|
|
|
type TradingPlanRunner struct { |
|
plan entity.TradePlan |
|
indicatorReg indicator.IndicatorRegistry |
|
strategyReg strategy.SigStrategyRegistry |
|
publisher publish.Publisher[int32, any] |
|
} |
|
|
|
func NewTradingPlan(plan entity.TradePlan, |
|
indicatorReg indicator.IndicatorRegistry, |
|
strategyReg strategy.SigStrategyRegistry, |
|
) *TradingPlanRunner { |
|
return &TradingPlanRunner{ |
|
plan: plan, |
|
indicatorReg: indicatorReg, |
|
strategyReg: strategyReg, |
|
} |
|
} |
|
|
|
// Init 初始化交易计划 |
|
// subKlineKeys 订阅k线更新, 更新时调用Update方法 |
|
// 交易信号/下单/平仓/风控 |
|
func (r *TradingPlanRunner) Init() (subSignalKeyKeys []string, err error) { |
|
// 初始化执行策略 |
|
_, err = r.initSigStrategy(r.plan.SigStrategy, r.plan.SigStrategyParams) |
|
if err != nil { |
|
return |
|
} |
|
|
|
// sigStrategy 1m |
|
// tradeStrategy 1s |
|
// closeStrategy 2s |
|
return |
|
} |
|
|
|
// initSigStrategy 初始化多空信号策略 |
|
// buy/sell -> 过滤/风控 -> tradeStrategy -> closeStrategy |
|
func (r *TradingPlanRunner) initSigStrategy(name, params string) (subSignalKeyKeys []string, err error) { |
|
strategy, ok := r.strategyReg.NewSigStrategy(name) |
|
if !ok { |
|
err = fmt.Errorf("strategy not exists: %s", name) |
|
return |
|
} |
|
_ = strategy |
|
// strategy.Update() |
|
return |
|
} |
|
|
|
// Update 订阅k线更新 |
|
func (r *TradingPlanRunner) Update(signalKey string) { |
|
|
|
}
|
|
|