-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
109 lines (96 loc) · 2.28 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
package main
import (
"fmt"
//"io"
//"bufio"
"os"
"strings"
//"os/signal"
"time"
//"syscall"
"github.com/RileyR387/sc-data-util/csv"
"github.com/RileyR387/sc-data-util/dly"
"github.com/RileyR387/sc-data-util/scid"
"github.com/RileyR387/sc-data-util/util"
"github.com/pborman/getopt/v2"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
var (
Version = util.Version
)
func main() {
log.Infof("%v version: %v", me, Version)
log.Infof("Symbol: %v\n", *symbol)
var r *scid.ScidReader
var err error
if *dailyDetail {
// TODO: Sanitize input?
dd := dly.NewDailyDataProvider(*symbol, viper.GetString("data.dir"))
dd.WriteDailyDetailCsv(os.Stdout)
return
}
if *stdIn {
r, err = scid.ReaderFromFile(os.Stdin)
if err != nil {
fmt.Printf("Failed to open os.Stdin with error: %v", err)
os.Exit(1)
}
} else {
// TODO: test for specified file first? Then ext?
dataFile := viper.GetString("data.dir") + "/" + strings.ToUpper(*symbol) + ".scid"
r, err = scid.ReaderFromFile(dataFile)
if err != nil {
fmt.Printf("Failed to open file '%v' with error: %v", dataFile, err)
os.Exit(1)
}
}
opts := csv.WriterOptions{
Writer: os.Stdout,
Reader: r,
StartTime: time.Unix(*startUnixTime, 0),
EndTime: time.Unix(*endUnixTime, 0),
TickSizeStr: *tickSize,
BarSize: *barSize,
Bundle: *bundle,
}
// Raw Ticks
if *barSize == "" {
log.Info("Writing ticks to stdout")
csv.WriteRawTicks(opts)
} else {
// 15m 1h 2d 4h 32t 3200t
// TODO: Support for days/weeks...
log.Infof("Writing %v bars to stdout", *barSize)
if *slim {
csv.WriteBarCsv(opts)
} else if *detailProfile {
csv.WriteBarDetailWithProfileCsv(opts)
} else {
csv.WriteBarDetailCsv(opts)
}
}
}
func usage(msg ...string) {
if len(msg) > 0 {
fmt.Fprintf(os.Stderr, "%s\n", msg[0])
}
// strip off the first line of generated usage
b := &strings.Builder{}
getopt.PrintUsage(b)
u := strings.SplitAfterN(b.String(), "\n", 2)
fmt.Printf(`Usage: %s [OPTIONS]
Notes:
- Config (%v) can reside in %v
- Data is written to Stdout
- Activity log is written to Stderr
- startUnixTime options sets first bar start time
OPTIONS
%s
`, me, yamlFile, configSearchPaths, u[1])
os.Exit(1)
}
func ShowVersion() {
fmt.Printf("%v %v\n", me, Version)
os.Exit(0)
}