mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
pull out db parameter from the constructor
This commit is contained in:
parent
3aa40f3aab
commit
cd666fdf9e
|
@ -89,8 +89,8 @@ type Environment struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDefaultEnvironment prepares the exchange sessions from the viper settings.
|
// NewDefaultEnvironment prepares the exchange sessions from the viper settings.
|
||||||
func NewDefaultEnvironment(db *sqlx.DB) *Environment {
|
func NewDefaultEnvironment() *Environment {
|
||||||
environment := NewEnvironment(db)
|
environment := NewEnvironment()
|
||||||
|
|
||||||
for _, n := range SupportedExchanges {
|
for _, n := range SupportedExchanges {
|
||||||
if viper.IsSet(string(n) + "-api-key") {
|
if viper.IsSet(string(n) + "-api-key") {
|
||||||
|
@ -106,14 +106,8 @@ func NewDefaultEnvironment(db *sqlx.DB) *Environment {
|
||||||
return environment
|
return environment
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEnvironment(db *sqlx.DB) *Environment {
|
func NewEnvironment() *Environment {
|
||||||
tradeService := &service.TradeService{DB: db}
|
|
||||||
return &Environment{
|
return &Environment{
|
||||||
TradeService: tradeService,
|
|
||||||
TradeSync: &service.TradeSync{
|
|
||||||
Service: tradeService,
|
|
||||||
},
|
|
||||||
|
|
||||||
// default trade scan time
|
// default trade scan time
|
||||||
tradeScanTime: time.Now().AddDate(0, 0, -7), // sync from 7 days ago
|
tradeScanTime: time.Now().AddDate(0, 0, -7), // sync from 7 days ago
|
||||||
sessions: make(map[string]*ExchangeSession),
|
sessions: make(map[string]*ExchangeSession),
|
||||||
|
|
|
@ -56,7 +56,7 @@ func TestEnvironment_Connect(t *testing.T) {
|
||||||
xdb, err := sqlx.Connect("mysql", mysqlURL)
|
xdb, err := sqlx.Connect("mysql", mysqlURL)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
environment := NewEnvironment(xdb)
|
environment := NewEnvironment()
|
||||||
environment.AddExchange("binance", exchange).
|
environment.AddExchange("binance", exchange).
|
||||||
Subscribe(types.KLineChannel,"BTCUSDT", types.SubscribeOptions{})
|
Subscribe(types.KLineChannel,"BTCUSDT", types.SubscribeOptions{})
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,8 @@ func runConfig(ctx context.Context, config *config.Config) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
environ := bbgo.NewDefaultEnvironment(db)
|
environ := bbgo.NewDefaultEnvironment()
|
||||||
|
environ.SyncTrades(db)
|
||||||
environ.ReportTrade(notifierSet)
|
environ.ReportTrade(notifierSet)
|
||||||
|
|
||||||
trader := bbgo.NewTrader(environ)
|
trader := bbgo.NewTrader(environ)
|
||||||
|
|
|
@ -61,7 +61,8 @@ var Cmd = &cobra.Command{
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
environ := bbgo.NewDefaultEnvironment(db)
|
environ := bbgo.NewDefaultEnvironment()
|
||||||
|
environ.SyncTrades(db)
|
||||||
trader := bbgo.NewTrader(environ)
|
trader := bbgo.NewTrader(environ)
|
||||||
trader.AttachStrategyOn(string(exchangeName), New(symbol, interval, baseQuantity))
|
trader.AttachStrategyOn(string(exchangeName), New(symbol, interval, baseQuantity))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user