github.com/InjectiveLabs/sdk-go@v1.53.0/examples/exchange/spot/15_StreamHistoricalOrders/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 := "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" 22 subaccountId := "0xc6fe5d33615a1c52c08018c47e8bc53646a0e101000000000000000000000000" 23 direction := "buy" 24 25 req := spotExchangePB.StreamOrdersHistoryRequest{ 26 MarketId: marketId, 27 SubaccountId: subaccountId, 28 Direction: direction, 29 } 30 stream, err := exchangeClient.StreamHistoricalSpotOrders(ctx, &req) 31 if err != nil { 32 panic(err) 33 } 34 35 for { 36 select { 37 case <-ctx.Done(): 38 return 39 default: 40 res, err := stream.Recv() 41 if err != nil { 42 panic(err) 43 return 44 } 45 str, _ := json.MarshalIndent(res, "", " ") 46 fmt.Print(string(str)) 47 } 48 } 49 }