-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.go
139 lines (127 loc) · 3.09 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
129
130
131
132
133
134
135
136
137
138
139
package main
import (
"flag"
"fmt"
"path/filepath"
"time"
"github.com/adyzng/go-duka/fxt4"
"github.com/go-clog/clog"
)
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),
},
})
*/
}
type argsList struct {
Verbose bool
Header bool
Local bool
Spread uint
Model uint
Dump string
Symbol string
Output string
Format string
Period string
Start string
End string
}
func main() {
args := 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")
flag.StringVar(&args.Symbol,
"symbol", "",
"symbol list using format, like: EURUSD EURGBP")
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")
flag.BoolVar(&args.Header,
"header", false,
"save csv with header")
flag.BoolVar(&args.Local,
"local", false,
"convert to given format with local data instead of downloading from dukascopy")
flag.BoolVar(&args.Verbose,
"verbose", false,
"verbose output trace log")
flag.Parse()
if args.Verbose {
clog.New(clog.CONSOLE, clog.ConsoleConfig{
Level: clog.TRACE,
BufferSize: 100,
})
} else {
clog.New(clog.CONSOLE, clog.ConsoleConfig{
Level: clog.INFO,
BufferSize: 100,
})
}
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 := ParseOption(args)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf(" Output: %s\n", opt.Folder)
fmt.Printf(" Symbol: %s\n", opt.Symbol)
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(" LocalData: %t\n", opt.Local)
fmt.Printf(" StartDate: %s\n", opt.Start.Format("2006-01-02:15H"))
fmt.Printf(" EndDate: %s\n", opt.End.Format("2006-01-02:15H"))
defer clog.Shutdown()
app := NewApp(opt)
app.Execute()
}