types: add CsvHeaders and CsvRecords methods to TradeStats

This commit is contained in:
c9s 2022-09-02 00:52:21 +08:00
parent d9cce129a0
commit db622fbb55
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -3,6 +3,7 @@ package types
import ( import (
"encoding/json" "encoding/json"
"math" "math"
"strconv"
"time" "time"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -203,6 +204,38 @@ func (s *TradeStats) SetIntervalProfitCollector(c *IntervalProfitCollector) {
s.IntervalProfits[c.Interval] = c s.IntervalProfits[c.Interval] = c
} }
func (s *TradeStats) CsvHeader() []string {
return []string{
"winningRatio",
"numOfProfitTrade",
"numOfLossTrade",
"grossProfit",
"grossLoss",
"profitFactor",
"largestProfitTrade",
"largestLossTrade",
"maximumConsecutiveWins",
"maximumConsecutiveLosses",
}
}
func (s *TradeStats) CsvRecords() [][]string {
return [][]string{
{
s.WinningRatio.String(),
strconv.Itoa(s.NumOfProfitTrade),
strconv.Itoa(s.NumOfLossTrade),
s.GrossProfit.String(),
s.GrossLoss.String(),
s.ProfitFactor.String(),
s.LargestProfitTrade.String(),
s.LargestLossTrade.String(),
strconv.Itoa(s.MaximumConsecutiveWins),
strconv.Itoa(s.MaximumConsecutiveLosses),
},
}
}
func (s *TradeStats) Add(profit *Profit) { func (s *TradeStats) Add(profit *Profit) {
if s.Symbol != "" && profit.Symbol != s.Symbol { if s.Symbol != "" && profit.Symbol != s.Symbol {
return return