ExchangeList gRPC Method
Parameters
page
integer
REQUIRED
Loading...
limit
integer
Loading...
Returns
exchanges
array
Loading...
exchange_id
integer
Loading...
creator_address
string
Loading...
create_time
integer
Loading...
first_token_id
string
Loading...
first_token_balance
integer
Loading...
second_token_id
string
Loading...
second_token_balance
integer
Loading...
Request
1package main23import (4"context"5"crypto/tls"6"fmt"7"github.com/fbsobreira/gotron-sdk/pkg/client"8"google.golang.org/grpc"9"google.golang.org/grpc/credentials"10)1112// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token13// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde12345678914// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}15// token will be : abcde1234567891617var token = "YOUR_TOKEN"18var endpoint = "YOUR_ENDPOINT:50051"1920type auth struct {21token string22}2324func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {25return map[string]string{26"x-token": a.token,27}, nil28}2930func (a *auth) RequireTransportSecurity() bool {31return false32}3334func main() {3536opts := []grpc.DialOption{37grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),38grpc.WithPerRPCCredentials(&auth{token}),39}40conn := client.NewGrpcClient(endpoint)41if err := conn.Start(opts...); err != nil {42panic(err)43}44defer conn.Conn.Close()4546fmt.Println("Retrieving all exchange pairs...")4748allExchanges, err := conn.ExchangeList(-1) // Use -1 to get all exchanges4950if err != nil {51fmt.Printf("Error retrieving all exchanges: %v\n", err)52return53}5455fmt.Printf("Total number of exchanges: %d\n\n", len(allExchanges.Exchanges))5657fmt.Println("Retrieving paginated exchange pairs...")5859page := int64(0) // Page number (starting from 0)60limit := 2 // Number of exchanges per page6162paginatedExchanges, err := conn.ExchangeList(page, limit)6364if err != nil {65fmt.Printf("Error retrieving paginated exchanges: %v\n", err)66return67}6869fmt.Printf("Page %d (limit %d): Retrieved %d exchanges\n\n",70page, limit, len(paginatedExchanges.Exchanges))7172fmt.Println("Exchange Details:")73for i, exchange := range paginatedExchanges.Exchanges {74fmt.Printf("Exchange #%d:\n", i+1)75fmt.Printf(" ID: %d\n", exchange.ExchangeId)76fmt.Printf(" Creator: %s\n", string(exchange.CreatorAddress))77fmt.Printf(" Creation Time: %d\n", exchange.CreateTime)78fmt.Printf(" First Token ID: %s\n", string(exchange.FirstTokenId))79fmt.Printf(" First Token Balance: %d\n", exchange.FirstTokenBalance)80fmt.Printf(" Second Token ID: %s\n", string(exchange.SecondTokenId))81fmt.Printf(" Second Token Balance: %d\n", exchange.SecondTokenBalance)8283if exchange.FirstTokenBalance > 0 && exchange.SecondTokenBalance > 0 {84rate1 := float64(exchange.SecondTokenBalance) / float64(exchange.FirstTokenBalance)85rate2 := float64(exchange.FirstTokenBalance) / float64(exchange.SecondTokenBalance)86fmt.Printf(" Exchange Rates:\n")87fmt.Printf(" 1 %s = %.6f %s\n", string(exchange.FirstTokenId), rate1, string(exchange.SecondTokenId))88fmt.Printf(" 1 %s = %.6f %s\n", string(exchange.SecondTokenId), rate2, string(exchange.FirstTokenId))89}90fmt.Println()91}92}
1package main23import (4"context"5"crypto/tls"6"fmt"7"github.com/fbsobreira/gotron-sdk/pkg/client"8"google.golang.org/grpc"9"google.golang.org/grpc/credentials"10)1112// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token13// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde12345678914// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}15// token will be : abcde1234567891617var token = "YOUR_TOKEN"18var endpoint = "YOUR_ENDPOINT:50051"1920type auth struct {21token string22}2324func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {25return map[string]string{26"x-token": a.token,27}, nil28}2930func (a *auth) RequireTransportSecurity() bool {31return false32}3334func main() {3536opts := []grpc.DialOption{37grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),38grpc.WithPerRPCCredentials(&auth{token}),39}40conn := client.NewGrpcClient(endpoint)41if err := conn.Start(opts...); err != nil {42panic(err)43}44defer conn.Conn.Close()4546fmt.Println("Retrieving all exchange pairs...")4748allExchanges, err := conn.ExchangeList(-1) // Use -1 to get all exchanges4950if err != nil {51fmt.Printf("Error retrieving all exchanges: %v\n", err)52return53}5455fmt.Printf("Total number of exchanges: %d\n\n", len(allExchanges.Exchanges))5657fmt.Println("Retrieving paginated exchange pairs...")5859page := int64(0) // Page number (starting from 0)60limit := 2 // Number of exchanges per page6162paginatedExchanges, err := conn.ExchangeList(page, limit)6364if err != nil {65fmt.Printf("Error retrieving paginated exchanges: %v\n", err)66return67}6869fmt.Printf("Page %d (limit %d): Retrieved %d exchanges\n\n",70page, limit, len(paginatedExchanges.Exchanges))7172fmt.Println("Exchange Details:")73for i, exchange := range paginatedExchanges.Exchanges {74fmt.Printf("Exchange #%d:\n", i+1)75fmt.Printf(" ID: %d\n", exchange.ExchangeId)76fmt.Printf(" Creator: %s\n", string(exchange.CreatorAddress))77fmt.Printf(" Creation Time: %d\n", exchange.CreateTime)78fmt.Printf(" First Token ID: %s\n", string(exchange.FirstTokenId))79fmt.Printf(" First Token Balance: %d\n", exchange.FirstTokenBalance)80fmt.Printf(" Second Token ID: %s\n", string(exchange.SecondTokenId))81fmt.Printf(" Second Token Balance: %d\n", exchange.SecondTokenBalance)8283if exchange.FirstTokenBalance > 0 && exchange.SecondTokenBalance > 0 {84rate1 := float64(exchange.SecondTokenBalance) / float64(exchange.FirstTokenBalance)85rate2 := float64(exchange.FirstTokenBalance) / float64(exchange.SecondTokenBalance)86fmt.Printf(" Exchange Rates:\n")87fmt.Printf(" 1 %s = %.6f %s\n", string(exchange.FirstTokenId), rate1, string(exchange.SecondTokenId))88fmt.Printf(" 1 %s = %.6f %s\n", string(exchange.SecondTokenId), rate2, string(exchange.FirstTokenId))89}90fmt.Println()91}92}
Don't have an account yet?
Create your Quicknode endpoint in seconds and start building
Get started for free