mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
extract NewProfitStats method
This commit is contained in:
parent
c3db85443e
commit
10a7928580
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user