mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-24 15:55:14 +00:00
make mysql-url optional for run command
This commit is contained in:
parent
f223940b69
commit
eb67fc0f8f
|
@ -164,14 +164,18 @@ 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) {
|
||||
// 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
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
|
||||
// session.Stream.OnKLineClosed(func(kline types.KLine) { })
|
||||
|
|
|
@ -65,11 +65,13 @@ func compileRunFile(filepath string, config *bbgo.Config) error {
|
|||
func runConfig(ctx context.Context, userConfig *bbgo.Config) error {
|
||||
environ := bbgo.NewEnvironment()
|
||||
|
||||
if viper.IsSet("mysql-url") {
|
||||
db, err := cmdutil.ConnectMySQL()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user