github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/examples/v1/ws-private/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	"github.com/bitfinexcom/bitfinex-api-go/v1"
     8  )
     9  
    10  // Set BFX_APIKEY and BFX_SECRET as :
    11  //
    12  // export BFX_API_KEY=YOUR_API_KEY
    13  // export BFX_API_SECRET=YOUR_API_SECRET
    14  //
    15  // you can obtain it from https://www.bitfinex.com/api
    16  
    17  func main() {
    18  	key := os.Getenv("BFX_API_KEY")
    19  	secret := os.Getenv("BFX_API_SECRET")
    20  	client := bitfinex.NewClient().Auth(key, secret)
    21  
    22  	dataChan := make(chan bitfinex.TermData)
    23  	go client.WebSocket.ConnectPrivate(dataChan)
    24  
    25  	for {
    26  		select {
    27  		case data := <-dataChan:
    28  			if data.HasError() {
    29  				// Data has error - websocket channel will be closed.
    30  				fmt.Println("Error:", data.Error)
    31  				return
    32  			} else {
    33  				fmt.Println("Data:", data)
    34  			}
    35  		}
    36  	}
    37  }