-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (43 loc) · 1.1 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
// nolint:errcheck
package main
import (
"context"
"github.com/blewater/zh/cmd"
"github.com/blewater/zh/log"
"github.com/blewater/zh/workflow"
"go.uber.org/zap"
"os"
"os/signal"
)
// nolint:errcheck
func main() {
cfg, logger := bootstrap()
w := workflow.New(cfg)
ctx, cancel := context.WithCancel(
log.ContextWithLogger(context.Background(), logger))
// Precedes socket communication to start the pool
go w.StartPool(ctx)
go func() {
if err := w.TradesToVwap(ctx); err != nil {
// socket failed to connect
os.Exit(1)
}
}()
waitInterruptSignal(cancel)
}
func waitInterruptSignal(cancel context.CancelFunc) {
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
<-interrupt
cancel()
}
func bootstrap() (cmd.Config, *zap.Logger) {
cfg := cmd.Execute()
logger := log.New(cfg.DevLogLevel, cfg.SocketURL)
defer logger.Sync()
logger.Info("Starting...")
logger.Info("Subscribing",zap.Strings("Pairs", cfg.ProductIDs))
logger.Info("log-mode",zap.Bool("development", cfg.DevLogLevel))
logger.Info("Socket",zap.String("URL", cfg.SocketURL))
return cfg, logger
}