Alcor
Search…
Node API
Description on interact directly with node api
Alcor Exchange provides an API for the UI view reasons charts/lates deals/orderbook. etc. But any intereation with blockchain, such as new order or order cancel, we have to work with blockchain now api directly, here we will provide some examples.
We will use EosJS lib to interact with node api. And will use WAX blockchain as example.

Submit new order.

1
// Code not tested yet, and provided for explanation reason
2
3
import fetch from 'node-fetch'
4
import { Api, JsonRpc, RpcError, JsSignatureProvider } from 'eosjs'
5
6
const rpc = new JsonRpc('https://wax.greymass.com', { fetch })
7
const signatureProvider = new JsSignatureProvider(['private key of order owner'])
8
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
9
10
// Place buy limit order, buying 1000 TLM for 10 WAX
11
const objTrans = [{
12
account: 'eosio', // token contract
13
name: 'transfer',
14
authorization: [{
15
actor: 'useraaaaaaaa', // account placing order (owner)
16
permission: 'active',
17
}],
18
data: {
19
from: 'useraaaaaaaa',
20
to: 'alcordexmain',
21
quantity: `10.0000 WAX`,
22
memo: `1000.0000 [email protected]`
23
}
24
}]
25
26
// Result of transaction
27
const r = await api.transact(objTrans, { blocksBehind: 3, expireSeconds: 30})
Copied!

Get order from contract table.

1
// Code not tested yet, and provided for explanation reason
2
3
import fetch from 'node-fetch'
4
import { Api, JsonRpc, RpcError } from 'eosjs'
5
6
const rpc = new JsonRpc('https://wax.greymass.com', { fetch })
7
8
// Get buy orderbook from conract table
9
10
const { rows } = await rpc.get_table_rows({
11
code: 'alcordexmain',
12
table: 'buyorder',
13
limit: 1000,
14
scope: 29, // Market id from /api/markets
15
key_type: 'i128', // we are using it for getting order sorted by price.
16
index_position: 2
17
})
18
Copied!
Copy link
Contents