Zerion API

This is a socket-based interactive api based on the Socket.io library.

Installation

Please, make sure to use Socket.io v2 client API.

// Javascript
npm i socket.io-client@2.4.0
// Python
pip install python-socketio==4.6.1

Example client code

import io from 'socket.io-client';

const FALLBACK_URL = 'wss://api-v4.zerion.io/';
const BASE_URL = process.env.API_URL || FALLBACK_URL;

function verify(request, response) {
  // each value in request payload must be found in response meta
  return Object.keys(request.payload).every(key => {
    const requestValue = request.payload[key];
    const responseMetaValue = response.meta[key];
    if (typeof requestValue === 'object') {
      return JSON.stringify(requestValue) === JSON.stringify(responseMetaValue);
    }
    return responseMetaValue === requestValue;
  });
}

const assetsSocket = {
  namespace: 'assets',
  socket: io(`${BASE_URL}assets`, {
    transports: ['websocket'],
    timeout: 60000,
    query: {
      api_token:
        process.env.ZERION_API_KEY_V4 ||
        'Demo.ukEVQp6L5vfgxcz4sBke7XvS873GMYHy',
    },
  }),
};

function get(socketNamespace, requestBody) {
  return new Promise(resolve => {
    const { socket, namespace } = socketNamespace;
    function handleReceive(data) {
      if (verify(requestBody, data)) {
        unsubscribe();
        resolve(data);
      }
    }
    const model = requestBody.scope[0];
    function unsubscribe() {
      socket.off(`received ${namespace} ${model}`, handleReceive);
      socket.emit('unsubscribe', requestBody);
    }
    socket.emit('get', requestBody);
    socket.on(`received ${namespace} ${model}`, handleReceive);
  });
}

get(assetsSocket, {
  scope: ['info'],
  payload: {
    explore_section: 1,
    currency: 'usd',
    offset: 0,
    limit: 20,
  },
}).then(response => {
  console.log(response.payload.info);
});

Overview

In order to connect, a valid api_token query parameter must be specified.All tokens are restricted by Origin and therefore a valid HTTP_ORIGIN header is expected.

let io_options = {transports: ['websocket'], query: {api_token: 'YOUR API TOKEN'}};
socket = io('wss://api.zerion.io', io_options);

Actions

There are three supported types of messages:

  • get - requests data, returns a single response and does not emit continuous messages

  • subscribe - returns a single response (the same as get) + creates a subscription

  • unsubscribe - deletes the subscription

Request

Each request has the following structure:

[
    "{action}",
    {
      "scope": ["scope1", "scope2"],
      "payload": {
          "parameter1": "value1",
          "parameter2": "value2"
      }
    }
]

Response

[ 
    "received {namespace} {model}",
    {
       "meta": {
           "status": "ok",
           "request parameter1": "value1",
           "request parameter2": "value2"
       },
       "payload": {
           "{scope}": "__result__"
       }
    }
]

Change

[ 
    "changed|appended|removed {namespace} {model}",
    {
       "meta": {
           "subscription parameter1": "value1",
           "subscription parameter2": "value2"
       },
       "payload": {
           // changed model
       }
    }
]

Handlers

AddressHandler (/address)

  • Payload

  • Messages

AssetsHandler (/assets)

  • Payload

  • Messages

BlockLagHandler (/block_lag)

  • Payload

  • Messages

CompoundHandler (/compound)

  • Payload

  • Messages

DyDxHandler (/dydx)

  • Payload

  • Messages

GasPriceHandler (/gas)

  • Payload

  • Messages

MakerHandler (/maker)

  • Payload

  • Messages

Models

AddressAsset

AddressBSCAsset

AddressInfo

AddressPolygonAsset

Asset

AssetAction

AssetActionAmount

AssetActionFee

AssetComponent

AssetDescription

AssetFullInfo

AssetFullInfoStats

AssetInfo

AssetRelevantResource

AssetStats

AssetTag

BlockLag

Category

CompoundAction

CompoundAsset

CompoundDeposit

CompoundInfo

CompoundLoan

CovalentAsset

Deposit

DyDxAccountBalance

ExploreSection

GasPriceInfo

Loan

LockedAsset

MakerCDP

MakerCDPAction

MakerVault

MakerVaultAction

Portfolio

Price

PriceStat

StakedAsset

Tokenlist

Transaction

TransactionChange

TransactionFee

Structures

AssetType

  • aave

  • aave-uniswap

  • aave-v2

  • alpha-homora

  • badger-sett

  • balancer

  • bancor

  • bitcoin

  • cream

  • curve

  • compound

  • dmm

  • dodo

  • dodo-v2

  • enzyme

  • ethereum

  • fulcrum

  • harvest-vault

  • idle

  • iearn-curve

  • iearn-v2

  • iearn-v3

  • indexed

  • keeperdao

  • maker

  • melon

  • mooniswap

  • mstable

  • mushroom-vault

  • nft

  • one-inch

  • pickle-jar

  • piedao-pool

  • pool-together

  • realt

  • snowswap

  • stablecoin

  • synthetix

  • sushi

  • swerve

  • tokenset

  • tokenset-v2

  • trash

  • uniswap

  • uniswap-v2

  • xsushi

  • yearn-vault

  • yearn-vault-v2

  • None

    TransactionStatus

  • confirmed

  • failed

  • pending

    MakerDSSActionType

  • open

  • deposit

  • withdraw

  • borrow

  • repay

  • transfer

  • liquidate

    TransactionAction

  • Authorize

  • Trade

  • Deposit

  • Withdraw

  • Borrow

  • Repay

  • Liquidate

  • Enable Borrowing

  • Open CDP

  • Close CDP

  • Transfer CDP

  • Migrate CDP

  • Open Vault

  • Close Vault

  • Transfer Vault

  • Migrate

  • Create Exchange

  • Add Liquidity

  • Remove Liquidity

  • Stake

  • Unstake

  • Claim Rewards

  • Register ENS Domain

  • Renew ENS Domain

    PriceCurrency

  • eth

  • btc

  • usd

  • eur

  • krw

  • rub

  • gbp

  • aud

  • cad

  • inr

  • jpy

  • nzd

  • try

  • zar

  • cny

  • chf

    RDBTransactionType

  • send

  • receive

  • trade

  • authorize

  • execution

  • deployment

  • cancel

  • deposit

  • withdraw

  • borrow

  • repay

  • stake

  • unstake

  • claim

    CategoryDisplayType

  • short

  • detailed

    Direction

  • in

  • out

  • self

    PortfolioFields

  • all

  • assets

    AssetActionType

  • buy

  • sell

  • send

  • receive

  • borrow

  • deposit

  • authorize

  • withdraw

  • repay

  • stake

  • unstake

  • claim

    GasPriceSource

  • gas-now

  • eth-gas-station

Last updated