Onboarding information for Arbitrageurs, Algo, Convergence and Pro-Traders

The EMDX team created this guide to help market makers, liquidity providers, and arbitrageurs get started. Please read the entire document before beginning any integration steps.

To get access to EMDX's API repository and perpetual API, fill out the form with the information requested and the team will contact you with the access. Remember to specify whether you want to interact with mainnet, testnet, or both, as the access tokens differ.

You can also request testnet AVAX to interact with the Fuji C chain via Avalanche's official faucet https://faucet.avax-test.network/. If you require testnet USDC, please contact us via Discord or Telegram.

Endpoints structure

EMDX has three types of endpoints:

  • Read only: This type of endpoint enables the trader to obtain information about the pairs, markets, funding, and so on. For example: - All /markets endpoints - All /trader endpoints - All /calculations endpoints - /metadata endpoints - /position/open/calculate - /position/read

  • Transaction creation: This type of endpoints returns all the data needed to sign and send the transaction. For example: - /allowance/add - /allowance/remove - /position/open - /position/close

  • Transaction broadcast: This is the endpoint /transaction/send. This route broadcasts the signed transaction to the blockchain.

Interact with the API: Step-by-step tutorial

This example is based on the BTC/USDC pair in testnet. In order to get started you need to have a testnet API token and authenticate on the Authorize section in Swagger. The execution endpoints like allowance or open/close position returns all the data needed to sign and broadcast the transaction. You can check an example of signing a transaction here.

Open a position

  1. Add allowance in the following allowance endpoint passing the address of the trader.

  2. After signing the allowance transaction, broadcast it to the network with send endpoint.

  3. This step is optional, but if you want to know more about the trade you're about to execute, such as the entry price, fee, etc; you can use the calculate endpoint.

  4. Get the open transaction data with the open endpoint.

  5. After signing the open transaction, broadcast it to the network with send endpoint.

  6. You can read the position data with the read endpoint.

Close a position

  1. In order to close an open position just execute the close endpoint, sign the transaction and broadcast it.

Example with scripts

EMDX developed a set of scripts to help users on-boarding the API usage. For this tutorial, we will use the JS example, but the same scripts are available in Python:

  1. Clone the repository

  2. Navigate to nodejs folder

  3. Copy the .env.example to .env

  4. Fill the environment variables

Open a position

  1. To open the position, you must first add allowance so that the clearing house contract can use the collateral. You have to use the add-allowance.js script.

  2. After you added the allowance, you can open the position with the open-position.js. Simply change the pair you want to operate and some parameters such as collateral, leverage, slippage, etc.

  3. If you do want to read the position information, you can use the /position/read endpoint.

Close a position

  1. To close a position you can use the close-position.js script.

Last updated