forked from KhavrTrading/flowex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
73 lines (62 loc) · 1.6 KB
/
main.go
File metadata and controls
73 lines (62 loc) · 1.6 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
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/KhavrTrading/flowex/binance"
log "github.com/sirupsen/logrus"
)
func main() {
log.SetLevel(log.InfoLevel)
mgr := binance.NewManager()
symbols := []string{"BTCUSDT", "ETHUSDT", "SOLUSDT", "XRPUSDT", "DOGEUSDT"}
for _, sym := range symbols {
if err := mgr.SubscribeAll(sym, nil, nil, nil); err != nil {
log.Fatalf("Subscribe %s failed: %v", sym, err)
}
fmt.Printf("Subscribed to %s\n", sym)
}
start := time.Now()
// Print stats every 5 seconds
go func() {
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
for range ticker.C {
elapsed := time.Since(start).Seconds()
fmt.Printf("\n=== %.0fs elapsed ===\n", elapsed)
var totalProcessed, totalDropped int64
for _, sym := range symbols {
worker := mgr.GetOrCreateWorker(sym)
snap := worker.GetSnapshot()
if snap == nil {
continue
}
m := worker.GetMetrics()
proc := m["processed"]
drops := m["candle_dropped"] + m["depth_dropped"] + m["trade_dropped"]
totalProcessed += proc
totalDropped += drops
fmt.Printf(" %-10s candles=%d depth=%d trades=%d | processed=%d dropped=%d\n",
sym,
len(snap.Candles),
snap.DepthStore.Size(),
len(snap.Trades),
proc, drops,
)
}
fmt.Printf(" TOTAL: %d msgs (%.0f/s) | dropped: %d\n",
totalProcessed,
float64(totalProcessed)/elapsed,
totalDropped,
)
}
}()
// Wait for interrupt
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
<-sigCh
fmt.Println("\nShutting down...")
mgr.Shutdown()
}