order/structure

Methods

# (async, static) getMakerTakerOrders(api, order) → {Promise.<Array.<Order>>}

🏃 getMakerTakerTxns

This method represents the synthesis of two execution types: Maker and Taker and is represented as "Both".

It first fetches TakerTxns using getTakerOrders . If there is a remainder, it concats the return of getTakerOrders and the return of withMakerTxns.

Scenarios:

  1. There are no Taker orders that meet the criteria.
  1. There are taker orders and no remainder.
  1. There are taker orders with a remainder

When is it used?

This execution type is mainly used with our frontend. Since getMakerTakerTxns is robust enough to handle both order types, it acts as a catch all method for placing orders with a UI.

If you are planning on integrating Algodex's service into your own UI this is a good method to facillate placing of orders. The more granular methods are beneficial for algorithmic trading strategies.

Parameters:
Name Type Description
api AlgodexApi

The Algodex API

order Order

The Order from the User

See:
  • withExecuteAssetTxns || withExecuteAlgoTxns || withPlaceAssetTxns || withPlaceAlgoTxns

Throws:

ValidationError

Returns:

A promise of all compiled and structured Orders

Type
Promise.<Array.<Order>>
Example
const AlgodexAPI = require(@algodex/algodex-sdk)
const api = new AlgodexAPI(require('../config.json'))
const order = {
  "client": api.algod,
  "indexer": api.indexer,
  "asset": {
    "id": 15322902,
    "decimals": 6,
  },
  "address": "TJFFNUYWHPPIYDE4DGGYPGHWKGAPJEWP3DGE5THZS3B2M2XIAPQ2WY3X4I",
  "price": 2.22,
  "amount": 1,
  "total": 2,
  "execution": "both",
  "type": "buy",
  "appId": 22045503,
  "version": 6
}

let res = await getTakerOrders(api, order)
console.log(res.contract.txns)
//Outputs an array with items being some combination of the below :
withExecuteAssetTxns || withExecuteAlgoTxns || withPlaceAssetTxns  || withPlaceAlgoTxns

# (async, static) getMakerTxns(order, optInopt) → {Promise.<Array.<Structure>>}

🏃 getMakerTxns

Determines which maker generator to use depending on the order type.

Parameters:
Name Type Attributes Default Description
order Order

The Maker Order

optIn boolean <optional>
false
Returns:
Type
Promise.<Array.<Structure>>

# (async, static) getTakerOrders(api, order) → {Promise.<Array.<Structure>>}

  • 🏃 getTakerOrders

Accepts an Order with execution of Taker and matches the criteria with Executable orders in the Orderbook.

If executable orders exist then the relevant transactions are generated.

The generated transactions fall into one of the two categories below:

SingleOrderExecution

Condition: For when the desired user "total" amount is less than the available escrow amount

  • Example: There is an order in the orderbook at the user's desired price and desired amount

Return value: An array of length=1 containing Order object with an txnArr attached to the contract

MultiOrderExececution

Condition: For when the desired user total amount is greater than the available escrow amount

  • Example: There are multiple orders in the orderbook at the user's desired price, but no entry contains the user's desired amount.

Return value: An array of variable length. Each item represents a group of transactions.

When is it used?

This method and the corresponding factories are used anytime a user is executing upon an existing Algodex Orderbook Order.

This method is used to generate the taker transactions in getMakerTakerTxns

This method would be ideal for use in algorithmic trading strategies.

Parameters:
Name Type Description
api AlgodexApi

The Algodex API

order Order

The User's Order

See:
Throws:

ValidationError

Returns:
Type
Promise.<Array.<Structure>>
Examples
const AlgodexAPI = require(@algodex/algodex-sdk)
const api = new AlgodexAPI(require('../config.json'))
const order = {
  "client": api.algod,
  "indexer": api.indexer,
  "asset": {
    "id": 15322902,
    "decimals": 6,
  },
  "address": "TJFFNUYWHPPIYDE4DGGYPGHWKGAPJEWP3DGE5THZS3B2M2XIAPQ2WY3X4I",
  "price": 2.22,
  "amount": 1,
  "total": 2,
  "execution": "taker",
  "type": "buy",
  "appId": 22045503,
  "version": 6
}

// Scenario: singleOrder
//order.execution === 'taker'
let res = await getTakerOrders(api, order)
console.log(res.contract.txns)
//Outputs an array with structure of:
makeExecuteAssetTxns || makeExecuteAlgoTxns
const AlgodexAPI = require(@algodex/algodex-sdk)
const api = new AlgodexAPI(require('../config.json'))
const order = {
  "client": api.algod,
  "indexer": api.indexer,
  "asset": {
    "id": 15322902,
    "decimals": 6,
  },
  "address": "TJFFNUYWHPPIYDE4DGGYPGHWKGAPJEWP3DGE5THZS3B2M2XIAPQ2WY3X4I",
  "price": 2.22,
  "amount": 1,
  "total": 2,
  "execution": "taker",
  "type": "buy",
  "appId": 22045503,
  "version": 6
}
// Scenario: multiOrder
//order.execution === 'taker'
let res = await getTakerOrders(api, order)
console.log(res)
//Outputs an array with each item being:
withExecuteAssetTxns || withExecuteAlgoTxns

# (async, static) withMakerTxns(api, order) → {Promise.<Order>}

🔗 withMakerTxns

Accepts an Order with execution type Maker and generates the relevant transactions.

Existing Escrow (Only relevant for makePlaceAlgo )

When a user places a maker order, we first check to see if the Algodex Orderbook already has an Order entry at that price, from that User.

  • If that order exists, we generate a set of transactions that adds to the existing order.
  • If the order does not exist, we generate a set of transactions to create a new maker order.

You can learn more about the differences between the two types of transactions in the trasnaction table for makePlaceAlgoTxns factory.

When is it used?

This method and the corresponding Factory is used anytime a Maker order is added to the Algodex Orderbook.

This method is the maker leg of getMakerTakerTxns.

This method would be ideal for use in algorithmic trading strategies and for programmaticaly providing liquidity to the Algodex Orderbook

Parameters:
Name Type Description
api Api

Instance of AlgodexApi

order Order

The User's Order

See:
Returns:
Type
Promise.<Order>
Example
const AlgodexAPI = require(@algodex/algodex-sdk)
const api = new AlgodexAPI(require('../config.json'))
const order = {
  "client": api.algod,
  "indexer": api.indexer,
  "asset": {
    "id": 15322902,
    "decimals": 6,
  },
  "address": "TJFFNUYWHPPIYDE4DGGYPGHWKGAPJEWP3DGE5THZS3B2M2XIAPQ2WY3X4I",
  "price": 2.22,
  "amount": 1,
  "total": 2,
  "execution": "maker",
  "type": "buy",
  "appId": 22045503,
  "version": 6
}
const {compile} = require(@algodex/algodex-sdk/order)

//order.execution === 'maker'
let res = await withMakerTxns(api, await compile(order))
console.log(res.contract.txns)
//Outputs:
makePlaceAlgoTxns || makePlaceAssetTxns

# (async, inner) structure(api, order) → {Promise.<Array.<Order>>}

🏗 Structure Order

🏗    Takes an Order and structures the underlying transactions

🎚    Structure switches based on the execution property of the Order

💽    The structured transactions are stored in the contract property under txns

When is it used?

This method is what enables [AlgodexApi.placeOrder]{#placeOrder} to handle every execution and order type

Parameters:
Name Type Description
api AlgodexApi

AlgodexApi Instance

order Order

The compiled Order Object

Returns:

Array of structured Order Objects

Type
Promise.<Array.<Order>>
Example
const {AlgodexApi} = require('@algodex/sdk')
const order = structure(new AlgodexApi(), {
  "client": new algosdk.Algodv2(),
  "asset": {
    "id": 15322902,
    "decimals": 6,
  },
  "address": "TJFFNUYWHPPIYDE4DGGYPGHWKGAPJEWP3DGE5THZS3B2M2XIAPQ2WY3X4I",
  "price": 2.22,
  "amount": 1,
  "total": 2,
  "execution": "maker",
  "type": "buy",
  "appId": 22045503,
  "version": 6
})
// Outputs Array of Objects with txns attached to contract property