github.com/InjectiveLabs/sdk-go@v1.53.0/examples/exchange/spot/17_StreamTradesV2/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 spotExchangePB "github.com/InjectiveLabs/sdk-go/exchange/spot_exchange_rpc/pb" 11 ) 12 13 func main() { 14 network := common.LoadNetwork("testnet", "lb") 15 exchangeClient, err := exchangeclient.NewExchangeClient(network) 16 if err != nil { 17 panic(err) 18 } 19 20 ctx := context.Background() 21 marketId := "0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0" 22 subaccountId := "0xc6fe5d33615a1c52c08018c47e8bc53646a0e101000000000000000000000000" 23 24 req := spotExchangePB.StreamTradesV2Request{ 25 MarketId: marketId, 26 SubaccountId: subaccountId, 27 } 28 stream, err := exchangeClient.StreamSpotTradesV2(ctx, &req) 29 if err != nil { 30 panic(err) 31 } 32 33 for { 34 select { 35 case <-ctx.Done(): 36 return 37 default: 38 res, err := stream.Recv() 39 if err != nil { 40 fmt.Println(err) 41 return 42 } 43 str, _ := json.MarshalIndent(res, "", " ") 44 fmt.Print(string(str)) 45 } 46 } 47 }