mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
strategy/supertrend: use pkg/data/tsv for tsv output
This commit is contained in:
parent
f7feb7e0fc
commit
2b638d1f8f
|
@ -21,6 +21,15 @@ func NewWriterFile(filename string) (*Writer, error) {
|
|||
return NewWriter(f), nil
|
||||
}
|
||||
|
||||
func AppendWriterFile(filename string) (*Writer, error) {
|
||||
f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewWriter(f), nil
|
||||
}
|
||||
|
||||
func NewWriter(file io.WriteCloser) *Writer {
|
||||
tsv := csv.NewWriter(file)
|
||||
tsv.Comma = '\t'
|
||||
|
|
|
@ -3,8 +3,8 @@ package supertrend
|
|||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"github.com/c9s/bbgo/pkg/data/tsv"
|
||||
"github.com/c9s/bbgo/pkg/risk"
|
||||
"github.com/fatih/color"
|
||||
"os"
|
||||
|
@ -312,15 +312,13 @@ func (s *Strategy) PrintResult(o *os.File) {
|
|||
hiyellow(f, "\n")
|
||||
|
||||
if s.AccumulatedProfitReportTsv != "" {
|
||||
tf, err := os.OpenFile(s.AccumulatedProfitReportTsv, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
|
||||
tsvwiter, err := tsv.AppendWriterFile(s.AccumulatedProfitReportTsv)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer tf.Close()
|
||||
csvwiter := csv.NewWriter(tf)
|
||||
csvwiter.Comma = '\t'
|
||||
defer csvwiter.Flush()
|
||||
csvwiter.Write([]string{s.Symbol, s.accumulatedProfit.String(), fmt.Sprintf("%f", s.accumulatedProfitMA.Last()), fmt.Sprintf("%f", s.dailyAccumulatedProfits.Sum())})
|
||||
defer tsvwiter.Close()
|
||||
// Output symbol, total acc. profit, acc. profit 60MA, 7d acc. profit
|
||||
tsvwiter.Write([]string{s.Symbol, s.accumulatedProfit.String(), fmt.Sprintf("%f", s.accumulatedProfitMA.Last()), fmt.Sprintf("%f", s.dailyAccumulatedProfits.Sum())})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user