diff --git a/pkg/bbgo/environment.go b/pkg/bbgo/environment.go index e94e1251f..44f02b9ae 100644 --- a/pkg/bbgo/environment.go +++ b/pkg/bbgo/environment.go @@ -587,7 +587,7 @@ func (environ *Environment) RecordPosition(position *types.Position, trade types log.Infof("recordPosition: position = %s, trade = %+v, profit = %+v", position.Base.String(), trade, profit) if profit != nil { - if err := environ.PositionService.Insert(position, trade, profit.Profit); err != nil { + if err := environ.PositionService.Insert(position, trade, profit.Profit, profit.NetProfit); err != nil { log.WithError(err).Errorf("can not insert position record") } @@ -595,7 +595,7 @@ func (environ *Environment) RecordPosition(position *types.Position, trade types log.WithError(err).Errorf("can not insert profit record: %+v", profit) } } else { - if err := environ.PositionService.Insert(position, trade, fixedpoint.Zero); err != nil { + if err := environ.PositionService.Insert(position, trade, fixedpoint.Zero, fixedpoint.Zero); err != nil { log.WithError(err).Errorf("can not insert position record") } } diff --git a/pkg/service/position.go b/pkg/service/position.go index 5fb38eaa7..d09b48bcf 100644 --- a/pkg/service/position.go +++ b/pkg/service/position.go @@ -51,7 +51,11 @@ func (s *PositionService) scanRows(rows *sqlx.Rows) (positions []types.Position, return positions, rows.Err() } -func (s *PositionService) Insert(position *types.Position, trade types.Trade, profit fixedpoint.Value) error { +func (s *PositionService) Insert( + position *types.Position, + trade types.Trade, + profit, netProfit fixedpoint.Value, +) error { _, err := s.DB.NamedExec(` INSERT INTO positions ( strategy, diff --git a/pkg/service/position_test.go b/pkg/service/position_test.go index b45a95fcf..7340f4811 100644 --- a/pkg/service/position_test.go +++ b/pkg/service/position_test.go @@ -34,7 +34,7 @@ func TestPositionService(t *testing.T) { ChangedAt: time.Now(), }, types.Trade{ Time: types.Time(time.Now()), - }, fixedpoint.Zero) + }, fixedpoint.Zero, fixedpoint.Zero) assert.NoError(t, err) }) @@ -54,7 +54,7 @@ func TestPositionService(t *testing.T) { Exchange: types.ExchangeBinance, Side: types.SideTypeSell, Time: types.Time(time.Now()), - }, fixedpoint.NewFromFloat(10.9)) + }, fixedpoint.NewFromFloat(10.9), fixedpoint.Zero) assert.NoError(t, err) })