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,13 +164,17 @@ 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) {
|
||||||
|
if err := environ.TradeService.Insert(trade); err != nil {
|
||||||
|
log.WithError(err).Errorf("trade insert error: %+v", trade)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
session.Stream.OnTradeUpdate(func(trade types.Trade) {
|
session.Stream.OnTradeUpdate(func(trade types.Trade) {
|
||||||
// append trades
|
// append trades
|
||||||
session.Trades[trade.Symbol] = append(session.Trades[trade.Symbol], trade)
|
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
|
// move market data store dispatch to here, use one callback to dispatch the market data
|
||||||
|
|
|
@ -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()
|
||||||
|
|
||||||
db, err := cmdutil.ConnectMySQL()
|
if viper.IsSet("mysql-url") {
|
||||||
if err != nil {
|
db, err := cmdutil.ConnectMySQL()
|
||||||
return err
|
if err != nil {
|
||||||
|
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 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user