mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
add net profit arg to the position insert method
This commit is contained in:
parent
e26156d77b
commit
9d0898ecc6
|
@ -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)
|
log.Infof("recordPosition: position = %s, trade = %+v, profit = %+v", position.Base.String(), trade, profit)
|
||||||
if profit != nil {
|
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")
|
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)
|
log.WithError(err).Errorf("can not insert profit record: %+v", profit)
|
||||||
}
|
}
|
||||||
} else {
|
} 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")
|
log.WithError(err).Errorf("can not insert position record")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,11 @@ func (s *PositionService) scanRows(rows *sqlx.Rows) (positions []types.Position,
|
||||||
return positions, rows.Err()
|
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(`
|
_, err := s.DB.NamedExec(`
|
||||||
INSERT INTO positions (
|
INSERT INTO positions (
|
||||||
strategy,
|
strategy,
|
||||||
|
|
|
@ -34,7 +34,7 @@ func TestPositionService(t *testing.T) {
|
||||||
ChangedAt: time.Now(),
|
ChangedAt: time.Now(),
|
||||||
}, types.Trade{
|
}, types.Trade{
|
||||||
Time: types.Time(time.Now()),
|
Time: types.Time(time.Now()),
|
||||||
}, fixedpoint.Zero)
|
}, fixedpoint.Zero, fixedpoint.Zero)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ func TestPositionService(t *testing.T) {
|
||||||
Exchange: types.ExchangeBinance,
|
Exchange: types.ExchangeBinance,
|
||||||
Side: types.SideTypeSell,
|
Side: types.SideTypeSell,
|
||||||
Time: types.Time(time.Now()),
|
Time: types.Time(time.Now()),
|
||||||
}, fixedpoint.NewFromFloat(10.9))
|
}, fixedpoint.NewFromFloat(10.9), fixedpoint.Zero)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user