ExchangeTrade gRPC Method
매개변수
출처:
문자열
필수
로딩 중...
exchangeID
정수
필수
로딩 중...
tokenID
문자열
필수
로딩 중...
amountToken
정수
필수
로딩 중...
amountExpected
정수
필수
로딩 중...
반품
거래
객체
로딩 중...
원시 데이터
객체
로딩 중...
ref_block_bytes
문자열
로딩 중...
ref_block_num
정수
로딩 중...
ref_block_hash
문자열
로딩 중...
만료
정수
로딩 중...
auths
배열
로딩 중...
데이터
문자열
로딩 중...
계약
배열
로딩 중...
유형
문자열
로딩 중...
매개변수
객체
로딩 중...
값
문자열
로딩 중...
type_url
문자열
로딩 중...
provider
문자열
로딩 중...
ContractName
문자열
로딩 중...
Permission_id
정수
로딩 중...
scripts
문자열
로딩 중...
타임스탬프
정수
로딩 중...
수수료 한도
정수
로딩 중...
서명
배열
로딩 중...
ret
배열
로딩 중...
수수료
정수
로딩 중...
ret
문자열
로딩 중...
contractRet
문자열
로딩 중...
assetIssueID
문자열
로딩 중...
withdraw_amount
정수
로딩 중...
unfreeze_amount
정수
로딩 중...
exchange_received_amount
정수
로딩 중...
exchange_inject_another_amount
정수
로딩 중...
exchange_withdraw_another_amount
정수
로딩 중...
exchange_id
정수
로딩 중...
shielded_transaction_fee
정수
로딩 중...
orderId
문자열
로딩 중...
orderDetails
배열
로딩 중...
makerOrderId
문자열
로딩 중...
takerOrderId
문자열
로딩 중...
fillSellQuantity
정수
로딩 중...
fillBuyQuantity
정수
로딩 중...
withdraw_expire_amount
정수
로딩 중...
cancelUnfreezeV2Amount
객체
로딩 중...
txid
문자열
로딩 중...
constant_result
배열
로딩 중...
결과
객체
로딩 중...
결과
부울
로딩 중...
코드
문자열
로딩 중...
메시지
문자열
로딩 중...
에너지_사용량
정수
로딩 중...
로그
배열
로딩 중...
주소
문자열
로딩 중...
주제
배열
로딩 중...
데이터
문자열
로딩 중...
internal_transactions
배열
로딩 중...
해시
문자열
로딩 중...
caller_address
문자열
로딩 중...
transferTo_address
문자열
로딩 중...
callValueInfo
배열
로딩 중...
callValue
정수
로딩 중...
tokenId
문자열
로딩 중...
note
문자열
로딩 중...
rejected
부울
로딩 중...
extra
문자열
로딩 중...
energy_penalty
정수
로딩 중...
요청
1패키지 main23가져오기 (4"문맥"5"crypto/tls"6"encoding/json"7"fmt"8"github.com/fbsobreira/gotron-sdk/pkg/client"9"google.golang.grpc"10"google.golang.grpc"11)1213// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token14// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde12345678915// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}16// token will be : abcde1234567891718var 토큰 token = "YOUR_TOKEN"19var endpoint = "YOUR_ENDPOINT:50051"2021유형 auth struct {22token string23}2425func (a *auth) GetRequestMetadata(ctx 컨텍스트.Context, uri ...문자열) (map[문자열]문자열, error) {26return map[string]string{27"x-token": a.token,28}, nil29}3031func (a *auth) RequireTransportSecurity() bool {32return false33}3435func main() {3637opts := []grpc.DialOption{38grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),39grpc.WithPerRPCCredentials(&auth{token}),40}41conn := client.NewGrpcClient(endpoint)42if err := conn.Start(opts...); err != nil {43panic(err)44}45defer conn.Conn.Close()4647from := "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g" // Address performing the trade48exchangeID := int64(123) // ID of the exchange pair4950fmt.Printf("Verifying exchange ID %d...\n", exchangeID)51exchange, err := conn.ExchangeByID(exchangeID)52if err != nil {53fmt.Printf("Error: The specified exchange does not exist: %v\n", err)54반환55}5657firstTokenID := string(exchange.FirstTokenId)58secondTokenID := string(exchange.SecondTokenId)59fmt.Printf("Exchange %d contains tokens: %s and %s\n",60exchangeID, firstTokenID, secondTokenID)6162tokenID := firstTokenID63amountToken := int64(1000000)64amountExpected := int64(1800000)6566if tokenID != firstTokenID && tokenID != secondTokenID {67fmt.Printf("Error: Token %s is not in exchange %d\n", tokenID, exchangeID)68반환69}7071fmt.Printf("Checking token balance for %s...\n", tokenID)72var tokenBalance int6473// The method to get balance depends on whether we're trading TRX or a TRC10 token74if tokenID == "" {75// For TRX76account, err := conn.GetAccount(from)77if err != nil {78fmt.Printf("Error getting account: %v\n", err)79반환80}81tokenBalance = account.Balance82} else {83// For TRC10 tokens84account, err := conn.GetAccount(from)85if err != nil {86fmt.Printf("Error getting account: %v\n", err)87반환88}8990found := false91for tokenName, balance := range account.AssetV2 {92if string(tokenName) == tokenID {93tokenBalance = balance94found = true95break96}97}98if !found {99tokenBalance = 0100}101}102103fmt.Printf("Token balance: %d\n", tokenBalance)104105if tokenBalance < amountToken {106fmt.Printf("Error: Insufficient token balance. Have: %d, Need: %d\n", tokenBalance, amountToken)107fmt.Println("Please make sure you have enough tokens before trading.")108반환109}110111// Create the trade transaction112fmt.Println("Creating exchange trade transaction...")113114tx, err := conn.ExchangeTrade(115from, // The trader's address116exchangeID, // Exchange ID117tokenID, // Token ID to trade118amountToken, // Amount to trade119amountExpected, // Minimum expected return120)121122if err != nil {123fmt.Printf("Error creating trade transaction: %v\n", err)124반환125}126127fmt.Println("Trade transaction created successfully. Transaction details:")128jsonData, _ := json.MarshalIndent(tx, "", " ")129fmt.Println(string(jsonData))130131// NOTE: In a production environment, the transaction should be signed here132fmt.Println("\nBroadcasting transaction to the TRON network...")133result, err := conn.Broadcast(tx.Transaction)134if err != nil {135fmt.Printf("Error broadcasting transaction: %v\n", err)136반환137}138139if !result.GetResult() {140fmt.Printf("Broadcast failed: %s\n", result.GetMessage())141반환142}143144fmt.Println("Trade executed successfully! Result:")145resultJSON, _ := json.MarshalIndent(result, "", " ")146fmt.Println(string(resultJSON))147}
1패키지 main23가져오기 (4"문맥"5"crypto/tls"6"encoding/json"7"fmt"8"github.com/fbsobreira/gotron-sdk/pkg/client"9"google.golang.grpc"10"google.golang.grpc"11)1213// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token14// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde12345678915// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}16// token will be : abcde1234567891718var 토큰 token = "YOUR_TOKEN"19var endpoint = "YOUR_ENDPOINT:50051"2021유형 auth struct {22token string23}2425func (a *auth) GetRequestMetadata(ctx 컨텍스트.Context, uri ...문자열) (map[문자열]문자열, error) {26return map[string]string{27"x-token": a.token,28}, nil29}3031func (a *auth) RequireTransportSecurity() bool {32return false33}3435func main() {3637opts := []grpc.DialOption{38grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),39grpc.WithPerRPCCredentials(&auth{token}),40}41conn := client.NewGrpcClient(endpoint)42if err := conn.Start(opts...); err != nil {43panic(err)44}45defer conn.Conn.Close()4647from := "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g" // Address performing the trade48exchangeID := int64(123) // ID of the exchange pair4950fmt.Printf("Verifying exchange ID %d...\n", exchangeID)51exchange, err := conn.ExchangeByID(exchangeID)52if err != nil {53fmt.Printf("Error: The specified exchange does not exist: %v\n", err)54반환55}5657firstTokenID := string(exchange.FirstTokenId)58secondTokenID := string(exchange.SecondTokenId)59fmt.Printf("Exchange %d contains tokens: %s and %s\n",60exchangeID, firstTokenID, secondTokenID)6162tokenID := firstTokenID63amountToken := int64(1000000)64amountExpected := int64(1800000)6566if tokenID != firstTokenID && tokenID != secondTokenID {67fmt.Printf("Error: Token %s is not in exchange %d\n", tokenID, exchangeID)68반환69}7071fmt.Printf("Checking token balance for %s...\n", tokenID)72var tokenBalance int6473// The method to get balance depends on whether we're trading TRX or a TRC10 token74if tokenID == "" {75// For TRX76account, err := conn.GetAccount(from)77if err != nil {78fmt.Printf("Error getting account: %v\n", err)79반환80}81tokenBalance = account.Balance82} else {83// For TRC10 tokens84account, err := conn.GetAccount(from)85if err != nil {86fmt.Printf("Error getting account: %v\n", err)87반환88}8990found := false91for tokenName, balance := range account.AssetV2 {92if string(tokenName) == tokenID {93tokenBalance = balance94found = true95break96}97}98if !found {99tokenBalance = 0100}101}102103fmt.Printf("Token balance: %d\n", tokenBalance)104105if tokenBalance < amountToken {106fmt.Printf("Error: Insufficient token balance. Have: %d, Need: %d\n", tokenBalance, amountToken)107fmt.Println("Please make sure you have enough tokens before trading.")108반환109}110111// Create the trade transaction112fmt.Println("Creating exchange trade transaction...")113114tx, err := conn.ExchangeTrade(115from, // The trader's address116exchangeID, // Exchange ID117tokenID, // Token ID to trade118amountToken, // Amount to trade119amountExpected, // Minimum expected return120)121122if err != nil {123fmt.Printf("Error creating trade transaction: %v\n", err)124반환125}126127fmt.Println("Trade transaction created successfully. Transaction details:")128jsonData, _ := json.MarshalIndent(tx, "", " ")129fmt.Println(string(jsonData))130131// NOTE: In a production environment, the transaction should be signed here132fmt.Println("\nBroadcasting transaction to the TRON network...")133result, err := conn.Broadcast(tx.Transaction)134if err != nil {135fmt.Printf("Error broadcasting transaction: %v\n", err)136반환137}138139if !result.GetResult() {140fmt.Printf("Broadcast failed: %s\n", result.GetMessage())141반환142}143144fmt.Println("Trade executed successfully! Result:")145resultJSON, _ := json.MarshalIndent(result, "", " ")146fmt.Println(string(resultJSON))147}