forked from leifcr/go-duka
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
128 lines (117 loc) · 3.06 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
import (
"flag"
"fmt"
"github.com/edward-yakop/go-duka/internal/app"
"log/slog"
"os"
"path/filepath"
"time"
"github.com/edward-yakop/go-duka/internal/export/fxt4"
)
func init() {
/*
var fpath string
if logPath == "" {
fpath, _ = os.Getwd()
} else {
fpath, _ = filepath.Abs(logPath)
}
if err := os.MkdirAll(filepath.Dir(fpath), 666); err != nil {
fmt.Printf("[App] Create log folder failed: %v.", err)
os.Exit(-1)
}
log.Trace("App Path: %s.", fpath)
log.New(log.FILE, log.FileConfig{
Level: log.TRACE,
Filename: filepath.Join(fpath, "app.log"),
BufferSize: 2048,
FileRotationConfig: log.FileRotationConfig{
Rotate: true,
MaxDays: 30,
MaxSize: 50 * (1 << 20),
},
})
*/
}
func main() {
args := app.ArgsList{}
start := time.Now().Format("2006-01-02")
end := time.Now().Add(24 * time.Hour).Format("2006-01-02")
flag.StringVar(&args.Dump,
"dump", "",
"dump given file format")
flag.StringVar(&args.Period,
"timeframe", "M1",
"timeframe values: M1, M5, M15, M30, H1, H4, D1, W1, MN (Comma separated list)")
flag.StringVar(&args.Symbol,
"symbol", "",
"symbol list using format, like: EURUSD EURGBP (*required)")
flag.StringVar(&args.Start,
"start", start,
"start date format YYYY-MM-DD")
flag.StringVar(&args.End,
"end", end,
"end date format YYYY-MM-DD")
flag.StringVar(&args.Output,
"output", ".",
"destination directory to save the output file")
flag.UintVar(&args.Spread,
"spread", 20,
"spread value in points")
flag.UintVar(&args.Model,
"model", 0,
"one of the model values: 0, 1, 2")
flag.StringVar(&args.Format,
"format", "",
"output file format, supported csv/hst/fxt (*required)")
flag.BoolVar(&args.Header,
"header", false,
"save csv with header")
flag.BoolVar(&args.Verbose,
"verbose", false,
"verbose output trace log")
flag.Parse()
if args.Verbose {
slog.SetDefault(slog.New(
slog.NewTextHandler(
os.Stdout,
&slog.HandlerOptions{Level: slog.LevelDebug},
),
))
} else {
slog.SetDefault(slog.New(
slog.NewTextHandler(
os.Stdout,
&slog.HandlerOptions{Level: slog.LevelInfo},
),
))
}
if args.Dump != "" {
if filepath.Ext(args.Dump) == ".fxt" {
fxt4.DumpFile(args.Dump, args.Header, nil)
} else {
fmt.Println("invalid file ext", filepath.Ext(args.Dump))
}
return
}
opt, err := app.ParseOption(args)
if err != nil {
fmt.Println("--------------------------------------------")
fmt.Printf("Error: %s\n", err)
fmt.Println("--------------------------------------------")
fmt.Println("Usage:")
flag.PrintDefaults()
return
}
fmt.Printf(" Output: %s\n", opt.Folder)
fmt.Printf(" Instrument: %s\n", opt.Instrument.Code())
fmt.Printf(" Spread: %d\n", opt.Spread)
fmt.Printf(" Mode: %d\n", opt.Mode)
fmt.Printf(" Timeframe: %s\n", opt.Periods)
fmt.Printf(" Format: %s\n", opt.Format)
fmt.Printf(" CsvHeader: %t\n", opt.CsvHeader)
fmt.Printf(" StartDate: %s\n", opt.Start.Format("2006-01-02:15H"))
fmt.Printf(" EndDate: %s\n", opt.End.Format("2006-01-02:15H"))
_ = app.NewApp(opt).Execute()
}