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
package main import ( "context" "crypto/tls" "fmt" "github.com/fbsobreira/gotron-sdk/pkg/client" "google.golang.org/grpc" "google.golang.org/grpc/credentials" ) // QuickNode endpoints consist of two crucial components: the endpoint name and the corresponding token // For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde123456789 // endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC} // token will be : abcde123456789 var token = "YOUR_TOKEN" var endpoint = "YOUR_ENDPOINT:50051" type auth struct { token string } func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) { return map[string]string{ "x-token": a.token, }, nil } func (a *auth) RequireTransportSecurity() bool { return false } func main() { opts := []grpc.DialOption{ grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})), grpc.WithPerRPCCredentials(&auth{token}), } conn := client.NewGrpcClient(endpoint) if err := conn.Start(opts...); err != nil { panic(err) } defer conn.Conn.Close() fmt.Println("Retrieving all exchange pairs...") allExchanges, err := conn.ExchangeList(-1) // Use -1 to get all exchanges if err != nil { fmt.Printf("Error retrieving all exchanges: %v\n", err) return } fmt.Printf("Total number of exchanges: %d\n\n", len(allExchanges.Exchanges)) fmt.Println("Retrieving paginated exchange pairs...") page := int64(0) // Page number (starting from 0) limit := 2 // Number of exchanges per page paginatedExchanges, err := conn.ExchangeList(page, limit) if err != nil { fmt.Printf("Error retrieving paginated exchanges: %v\n", err) return } fmt.Printf("Page %d (limit %d): Retrieved %d exchanges\n\n", page, limit, len(paginatedExchanges.Exchanges)) fmt.Println("Exchange Details:") for i, exchange := range paginatedExchanges.Exchanges { fmt.Printf("Exchange #%d:\n", i+1) fmt.Printf(" ID: %d\n", exchange.ExchangeId) fmt.Printf(" Creator: %s\n", string(exchange.CreatorAddress)) fmt.Printf(" Creation Time: %d\n", exchange.CreateTime) fmt.Printf(" First Token ID: %s\n", string(exchange.FirstTokenId)) fmt.Printf(" First Token Balance: %d\n", exchange.FirstTokenBalance) fmt.Printf(" Second Token ID: %s\n", string(exchange.SecondTokenId)) fmt.Printf(" Second Token Balance: %d\n", exchange.SecondTokenBalance) if exchange.FirstTokenBalance > 0 && exchange.SecondTokenBalance > 0 { rate1 := float64(exchange.SecondTokenBalance) / float64(exchange.FirstTokenBalance) rate2 := float64(exchange.FirstTokenBalance) / float64(exchange.SecondTokenBalance) fmt.Printf(" Exchange Rates:\n") fmt.Printf(" 1 %s = %.6f %s\n", string(exchange.FirstTokenId), rate1, string(exchange.SecondTokenId)) fmt.Printf(" 1 %s = %.6f %s\n", string(exchange.SecondTokenId), rate2, string(exchange.FirstTokenId)) } fmt.Println() } }
Don't have an account yet?
Create your QuickNode endpoint in seconds and start building
Get started for free