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.
72 lines
2.0 KiB
72 lines
2.0 KiB
package sig |
|
|
|
import ( |
|
"sig-pub/pkg/data/entity" |
|
"sig-pub/pkg/indicator" |
|
"sig-pub/pkg/strategy" |
|
"sig-pub/pkg/types" |
|
"sync/atomic" |
|
) |
|
|
|
type TradingPlan struct { |
|
Status atomic.Int32 |
|
Plan entity.TradePlan |
|
indicatorReg *indicator.IndicatorRegistry |
|
|
|
sigStrategyType strategy.SigStrategyType |
|
sigStrategy strategy.ISigStrategy |
|
sigStrategyContext strategy.ISingleSigStrategyContext |
|
} |
|
|
|
func NewTradingPlan(plan entity.TradePlan, indicatorReg *indicator.IndicatorRegistry) *TradingPlan { |
|
return &TradingPlan{ |
|
Plan: plan, |
|
indicatorReg: indicatorReg, |
|
} |
|
} |
|
|
|
// Init 初始化交易计划 |
|
// subKlineKeys 订阅k线更新, 更新时调用Update方法 |
|
// 交易信号/下单/平仓/风控 |
|
func (r *TradingPlan) Init() (err error) { |
|
// 初始化执行策略 |
|
// if err = r.initSigStrategy(r.sigStrategy, r.plan.SigStrategyParams); err != nil { |
|
// return |
|
// } |
|
|
|
// sigStrategy 1m |
|
// tradeStrategy 1s |
|
// closeStrategy 2s |
|
return |
|
} |
|
|
|
// initSigStrategy 初始化多空信号策略 |
|
// buy/sell -> 过滤/风控 -> tradeStrategy -> closeStrategy |
|
func (r *TradingPlan) InitSigStrategy(sigStrategyType strategy.SigStrategyType, sigStrategy strategy.ISigStrategy, sigStrategyInput types.Input, sigStrategyContext strategy.ISingleSigStrategyContext) (err error) { |
|
if err = sigStrategy.Init(sigStrategyInput); err != nil { |
|
return |
|
} |
|
r.sigStrategyType = sigStrategyType |
|
r.sigStrategy = sigStrategy |
|
r.sigStrategyContext = sigStrategyContext |
|
return |
|
} |
|
|
|
func (r *TradingPlan) GetSigStrategy() strategy.ISigStrategy { |
|
return r.sigStrategy |
|
} |
|
|
|
// Update 订阅k线更新 |
|
// todo filted sigle |
|
func (r *TradingPlan) Update(signalType strategy.StrategyType) (side types.Side) { |
|
switch signalType { |
|
case strategy.StrategyTypeSig: |
|
switch r.sigStrategyType { |
|
case strategy.SigStrategyTypeSingle: |
|
return r.sigStrategy.(strategy.ISingleSigStrategy).Update(r.sigStrategyContext) |
|
case strategy.SigStrategyTypeInterval: |
|
return r.sigStrategy.(strategy.IIntervalSigStrategy).Update(nil) |
|
} |
|
} |
|
return |
|
}
|
|
|