insert trades to db only when backtest service is nil

This commit is contained in:
c9s 2021-05-07 01:50:38 +08:00
parent 584a4c2ef8
commit 494a270c54
3 changed files with 4 additions and 2 deletions

View File

@ -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
}

View File

@ -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)

View File

@ -120,6 +120,7 @@ var BacktestCmd = &cobra.Command{
}
backtestService := &service.BacktestService{DB: environ.DatabaseService.DB}
environ.BacktestService = backtestService
if wantSync {
var syncFromTime = startTime