types: init today since if it's 0

This commit is contained in:
c9s 2022-09-15 17:29:16 +08:00
parent f0c0c6712d
commit 24fd81986c
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -196,6 +196,11 @@ func (s *ProfitStats) AddProfit(profit Profit) {
s.AccumulatedSince = profit.TradedAt.Unix()
}
if s.TodaySince == 0 {
var beginningOfTheDay = BeginningOfTheDay(profit.TradedAt.Local())
s.TodaySince = beginningOfTheDay.Unix()
}
s.AccumulatedPnL = s.AccumulatedPnL.Add(profit.Profit)
s.AccumulatedNetProfit = s.AccumulatedNetProfit.Add(profit.NetProfit)
s.TodayPnL = s.TodayPnL.Add(profit.Profit)