mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-13 02:23:51 +00:00
insert trades to db only when backtest service is nil
This commit is contained in:
parent
584a4c2ef8
commit
494a270c54
|
@ -68,6 +68,7 @@ type Environment struct {
|
||||||
DatabaseService *service.DatabaseService
|
DatabaseService *service.DatabaseService
|
||||||
OrderService *service.OrderService
|
OrderService *service.OrderService
|
||||||
TradeService *service.TradeService
|
TradeService *service.TradeService
|
||||||
|
BacktestService *service.BacktestService
|
||||||
RewardService *service.RewardService
|
RewardService *service.RewardService
|
||||||
SyncService *service.SyncService
|
SyncService *service.SyncService
|
||||||
|
|
||||||
|
@ -285,7 +286,7 @@ func (environ *Environment) Init(ctx context.Context) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := session.InitSymbols(ctx, environ) ; err != nil {
|
if err := session.InitSymbols(ctx, environ); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -250,7 +250,7 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
|
||||||
session.Account.BindStream(session.Stream)
|
session.Account.BindStream(session.Stream)
|
||||||
|
|
||||||
// insert trade into db right before everything
|
// insert trade into db right before everything
|
||||||
if environ.TradeService != nil {
|
if environ.TradeService != nil && environ.BacktestService == nil {
|
||||||
session.Stream.OnTradeUpdate(func(trade types.Trade) {
|
session.Stream.OnTradeUpdate(func(trade types.Trade) {
|
||||||
if err := environ.TradeService.Insert(trade); err != nil {
|
if err := environ.TradeService.Insert(trade); err != nil {
|
||||||
log.WithError(err).Errorf("trade insert error: %+v", trade)
|
log.WithError(err).Errorf("trade insert error: %+v", trade)
|
||||||
|
|
|
@ -120,6 +120,7 @@ var BacktestCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
backtestService := &service.BacktestService{DB: environ.DatabaseService.DB}
|
backtestService := &service.BacktestService{DB: environ.DatabaseService.DB}
|
||||||
|
environ.BacktestService = backtestService
|
||||||
|
|
||||||
if wantSync {
|
if wantSync {
|
||||||
var syncFromTime = startTime
|
var syncFromTime = startTime
|
||||||
|
|
Loading…
Reference in New Issue
Block a user