mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
bbgo: add SetTradeScanTime method
This commit is contained in:
parent
3b3df77ec3
commit
a08aebaa17
|
@ -22,6 +22,7 @@ type Environment struct {
|
||||||
TradeService *service.TradeService
|
TradeService *service.TradeService
|
||||||
TradeSync *service.TradeSync
|
TradeSync *service.TradeSync
|
||||||
|
|
||||||
|
tradeScanTime time.Time
|
||||||
sessions map[string]*ExchangeSession
|
sessions map[string]*ExchangeSession
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +50,7 @@ func NewEnvironment(db *sqlx.DB) *Environment {
|
||||||
TradeSync: &service.TradeSync{
|
TradeSync: &service.TradeSync{
|
||||||
Service: tradeService,
|
Service: tradeService,
|
||||||
},
|
},
|
||||||
|
tradeScanTime: time.Now().AddDate(0, 0, -7), // sync from 7 days ago
|
||||||
sessions: make(map[string]*ExchangeSession),
|
sessions: make(map[string]*ExchangeSession),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,9 +84,14 @@ func (environ *Environment) Init(ctx context.Context) (err error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetTradeScanTime overrides the default trade scan time (-7 days)
|
||||||
|
func (environ *Environment) SetTradeScanTime(t time.Time) *Environment {
|
||||||
|
environ.tradeScanTime = t
|
||||||
|
return environ
|
||||||
|
}
|
||||||
|
|
||||||
func (environ *Environment) Connect(ctx context.Context) error {
|
func (environ *Environment) Connect(ctx context.Context) error {
|
||||||
var err error
|
var err error
|
||||||
var startTime = time.Now().AddDate(0, 0, -7) // sync from 7 days ago
|
|
||||||
|
|
||||||
for n := range environ.sessions {
|
for n := range environ.sessions {
|
||||||
// avoid using the placeholder variable for the session because we use that in the callbacks
|
// avoid using the placeholder variable for the session because we use that in the callbacks
|
||||||
|
@ -103,7 +110,7 @@ func (environ *Environment) Connect(ctx context.Context) error {
|
||||||
// trade sync and market data store depends on subscribed symbols so we have to do this here.
|
// trade sync and market data store depends on subscribed symbols so we have to do this here.
|
||||||
for symbol := range loadedSymbols {
|
for symbol := range loadedSymbols {
|
||||||
log.Infof("syncing trades from %s for symbol %s...", session.Exchange.Name(), symbol)
|
log.Infof("syncing trades from %s for symbol %s...", session.Exchange.Name(), symbol)
|
||||||
if err := environ.TradeSync.Sync(ctx, session.Exchange, symbol, startTime); err != nil {
|
if err := environ.TradeSync.Sync(ctx, session.Exchange, symbol, environ.tradeScanTime); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user