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