github.com/InjectiveLabs/sdk-go@v1.53.0/examples/exchange/derivatives/21_TradesV2/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  	derivativeExchangePB "github.com/InjectiveLabs/sdk-go/exchange/derivative_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 := "0x4ca0f92fc28be0c9761326016b5a1a2177dd6375558365116b5bdda9abc229ce"
    22  	subaccountId := "0xc6fe5d33615a1c52c08018c47e8bc53646a0e101000000000000000000000000"
    23  
    24  	req := derivativeExchangePB.TradesV2Request{
    25  		MarketId:     marketId,
    26  		SubaccountId: subaccountId,
    27  	}
    28  
    29  	res, err := exchangeClient.GetDerivativeTradesV2(ctx, &req)
    30  	if err != nil {
    31  		panic(err)
    32  	}
    33  
    34  	str, _ := json.MarshalIndent(res, "", " ")
    35  	fmt.Print(string(str))
    36  }