Skip to main content

ExchangeList gRPC Method

Loading...

Updated on
May 13, 2025

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
1
package main
2
3
import (
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
)
11
12
// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token
13
// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde123456789
14
// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}
15
// token will be : abcde123456789
16
17
var token = "YOUR_TOKEN"
18
var endpoint = "YOUR_ENDPOINT:50051"
19
20
type auth struct {
21
token string
22
}
23
24
func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
25
return map[string]string{
26
"x-token": a.token,
27
}, nil
28
}
29
30
func (a *auth) RequireTransportSecurity() bool {
31
return false
32
}
33
34
func main() {
35
36
opts := []grpc.DialOption{
37
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
38
grpc.WithPerRPCCredentials(&auth{token}),
39
}
40
conn := client.NewGrpcClient(endpoint)
41
if err := conn.Start(opts...); err != nil {
42
panic(err)
43
}
44
defer conn.Conn.Close()
45
46
fmt.Println("Retrieving all exchange pairs...")
47
48
allExchanges, err := conn.ExchangeList(-1) // Use -1 to get all exchanges
49
50
if err != nil {
51
fmt.Printf("Error retrieving all exchanges: %v\n", err)
52
return
53
}
54
55
fmt.Printf("Total number of exchanges: %d\n\n", len(allExchanges.Exchanges))
56
57
fmt.Println("Retrieving paginated exchange pairs...")
58
59
page := int64(0) // Page number (starting from 0)
60
limit := 2 // Number of exchanges per page
61
62
paginatedExchanges, err := conn.ExchangeList(page, limit)
63
64
if err != nil {
65
fmt.Printf("Error retrieving paginated exchanges: %v\n", err)
66
return
67
}
68
69
fmt.Printf("Page %d (limit %d): Retrieved %d exchanges\n\n",
70
page, limit, len(paginatedExchanges.Exchanges))
71
72
fmt.Println("Exchange Details:")
73
for i, exchange := range paginatedExchanges.Exchanges {
74
fmt.Printf("Exchange #%d:\n", i+1)
75
fmt.Printf(" ID: %d\n", exchange.ExchangeId)
76
fmt.Printf(" Creator: %s\n", string(exchange.CreatorAddress))
77
fmt.Printf(" Creation Time: %d\n", exchange.CreateTime)
78
fmt.Printf(" First Token ID: %s\n", string(exchange.FirstTokenId))
79
fmt.Printf(" First Token Balance: %d\n", exchange.FirstTokenBalance)
80
fmt.Printf(" Second Token ID: %s\n", string(exchange.SecondTokenId))
81
fmt.Printf(" Second Token Balance: %d\n", exchange.SecondTokenBalance)
82
83
if exchange.FirstTokenBalance > 0 && exchange.SecondTokenBalance > 0 {
84
rate1 := float64(exchange.SecondTokenBalance) / float64(exchange.FirstTokenBalance)
85
rate2 := float64(exchange.FirstTokenBalance) / float64(exchange.SecondTokenBalance)
86
fmt.Printf(" Exchange Rates:\n")
87
fmt.Printf(" 1 %s = %.6f %s\n", string(exchange.FirstTokenId), rate1, string(exchange.SecondTokenId))
88
fmt.Printf(" 1 %s = %.6f %s\n", string(exchange.SecondTokenId), rate2, string(exchange.FirstTokenId))
89
}
90
fmt.Println()
91
}
92
}
Don't have an account yet?
Create your Quicknode endpoint in seconds and start building
Get started for free