forked from bitfinexcom/bitfinex-api-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
46 lines (43 loc) · 987 Bytes
/
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
package main
import (
"context"
"log"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"github.com/aopoltorzhicky/bitfinex-api-go/pkg/models/common"
"github.com/aopoltorzhicky/bitfinex-api-go/v2/websocket"
)
func main() {
client := websocket.New()
err := client.Connect()
if err != nil {
log.Printf("could not connect: %s", err.Error())
return
}
go func() {
for msg := range client.Listen() {
log.Printf("recv: %#v", msg)
if _, ok := msg.(*websocket.InfoEvent); ok {
_, err := client.SubscribeBook(context.Background(), "BTCUSD", common.Precision0, common.FrequencyRealtime, 1)
if err != nil {
log.Printf("could not subscribe to book: %s", err.Error())
}
}
}
}()
done := make(chan bool, 1)
interrupt := make(chan os.Signal)
signal.Notify(interrupt, os.Interrupt, os.Kill)
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
go func() {
<-interrupt
client.Close()
done <- true
os.Exit(0)
}()
<-done
}