Querying THORChain
How to Query THORChain

Querying THORChain Details can be done from Midgard. This page gives some examples.

Full documentation for Midgard can be found at Midgard's API documented at https://midgard.thorchain.info/v2/doc.

Getting the Asgard Vault

Vaults are fetched from the /inbound_addresses endpoint. You need to select the address of the Chain the inbound transaction will go do.
The address will be the current active Asgard Address that accepts inbounds. Do not cache these address as they change regularly.
Example Output, each connected chain will be displayed.
"chain": "BCH",
"pub_key": "thorpub1addwnpepqwhrpzyaehvq3crh4mh7jd24h5shknthr7c247qyfzaqcy0nh5s2q0akde8",
"address": "qr0l8n9v3yrs2rccmz4usp5fz0rnjrf30y98tzpdyt",
"halted": false,
"gas_rate": "3"
If you connect to a public Midgard, you must be conscious of the fact that you can be phished and could send money to the WRONG vault. You should do safety checks, i.e. comparing with other nodes, or even inspecting the vault itself for presence of funds. You should also consider running your own 'fullnode' instance to query for trusted data.
Never cache vault addresses, they churn regularly.
Check for the halted parameter and never send funds if it is set to true
Chain: Chain Name
Address: Asgard Vault inbound address for that chain.,
Halted: Boolean, if the chain is halted. This should be monitored.
gas_rate: rate to be used, e.g. in Stats or GWei. See Fees.

Displaying available pairs

Use the /pools endpoint of Midgard to retrieve all swappable assets on THORChain. The response will be an array of objects like this:
"asset": "BNB.BTCB-1DE",
"assetDepth": "11262499812",
"assetPrice": "11205.698400479405",
"assetPriceUSD": "38316.644098172634",
"liquidityUnits": "61816750778660",
"poolAPY": "0.24483254735655713",
"runeDepth": "126204176128728",
"status": "available",
"synthSupply": "0",
"synthUnits": "0",
"units": "61816750778660",
"volume24h": "67544420820530"
Only pools with "status": "available" are available to trade
Make sure to manually add Native $RUNE as a swappable asset.
"assetPrice" tells you the asset's price in RUNE (RUNE Depth/AssetDepth ). In the above example
1 BNB.BTCB-1DE = 11,205 RUNE
See code examples using the THORChain xchain package here https://github.com/xchainjs/xchainjs-lib/tree/master/packages/xchain-thorchain

Finding Chain Status

There are two ways to see if a Chain is halted.
  1. 1.
    Looking at the /inbound_addresses endpoint and inspecting the halted flag.
  2. 2.
    Looking at Mimir and inspecting the HALT[Chain]TRADING setting. See below for more details.