-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
81 lines (68 loc) · 2.08 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
package main
import (
"bollinger/bands"
"bollinger/plot"
"bollinger/strategies"
"flag"
"fmt"
"sync"
)
// Calculate investment suggestion using strategy on each given symbol
func parallelSuggest(symbols []string, strategy string){
// default strategy
fn := strategies.MoreDown
switch strategy {
case "moredown": fn = strategies.MoreDown
case "moreup": fn = strategies.MoreUp
case "uponce": fn = strategies.UpOnce
case "downonce": fn = strategies.DownOnce
default: fmt.Println("Invalid strategy: ", strategy, "use any of: moredown, moreup, uponce, downonce"); return;
}
// process each symbol in parallel
var wg sync.WaitGroup
wg.Add(len(symbols))
for _,symbol := range(symbols){
go func(symbol string){
all := bands.All(symbol)
if fn(all) {
fmt.Println("Invest [", symbol, "] YES")
} else {
fmt.Println("Invest [", symbol, "] NO")
}
wg.Done()
}(symbol)
}
// wait for execution of all goroutines
wg.Wait()
}
// Executes plot on each given symbol
func parallelPlot(symbols []string){
// process each symbol in parallel
var wg sync.WaitGroup
wg.Add(len(symbols))
for _,symbol := range(symbols){
go func(symbol string){
all := bands.All(symbol)
plot.PlotBands(symbol, all)
fmt.Println("Plot [", symbol, "] OK")
wg.Done()
}(symbol)
}
// wait for execution of all goroutines
wg.Wait()
}
func main() {
args := flag.String("s", "moredown", "suggests investement using given strategy, available: moredown, moreup, uponce, downonce")
argp := flag.Bool("p", false, "calculates and saves bollinger bands as SYMBOL.png")
flag.Parse()
symbols := flag.Args()
if len(symbols) == 0 {
fmt.Println("at least one symbol is required")
return
}
if *argp {
parallelPlot(symbols)
} else {
parallelSuggest(symbols, *args)
}
}