Alcor
  • Alcor.exchange
  • What is Alcor Exchange?
  • Home Page Overview
    • Swap
      • Swap Charts
      • Add Liquidity
      • Manage Liquidity
    • Markets
      • Market Exchange
        • Order Books
        • Graph
        • Open Orders
        • Placing Trades
    • OTC
    • NFT
    • Wallet
  • Developers API
    • Amm Swap Contract API
      • Formulas
      • Contracts
      • Examples
    • Market creation
      • Open new market
    • Contract actions
    • Contract Tables
    • API
      • Markets API
      • Account
      • WebSocket
      • Node API
    • Public Alcor Data Access
  • Alcor Swap
    • Referral / Custom Market Fee
    • Introduction
    • Swap Page
    • Locking Liquidity
    • Providing liquidity
      • How to Add Liquidity on Alcor Exchange
    • Ranges: Everything you need to know
      • How to set a Range for your Liquidity position
    • Pool Page
    • Liquidity Provider FAQ
    • Concentrated liquidity FAQ
    • AlcorSwap v2 Price Oracles
      • Alcor Price Oracle vs DelphiOracle
      • Expanding Price Availability with RAM Purchase
      • How to Use Alcor Price Oracle
  • Alcor Farms: Unlocking DeFi Opportunities
    • Creating Farm Incentives - Quick Tutorial
    • Project Farms Unique Link
    • Technical details
  • LSW- Liquid Staked WAX
    • How it works
    • Exchange rate
    • Withdrawal process
  • Adding Token Information
    • Token logo
    • USD Price
  • Swap Widget
    • Swap Chart Widget
  • Networks Features
    • WAX
      • Alcor USDT
  • Additional Docs
  • Definitions
  • FAQ
    • Does Alcor Exchange Have Fees?
    • Whats the difference between using Swap, Market Trade, and OTC?
    • What is a liquidity Pool?
  • Social Media/Contact
Powered by GitBook
On this page

Was this helpful?

  1. Developers API
  2. API

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.

// Code not tested yet, and provided for explanation reason

import fetch from 'node-fetch'
import { Api, JsonRpc, RpcError, JsSignatureProvider } from 'eosjs'

const rpc = new JsonRpc('https://wax.greymass.com', { fetch })
const signatureProvider = new JsSignatureProvider(['private key of order owner'])
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });

// Place buy limit order, buying 1000 TLM for 10 WAX
const objTrans = [{
  account: 'eosio', // token contract
  name: 'transfer',
  authorization: [{
    actor: 'useraaaaaaaa', // account placing order (owner)
    permission: 'active',
  }],
  data: {
    from: 'useraaaaaaaa',
    to: 'alcordexmain',
    quantity: `10.0000 WAX`,
    memo: `1000.0000 TLM@alien.worlds`
  }
}]

// Result of transaction
const r = await api.transact(objTrans, { blocksBehind: 3, expireSeconds: 30})

Get order from contract table.

// Code not tested yet, and provided for explanation reason

import fetch from 'node-fetch'
import { Api, JsonRpc, RpcError } from 'eosjs'

const rpc = new JsonRpc('https://wax.greymass.com', { fetch })

// Get buy orderbook from conract table

const { rows } = await rpc.get_table_rows({
  code: 'alcordexmain',
  table: 'buyorder',
  limit: 1000,
  scope: 29, // Market id from /api/markets
  key_type: 'i128', // we are using it for getting order sorted by price.
  index_position: 2
})
PreviousWebSocketNextPublic Alcor Data Access

Last updated 3 years ago

Was this helpful?