Skip to content

Instantly share code, notes, and snippets.

@Rovak Rovak/README.md Secret
Last active May 31, 2019

Embed
What would you like to do?
TronTrade GraphQL Queries

TronTrade GraphQL Queries

These queries can be used in https://trontrade.io/graphql

1.how to get my balances?

You can get your TRX/TRC10/TRC20 balances from your Tron wallet like GuildWallet or TronLink.

2.how to get all of my open orders?

query myOrders($address: ID!, $start: Int, $limit: Int, $status: String!, $exchangeId: Int, $sortType: String, $orderBy: String){
  wallet(address: $address) {
    orders(limit: $limit, start: $start, status: $status, exchangeId: $exchangeId, sortType: $sortType, orderBy: $orderBy) {
      totalCount,
      rows {
        id
        marketPrice
        amount
        filled
        status
        txStatus
        createdAt
        txOrder
        marketId
        contractId
        side
        completedAt
      }
    }
  }
}

query parameters and explain:

{
  "address": "TXRgUnEKA9qHwCnsmXJxvBSNogkZUGgf9v", //required. the wallet address you want to query.
  "status": "0,1,2,3", //required. order status list split by comma, see `order status define ` below.
  "start": 0, //optional. default 0.  page index for this query, start from 0,
  "limit": 50, //optional. default 50. page count for this query.
  "exchangeId": 1, //optional. default null. the exchange pair id you want to filter, eg: 1 for ANTE, to get the exchange list , see ...  .  null for all orders.
  "sortType": "createdAt", //optional. default "createdAt". the sort field you want. if you pass any invalid value, it will use the default value. note that it's case sensitive.
  "orderBy": "DESC"  //optional. default "DESC". if you pass any invalid value, it will use the default value. note that it's case sensitive.
}

3.how to get order info by order id?

query orderById($orderId:ID!) {
  order(id: $orderId){
    id
    ownerWallet
    side
    amount
    filled
    marketId
    marketPrice
    txOrder
    createdAt
    completedAt
  }
}

some order field explains:

side: 0 = a sell order , 1 = a buy order.

filled: the filled amout of the order.

4.how to place an order?

since TronTrade is a DEX. you can place order by calling our smart contract. use tronweb.js or some other libraries or use the raw tron http/grpc api.

note that calling contract will cost your energy, make sure your calling account have enough energy, or it will charge you fees.

TRC10 contract address: TTuer45Lt3ikwF5cbJsUghQR7NW4CjJ6HS

to place a sell order call:

contract.sellToken(orderForm.getPriceValue(), TYPE_LIMIT).send({
    tokenId: 1, // 
    tokenValue: ,
    feeLimit: FEE_LIMIT,
});

** note that the call also transfer your order assets to the contract.**

to place a buy order call:

contract.buyToken(orderForm.market.tokenIdA, price, amount).send({
    feeLimit: FEE_LIMIT,
    callValue: orderForm.callValue(),
})

TRC20 contract address: TCgnJmYmMUJ9eS6x62Vj7YFfpBM1DTL8V8

to place a buy order call:

contract.buyToken(orderForm.market.tokenIdA, price, amount).send({
    callValue: orderForm.callValue(),
    feeLimit: FEE_LIMIT,
});

to place a sell order call:

// approve the contract to transfer your token when it get selled
contract.approve(orderForm.market.tokenIdA, orderForm.getTokenValue());

contract.sellToken(orderForm.market.tokenIdA, price, amount, TYPE_LIMIT).send({
    feeLimit: FEE_LIMIT,
});

5.how to cancel an order?

call the Cancel contract: TYemZc2xRyGcB831F1XstGJ1sSSW6NC6KG

cancel TRC10 order:

contract.cancelTrc10Order(orderId)
contract.cancelOrder(orderId);

how to get the exchange pair list?

query {
    exchanges {
      id
      icon
      buyAssetName
      sellAssetName
      tokenTypeA
      tokenIdA
      tokenTypeB
      tokenIdB
      tokenDecimalsA
      tokenDecimalsB
      site
      listed
    }
  }

order status define:

Failed: 0, Pending: 1, Completed: 2, Cancelled: 3,

sortType allowed for myOrders query:

"status", "completedAt", "createdAt", "side", "marketPrice", "amountQuantity", "filledQuantity", "total",

query {
exchanges {
id
buyAssetName
sellAssetName
tokenTypeA
tokenIdA
tokenDecimalsA
tokenTypeB
tokenIdB
tokenDecimalsB
stats {
high
low
lastPrice
h24_price
h24_change
volume
}
orderBook {
buy {
price
totalAmount
}
sell {
price
totalAmount
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.