mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +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
|
||||
OrderService *service.OrderService
|
||||
TradeService *service.TradeService
|
||||
BacktestService *service.BacktestService
|
||||
RewardService *service.RewardService
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -250,7 +250,7 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
|
|||
session.Account.BindStream(session.Stream)
|
||||
|
||||
// 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) {
|
||||
if err := environ.TradeService.Insert(trade); err != nil {
|
||||
log.WithError(err).Errorf("trade insert error: %+v", trade)
|
||||
|
|
|
@ -120,6 +120,7 @@ var BacktestCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
backtestService := &service.BacktestService{DB: environ.DatabaseService.DB}
|
||||
environ.BacktestService = backtestService
|
||||
|
||||
if wantSync {
|
||||
var syncFromTime = startTime
|
||||
|
|
Loading…
Reference in New Issue
Block a user