github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/examples/v2/trade-feed-multi/main.go (about) 1 package main 2 3 import ( 4 "context" 5 "log" 6 _ "net/http/pprof" 7 8 "github.com/bitfinexcom/bitfinex-api-go/pkg/models/trade" 9 "github.com/bitfinexcom/bitfinex-api-go/v2/websocket" 10 ) 11 12 var tickers = []string{"tBTCUSD", "tETHUSD", "tBTCUSD", "tVETUSD", "tDGBUSD", "tEOSUSD", "tTRXUSD"} 13 14 func main() { 15 client := websocket.New() 16 err := client.Connect() 17 if err != nil { 18 log.Printf("could not connect: %s", err.Error()) 19 return 20 } 21 22 for obj := range client.Listen() { 23 switch obj.(type) { 24 case error: 25 log.Printf("channel closed: %s", obj) 26 return 27 case *trade.Trade: 28 log.Printf("New trade: %+v\n", obj) 29 case *websocket.InfoEvent: 30 // Info event confirms connection to the bfx websocket 31 for _, ticker := range tickers { 32 _, err := client.SubscribeTrades(context.Background(), ticker) 33 if err != nil { 34 log.Printf("could not subscribe to trades: %s", err.Error()) 35 } 36 } 37 default: 38 log.Printf("MSG RECV: %#v", obj) 39 } 40 } 41 }