extract NewProfitStats method

This commit is contained in:
c9s 2022-05-05 14:48:50 +08:00
parent c3db85443e
commit 10a7928580
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 11 additions and 11 deletions

View File

@ -5,7 +5,6 @@ import (
"fmt"
"math"
"sync"
"time"
"github.com/c9s/bbgo/pkg/indicator"
"github.com/c9s/bbgo/pkg/util"
@ -291,15 +290,6 @@ func (s *Strategy) EmergencyStop(ctx context.Context) error {
return err
}
func (s *Strategy) newProfitStats() *types.ProfitStats {
return &types.ProfitStats{
Symbol: s.Market.Symbol,
BaseCurrency: s.Market.BaseCurrency,
QuoteCurrency: s.Market.QuoteCurrency,
AccumulatedSince: time.Now().Unix(),
}
}
// Deprecated: LoadState method is migrated to the persistence struct tag.
func (s *Strategy) LoadState() error {
var state State
@ -605,7 +595,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
p2 := s.state.ProfitStats
s.ProfitStats = &p2
} else {
s.ProfitStats = s.newProfitStats()
s.ProfitStats = types.NewProfitStats(s.Market)
}
}

View File

@ -218,6 +218,16 @@ type ProfitStats struct {
TodaySince int64 `json:"todaySince,omitempty"`
}
func NewProfitStats(market Market) *ProfitStats {
return &ProfitStats{
Symbol: market.Symbol,
BaseCurrency: market.BaseCurrency,
QuoteCurrency: market.QuoteCurrency,
AccumulatedSince: time.Now().Unix(),
}
}
func (s *ProfitStats) Init(market Market) {
s.Symbol = market.Symbol
s.BaseCurrency = market.BaseCurrency