DeFi SDK
Search
K

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
// Python
pip install python-socketio==4.6.1

Example client code

JavaScript
Python
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);
});
import asyncio
import socketio
URI = "wss://api-v4.zerion.io"
API_TOKEN = "Demo.ukEVQp6L5vfgxcz4sBke7XvS873GMYHy"
ORIGIN = "http://localhost:3000"
sio = socketio.AsyncClient()
@sio.event
def connect():
print("I'm connected!")
@sio.event
def connect_error():
print("The connection failed!")
async def sio_connect():
await sio.connect(f"{URI}/?api_token={API_TOKEN}", headers={"Origin": ORIGIN})
if name == '__main__':
loop = asyncio.get_event_loop()
loop.create_task(sio_connect())

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
Field
Type
Default
address
str
-
addresses
list
[]
currency
PriceCurrency
usd
charts_type
str
d
charts_max_assets
int
0
charts_min_percentage
int
100
transactions_limit
int
50
transactions_offset
int
0
transactions_search_query
str
-
portfolio_fields
PortfolioFields
assets
asset_codes
list
[]
  • Messages
Scope
Result
info
AddressInfo
assets
Dict[str, AddressAsset]
portfolio
Portfolio
transactions
List[Transaction]
charts
Dict[str, List[Tuple[int, float]]]
deposits
List[Deposit]
loans
List[Loan]
locked-assets
List[LockedAsset]
staked-assets
List[StakedAsset]
bsc-assets
Dict[str, AddressBSCAsset]
polygon-assets
Dict[str, AddressPolygonAsset]

AssetsHandler (/assets)

  • Payload
Field
Type
Default
address
str
-
addresses
list
[]
asset_code
str
-
asset_codes
list
[]
currency
PriceCurrency
usd
limit
int
10000
offset
int
0
explore_section
str
-
order_by
dict
{}
charts_type
str
d
explore_sections
list
[]
category_id
str
-
explore_sections_aliases
list
[]
search_query
str
-
tags_group
str
all
  • Messages
Scope
Result
prices
Dict[str, Asset]
info
List[AssetInfo]
full-info
Optional[zerion_api.entities.socketio.AssetFullInfo]
explore-sections
List[ExploreSection]
charts
Dict[str, List[Tuple[int, float]]]
tags
List[AssetTag]
actions
List[AssetAction]
stats
AssetStats
list
List[AssetInfo]
tokenlists
List[Tokenlist]
categories
List[Category]

BlockLagHandler (/block_lag)

  • Payload
Field
Type
Default
  • Messages
Scope
Result
block-lag
BlockLag

CompoundHandler (/compound)

  • Payload
Field
Type
Default
address
str
-
currency
PriceCurrency
usd
  • Messages
Scope
Result
info
CompoundInfo
assets
List[CompoundAsset]
actions
List[CompoundAction]
deposits
List[CompoundDeposit]
loans
List[CompoundLoan]

DyDxHandler (/dydx)

  • Payload
Field
Type
Default
address
str
-
currency
PriceCurrency
usd
  • Messages
Scope
Result
deposits
List[DyDxAccountBalance]
loans
List[DyDxAccountBalance]

GasPriceHandler (/gas)

  • Payload
Field
Type
Default
  • Messages
Scope
Result
price
GasPriceInfo

MakerHandler (/maker)

  • Payload
Field
Type
Default
cdp_id
str
-
vault_id
str
-
currency
PriceCurrency
usd
  • Messages
Scope
Result
cdp
MakerCDP
vault
MakerVault
cdp-actions
List[MakerCDPAction]
vault-actions
List[MakerVaultAction]

Models

AddressAsset

Name
Type
Optional
asset
Asset
quantity
str

AddressBSCAsset

Name
Type
Optional
asset
CovalentAsset
quantity
str

AddressInfo

Name
Type
Optional
address
str
type
str
proxies
str
yes
cdps
int
yes
vaults
int
yes
aggregated_at
int
yes

AddressPolygonAsset

Name
Type
Optional
asset
CovalentAsset
quantity
str

Asset

Name
Type
Optional
asset_code
str
name
str
symbol
str
decimals
int
type
AssetType
icon_url
str
yes
price
Price
yes
is_displayable
bool
is_verified
bool

AssetAction

Name
Type
Optional
id
str
transaction_hash
str
type
AssetActionType
value
float
yes
quantity
str
price
float
yes
datetime
int
asset
Asset
status
TransactionStatus
direction
Direction
fee
AssetActionFee
yes

AssetActionAmount

Name
Type
Optional
base
float
currency
float
yes

AssetActionFee

Name
Type
Optional
quantity
str
value
float

AssetComponent

Name
Type
Optional
asset
Asset
quantity
float
share
float
allocation
float

AssetDescription

Name
Type
Optional
asset_code
str
full
str
yes

AssetFullInfo

Name
Type
Optional
asset
Asset
title
str
stats
AssetFullInfoStats
components
str
yes
gradient_color
str
yes
explore_sections
int
yes
subtitle
str
yes
tagline
str
yes
market_cap
float
yes
fully_diluted_valuation
float
yes
total_supply
float
yes
circulating_supply
float
yes
relative_changes
str
yes
description
str
yes
relevant_resources
AssetRelevantResource
yes
tags
str
yes
is_tradable
bool

AssetFullInfoStats

Name
Type
Optional
asset_code
str
year_min
float
yes
year_max
float
yes
volume_24h
float
yes

AssetInfo

Name
Type
Optional
asset
Asset
title
str
gradient_color
str
yes
explore_sections
int
yes
subtitle
str
yes
tagline
str
yes
market_cap
float
yes
total_supply
float
yes
circulating_supply
float
yes
relative_changes
str
yes
tags
str
yes

AssetRelevantResource

Name
Type
Optional
name
str
url
str
displayable_name
str
yes

AssetStats