mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
types: use passed time to reset today pnl
This commit is contained in:
parent
26cf048c84
commit
f9f2df29e7
|
@ -2,6 +2,7 @@ package xmaker
|
|||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
|
@ -57,7 +58,7 @@ func (s *ProfitStats) AddTrade(trade types.Trade) {
|
|||
}
|
||||
|
||||
func (s *ProfitStats) ResetToday() {
|
||||
s.ProfitStats.ResetToday()
|
||||
s.ProfitStats.ResetToday(time.Now())
|
||||
|
||||
s.lock.Lock()
|
||||
s.TodayMakerVolume = fixedpoint.Zero
|
||||
|
|
|
@ -198,7 +198,7 @@ func (s *ProfitStats) Init(market Market) {
|
|||
|
||||
func (s *ProfitStats) AddProfit(profit Profit) {
|
||||
if s.IsOver24Hours() {
|
||||
s.ResetToday()
|
||||
s.ResetToday(profit.TradedAt)
|
||||
}
|
||||
|
||||
// since field guard
|
||||
|
@ -227,7 +227,7 @@ func (s *ProfitStats) AddProfit(profit Profit) {
|
|||
|
||||
func (s *ProfitStats) AddTrade(trade Trade) {
|
||||
if s.IsOver24Hours() {
|
||||
s.ResetToday()
|
||||
s.ResetToday(trade.Time.Time())
|
||||
}
|
||||
|
||||
s.AccumulatedVolume = s.AccumulatedVolume.Add(trade.Quantity)
|
||||
|
@ -238,13 +238,13 @@ func (s *ProfitStats) IsOver24Hours() bool {
|
|||
return time.Since(time.Unix(s.TodaySince, 0)) >= 24*time.Hour
|
||||
}
|
||||
|
||||
func (s *ProfitStats) ResetToday() {
|
||||
func (s *ProfitStats) ResetToday(t time.Time) {
|
||||
s.TodayPnL = fixedpoint.Zero
|
||||
s.TodayNetProfit = fixedpoint.Zero
|
||||
s.TodayGrossProfit = fixedpoint.Zero
|
||||
s.TodayGrossLoss = fixedpoint.Zero
|
||||
|
||||
var beginningOfTheDay = BeginningOfTheDay(time.Now().Local())
|
||||
var beginningOfTheDay = BeginningOfTheDay(t.Local())
|
||||
s.TodaySince = beginningOfTheDay.Unix()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user