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,13 +164,17 @@ func (environ *Environment) Init(ctx context.Context) (err error) {
session.marketDataStores[kline.Symbol].AddKLine(kline)
})
if environ.TradeService != nil {
session.Stream.OnTradeUpdate(func(trade types.Trade) {
if err := environ.TradeService.Insert(trade); err != nil {
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)
if err := environ.TradeService.Insert(trade); err != nil {
log.WithError(err).Errorf("trade insert error: %+v", trade)
}
})
// move market data store dispatch to here, use one callback to dispatch the market data

View File

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