-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (46 loc) · 1.26 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
package main
import (
"flag"
"log"
"sync"
"time"
"github.com/antonioshadji/goquotemonitor/coinbase"
"github.com/antonioshadji/goquotemonitor/db"
"github.com/antonioshadji/goquotemonitor/sfox"
"github.com/antonioshadji/goquotemonitor/kraken"
)
var port = flag.String("port", "8080", "Port to listen on for web ui.")
func init() {
// https://pkg.go.dev/log#pkg-constants
log.SetFlags(log.LstdFlags | log.Lmicroseconds | log.Lshortfile)
}
func main() {
flag.Parse()
defer db.DB.Close()
defer db.Stmt.Close() // Prepared statements take up server resources and should be closed after use.
var mainwg sync.WaitGroup
for i, w := range db.WorkList {
log.Printf("%02d: %#v", i, w)
go func(w db.Work) {
mainwg.Add(1)
defer mainwg.Done()
if w.LP == "Coinbase" {
coinbase.Work(w)
} else if w.LP == "sFOX" {
sfox.Work(w)
} else if w.LP == "Kraken" {
kraken.Work(w)
} else {
log.Printf("LP %v not implemented", w.LP)
}
}(w)
// separate quotes to reduce load
time.Sleep(1 * time.Second)
}
// TODO: work in progress - display config settings and edit
go db.Webui(*port)
// TODO: add mechanism for stopping go routines
log.Println("Waiting for Main WaitGroup.")
mainwg.Wait()
log.Println("Main WaitGroup ended.")
}