Tutorial: Order book

What is an Order book?

An orderbook is a collection of Buy and Sell orders that were originally placed using a Maker execution type.

Condition

If Algodex supports an asset then a unique orderbook exists for that asset.

Walkthrough

  1. A user is interested in the price of a particular asset so they fetch the Algodex orderbook related to that asset.

  2. The Algodex order book contains the most recent unfulfilled Buy and Sell order's related to that asset.

  3. An order remains in the order book until someone places an order using a Taker execution type.

Fetch Order book [JavaScript]

When using api.placeOrder() if an orderbook is not provided we fetch the orderbook based off the asset id specified in the order object. However, it is possible to fetch the orderbook ahead of time, as shown in the example below.

order = {
  'asset': {
    'id': 15322902,
    'decimals': 6,
  },
  'address': 'WYWRYK42XADLY3O62N52BOLT27DMPRA3WNBT2OBRT65N6OEZQWD4OSH6PI',
  'price': 3.22,
  'amount': 1,
  'execution': 'taker',
  'type': 'buy',
}


const res = await api.http.dexd.fetchAssetOrders(order.asset.id)
const orderbook = api.http.dexd.mapToAllEscrowOrders({
  buy: res.buyASAOrdersInEscrow,
  sell: res.sellASAOrdersInEscrow,
 })

await api.placeOrder(order, {orderbook})

Last updated