github.com/InjectiveLabs/sdk-go@v1.53.0/examples/exchange/auction/3_StreamBids/example.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"encoding/json"
     6  	"fmt"
     7  
     8  	"github.com/InjectiveLabs/sdk-go/client/common"
     9  	exchangeclient "github.com/InjectiveLabs/sdk-go/client/exchange"
    10  )
    11  
    12  func main() {
    13  	network := common.LoadNetwork("testnet", "lb")
    14  	exchangeClient, err := exchangeclient.NewExchangeClient(network)
    15  	if err != nil {
    16  		panic(err)
    17  	}
    18  
    19  	ctx := context.Background()
    20  
    21  	stream, err := exchangeClient.StreamBids(ctx)
    22  	if err != nil {
    23  		panic(err)
    24  	}
    25  
    26  	for {
    27  		select {
    28  		case <-ctx.Done():
    29  			return
    30  		default:
    31  			res, err := stream.Recv()
    32  			if err != nil {
    33  				fmt.Println(err)
    34  				return
    35  			}
    36  			str, _ := json.MarshalIndent(res, "", " ")
    37  			fmt.Print(string(str))
    38  		}
    39  	}
    40  }