bbgo: add RecordPosition method

This commit is contained in:
c9s 2022-03-11 16:23:34 +08:00
parent 9faaed6892
commit 6088f7b542

View File

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