-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
80 lines (63 loc) · 1.77 KB
/
main.go
File metadata and controls
80 lines (63 loc) · 1.77 KB
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
package main
import (
"flag"
"os"
"os/signal"
"strings"
"sync"
"github.com/ohmpatel1997/vwap/clients"
"github.com/ohmpatel1997/vwap/consumers"
"github.com/ohmpatel1997/vwap/entity"
"github.com/ohmpatel1997/vwap/factory"
"github.com/ohmpatel1997/vwap/producers"
"github.com/ohmpatel1997/vwap/repository"
log "github.com/sirupsen/logrus"
)
const (
DefaultProducts = "BTC-USD,ETH-USD,ETH-BTC"
DefaultVolumeSize = 200
)
func main() {
logger := log.New()
logger.SetOutput(os.Stderr)
logger.Info("Live vwap")
feedURL := flag.String("feed-url", clients.DefaultCoinbaseRateFeedWebsocketURL, "Coinbase feed URL")
capacity := flag.Int("capacity", DefaultVolumeSize, "Capacity for storing data for VWAP calculation")
logLevel := flag.String("log-level", "error", "Logging level")
flag.Parse()
level, err := log.ParseLevel(*logLevel)
if err != nil {
level = log.ErrorLevel
}
logger.SetLevel(level)
cfg := &entity.Config{
Channels: strings.Split(clients.DefaultCoinbaseRateFeedChannel, ","),
ProductIDs: strings.Split(DefaultProducts, ","),
URL: *feedURL,
Capacity: *capacity,
}
wg := sync.WaitGroup{}
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
client, err := clients.NewCoinbaseRateFeed(logger, &wg, cfg)
if err != nil {
logger.WithField("error", err).Fatal("Failed to create Coinbase websocket client")
}
repo := repository.NewRepository(cfg)
producer := producers.NewProducer()
useCase := factory.New(repo, producer, cfg)
matchConsumer := consumers.NewVWAPConsumer(logger, useCase, cfg)
client.RegisterConsumer(matchConsumer)
client.Run()
go func() {
for {
if x := <-interrupt; x != nil {
logger.Info("interrupt")
client.Stop()
return
}
}
}()
wg.Wait()
logger.Debug("Finished.")
}