|
|
|
@ -14,11 +14,11 @@ type TradingService struct { |
|
|
|
marketClientAside *client.TradeInstanceAside |
|
|
|
marketClientAside *client.TradeInstanceAside |
|
|
|
exchangeClient pb.ExchangeServiceClient |
|
|
|
exchangeClient pb.ExchangeServiceClient |
|
|
|
|
|
|
|
|
|
|
|
klineStore *KlineStore |
|
|
|
klineStore *KlineStore |
|
|
|
windowIndicators *collect.SyncMap[string, indicator.IWindowIndicator] |
|
|
|
indicatorsW *collect.SyncMap[string, indicator.IWindowIndicator] // 注册窗口指标
|
|
|
|
strategies *collect.SyncMap[string, strategy.IStrategy] |
|
|
|
strategies *collect.SyncMap[string, strategy.ISigStrategy] // 注册信号策略
|
|
|
|
publisher publish.Publisher[int64, *TradingPlan] |
|
|
|
publisher publish.Publisher[int64, *TradingPlan] |
|
|
|
tradingPlan chan *TradingPlan |
|
|
|
tradingPlan chan *TradingPlan |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func NewTradingService( |
|
|
|
func NewTradingService( |
|
|
|
@ -29,7 +29,8 @@ func NewTradingService( |
|
|
|
marketClientAside: marketClientAside, |
|
|
|
marketClientAside: marketClientAside, |
|
|
|
exchangeClient: exchangeClient, |
|
|
|
exchangeClient: exchangeClient, |
|
|
|
klineStore: NewKlineSeriesStore(exchangeClient), |
|
|
|
klineStore: NewKlineSeriesStore(exchangeClient), |
|
|
|
windowIndicators: collect.NewSyncMap[string, indicator.IWindowIndicator](), |
|
|
|
indicatorsW: collect.NewSyncMap[string, indicator.IWindowIndicator](), |
|
|
|
|
|
|
|
strategies: collect.NewSyncMap[string, strategy.ISigStrategy](), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -55,7 +56,7 @@ func (svr *TradingService) Init() (err error) { |
|
|
|
// RegisterWindowIndicator
|
|
|
|
// RegisterWindowIndicator
|
|
|
|
func (svr *TradingService) RegisterWindowIndicator(ind indicator.IWindowIndicator) (err error) { |
|
|
|
func (svr *TradingService) RegisterWindowIndicator(ind indicator.IWindowIndicator) (err error) { |
|
|
|
indName := ind.Name() |
|
|
|
indName := ind.Name() |
|
|
|
_, loaded := svr.windowIndicators.LoadOrStore(indName, ind) |
|
|
|
_, loaded := svr.indicatorsW.LoadOrStore(indName, ind) |
|
|
|
if loaded { |
|
|
|
if loaded { |
|
|
|
err = fmt.Errorf("window indicator name %s already duplicated", indName) |
|
|
|
err = fmt.Errorf("window indicator name %s already duplicated", indName) |
|
|
|
return |
|
|
|
return |
|
|
|
@ -70,7 +71,7 @@ func (svr *TradingService) MustRegisterWindowIndicator(ind indicator.IWindowIndi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// RegisterStrategy
|
|
|
|
// RegisterStrategy
|
|
|
|
func (svr *TradingService) RegisterStrategy(strategy strategy.IStrategy) (err error) { |
|
|
|
func (svr *TradingService) RegisterStrategy(strategy strategy.ISigStrategy) (err error) { |
|
|
|
strategyName := strategy.Meta().Name |
|
|
|
strategyName := strategy.Meta().Name |
|
|
|
_, loaded := svr.strategies.LoadOrStore(strategyName, strategy) |
|
|
|
_, loaded := svr.strategies.LoadOrStore(strategyName, strategy) |
|
|
|
if loaded { |
|
|
|
if loaded { |
|
|
|
@ -80,7 +81,7 @@ func (svr *TradingService) RegisterStrategy(strategy strategy.IStrategy) (err er |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (svr *TradingService) MustRegisterStrategy(strategy strategy.IStrategy) { |
|
|
|
func (svr *TradingService) MustRegisterStrategy(strategy strategy.ISigStrategy) { |
|
|
|
if err := svr.RegisterStrategy(strategy); err != nil { |
|
|
|
if err := svr.RegisterStrategy(strategy); err != nil { |
|
|
|
panic(err) |
|
|
|
panic(err) |
|
|
|
} |
|
|
|
} |
|
|
|
|