diff --git a/pkg/bbgo/environment.go b/pkg/bbgo/environment.go index b6d3880d5..c4996af06 100644 --- a/pkg/bbgo/environment.go +++ b/pkg/bbgo/environment.go @@ -573,7 +573,35 @@ func (environ *Environment) Sync(ctx context.Context, userConfig ...*Config) err return nil } +func (environ *Environment) RecordPosition(position *types.Position, trade types.Trade, profit types.Profit) { + // skip for back-test + if environ.BacktestService != nil { + return + } + + if environ.DatabaseService == nil { + return + } + + if environ.ProfitService == nil { + return + } + + if err := environ.PositionService.Insert(position, trade, profit.Profit); err != nil { + log.WithError(err).Errorf("can not insert position record") + } + + if err := environ.ProfitService.Insert(profit); err != nil { + log.WithError(err).Errorf("can not insert profit record: %+v", profit) + } +} + func (environ *Environment) RecordProfit(profit types.Profit) { + // skip for back-test + if environ.BacktestService != nil { + return + } + if environ.DatabaseService == nil { return }