mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
pull out .Subscribe from trader.Run
This commit is contained in:
parent
fca6115a0a
commit
a60aeb4771
|
@ -148,6 +148,8 @@ type ExchangeSession struct {
|
|||
|
||||
usedSymbols map[string]struct{}
|
||||
initializedSymbols map[string]struct{}
|
||||
|
||||
logger *log.Entry
|
||||
}
|
||||
|
||||
func NewExchangeSession(name string, exchange types.Exchange) *ExchangeSession {
|
||||
|
@ -174,6 +176,7 @@ func NewExchangeSession(name string, exchange types.Exchange) *ExchangeSession {
|
|||
orderStores: make(map[string]*OrderStore),
|
||||
usedSymbols: make(map[string]struct{}),
|
||||
initializedSymbols: make(map[string]struct{}),
|
||||
logger: log.WithField("session", name),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ func (trader *Trader) SetRiskControls(riskControls *RiskControls) {
|
|||
trader.riskControls = riskControls
|
||||
}
|
||||
|
||||
func (trader *Trader) Run(ctx context.Context) error {
|
||||
func (trader *Trader) Subscribe() {
|
||||
// pre-subscribe the data
|
||||
for sessionName, strategies := range trader.exchangeStrategies {
|
||||
session := trader.environment.sessions[sessionName]
|
||||
|
@ -143,7 +143,9 @@ func (trader *Trader) Run(ctx context.Context) error {
|
|||
subscriber.CrossSubscribe(trader.environment.sessions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (trader *Trader) Run(ctx context.Context) error {
|
||||
if err := trader.environment.Init(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -218,6 +218,8 @@ var BacktestCmd = &cobra.Command{
|
|||
log.Warnf("backtest does not support CrossExchangeStrategy, strategies won't be added.")
|
||||
}
|
||||
|
||||
trader.Subscribe()
|
||||
|
||||
if err := trader.Run(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -214,6 +214,8 @@ func runConfig(basectx context.Context, userConfig *bbgo.Config, enableApiServer
|
|||
}
|
||||
}
|
||||
|
||||
trader.Subscribe()
|
||||
|
||||
if err := trader.Run(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user