make mysql-url optional for run command

This commit is contained in:
c9s 2020-11-02 22:22:17 +08:00
parent f223940b69
commit eb67fc0f8f
2 changed files with 14 additions and 10 deletions

View File

@ -164,14 +164,18 @@ func (environ *Environment) Init(ctx context.Context) (err error) {
session.marketDataStores[kline.Symbol].AddKLine(kline) session.marketDataStores[kline.Symbol].AddKLine(kline)
}) })
if environ.TradeService != nil {
session.Stream.OnTradeUpdate(func(trade types.Trade) { session.Stream.OnTradeUpdate(func(trade types.Trade) {
// append trades
session.Trades[trade.Symbol] = append(session.Trades[trade.Symbol], trade)
if err := environ.TradeService.Insert(trade); err != nil { if err := environ.TradeService.Insert(trade); err != nil {
log.WithError(err).Errorf("trade insert error: %+v", trade) log.WithError(err).Errorf("trade insert error: %+v", trade)
} }
}) })
}
session.Stream.OnTradeUpdate(func(trade types.Trade) {
// append trades
session.Trades[trade.Symbol] = append(session.Trades[trade.Symbol], trade)
})
// move market data store dispatch to here, use one callback to dispatch the market data // move market data store dispatch to here, use one callback to dispatch the market data
// session.Stream.OnKLineClosed(func(kline types.KLine) { }) // session.Stream.OnKLineClosed(func(kline types.KLine) { })

View File

@ -65,11 +65,13 @@ func compileRunFile(filepath string, config *bbgo.Config) error {
func runConfig(ctx context.Context, userConfig *bbgo.Config) error { func runConfig(ctx context.Context, userConfig *bbgo.Config) error {
environ := bbgo.NewEnvironment() environ := bbgo.NewEnvironment()
if viper.IsSet("mysql-url") {
db, err := cmdutil.ConnectMySQL() db, err := cmdutil.ConnectMySQL()
if err != nil { if err != nil {
return err return err
} }
environ.SyncTrades(db) environ.SyncTrades(db)
}
if len(userConfig.Sessions) == 0 { if len(userConfig.Sessions) == 0 {
for _, n := range bbgo.SupportedExchanges { for _, n := range bbgo.SupportedExchanges {
@ -97,7 +99,6 @@ func runConfig(ctx context.Context, userConfig *bbgo.Config) error {
} }
} }
notification := bbgo.Notifiability{ notification := bbgo.Notifiability{
SymbolChannelRouter: bbgo.NewPatternChannelRouter(nil), SymbolChannelRouter: bbgo.NewPatternChannelRouter(nil),
SessionChannelRouter: bbgo.NewPatternChannelRouter(nil), SessionChannelRouter: bbgo.NewPatternChannelRouter(nil),
@ -125,7 +126,6 @@ func runConfig(ctx context.Context, userConfig *bbgo.Config) error {
environ.ConfigureNotification(userConfig.Notifications) environ.ConfigureNotification(userConfig.Notifications)
} }
trader := bbgo.NewTrader(environ) trader := bbgo.NewTrader(environ)
if userConfig.RiskControls != nil { if userConfig.RiskControls != nil {