On-chain Data
Reading spot markets and orders straight from the DEX contract tables.
Markets and orders can be read directly from the DEX contract with any node API, without Alcor's servers. The table layouts are described in Contract tables.
The DEX contract per chain:
| Chain | DEX contract |
|---|---|
| WAX | alcordexmain |
| EOS | eostokensdex |
| Telos | eostokensdex |
| XPR | alcor |
Markets
Markets are stored in the markets table, with the contract itself as scope.
cleos -u https://wax.greymass.com get table alcordexmain alcordexmain marketsimport { JsonRpc } from 'eosjs'
const rpc = new JsonRpc('https://wax.greymass.com', { fetch })
const { rows } = await rpc.get_table_rows({
code: 'alcordexmain', // DEX contract
scope: 'alcordexmain', // same as the contract
table: 'markets',
limit: 1000,
}){
"rows": [
{
"id": 0,
"base_token": { "sym": "8,WAX", "contract": "eosio.token" },
"quote_token": { "sym": "4,PGL", "contract": "prospectorsw" },
"min_buy": "0.00000100 WAX",
"min_sell": "0.0001 PGL",
"frozen": 0,
"fee": 0
}
],
"more": true
}The contract names the sides the other way round from the API: its base_token is the API's target (the token
prices are quoted in) and its quote_token is the API's base.
| Field | Description |
|---|---|
| id | Market id: the scope of the market's order tables, and the market_id of the API tickers |
| base_token | Target token: the token prices are quoted in |
| quote_token | Base token: the token being traded |
| min_buy | Smallest buy order |
| min_sell | Smallest sell order |
| frozen | 1 when trading is frozen |
| fee | Market fee in hundredths of a percent |
Orders
Orders are stored in the buyorder and sellorder tables, with the market id as scope.
cleos -u https://wax.greymass.com get table alcordexmain 26 buyorder -l 2const { rows } = await rpc.get_table_rows({
code: 'alcordexmain',
scope: 26, // market id
table: 'buyorder', // or 'sellorder'
key_type: 'i128',
index_position: 2, // secondary index: sorted by price
limit: 1000,
}){
"rows": [
{
"id": 28,
"account": "pxawpxawpxaw",
"bid": "10.00000000 WAX",
"ask": "1999.9560 TLM",
"unit_price": "500012",
"timestamp": 1603653505
}
],
"more": true,
"next_key": "558"
}| Field | Description |
|---|---|
| id | Order id, used to cancel the order |
| account | Order owner |
| bid | What the order offers |
| ask | What the order wants in return |
| unit_price | Price as an integer: the price in target per base multiplied by 10^8 |
| timestamp | Order creation time, unix seconds |