AlcorDocs

Trade API

Placing and cancelling spot orders with contract actions.

The HTTP API only reads data. Orders are placed and cancelled by sending transactions to the DEX contract through any node API, signed by the order owner. The examples use eosjs and the WAX contract alcordexmain; the contract of each chain is listed in On-chain Data.

import { Api, JsonRpc } from 'eosjs'
import { JsSignatureProvider } from 'eosjs/dist/eosjs-jssig'

const rpc = new JsonRpc('https://wax.greymass.com', { fetch })
const signatureProvider = new JsSignatureProvider(['<private key of the order owner>'])
const api = new Api({ rpc, signatureProvider })

Place order

Transfer the amount you sell (the bid) to the DEX contract, with the amount you want in return (the ask) in the memo. The contract finds the market and the price from the two tokens and amounts, fills what it can against the opposite side, and leaves the rest as an open order.

Memo format: <amount> <SYMBOL>@<contract>, e.g. 0.0010 EOS@eosio.token.

# bob sells 0.5 TKT for 0.001 EOS
cleos push action tktoken transfer \
  '["bob", "alcordexmain", "0.5000 TKT", "0.0010 EOS@eosio.token"]' -p bob@active
await api.transact({
  actions: [{
    account: 'tktoken',            // contract of the token you sell
    name: 'transfer',
    authorization: [{ actor: 'bob', permission: 'active' }],
    data: {
      from: 'bob',
      to: 'alcordexmain',
      quantity: '0.5000 TKT',      // bid
      memo: '0.0010 EOS@eosio.token' // ask
    }
  }]
}, { blocksBehind: 3, expireSeconds: 30 })

Several orders can be placed in one transaction, one transfer action each.

Orders cannot be changed. To move an order, cancel it and place a new one.

Cancel order

Call cancelbuy for a buy order or cancelsell for a sell order on the DEX contract.

ParameterDescription
executorOrder owner
market_idMarket id of the order
order_idOrder id
# bob cancels sell order 1284277 on market 262
cleos push action alcordexmain cancelsell '["bob", 262, 1284277]' -p bob@active
await api.transact({
  actions: [{
    account: 'alcordexmain',
    name: 'cancelsell',            // or 'cancelbuy'
    authorization: [{ actor: 'bob', permission: 'active' }],
    data: {
      executor: 'bob',
      market_id: 262,
      order_id: 1284277
    }
  }]
}, { blocksBehind: 3, expireSeconds: 30 })

Find order ids in the buyorder and sellorder tables (On-chain Data).

On this page