Connection

Due to the huge volume of data for select datasets, please use the following dedicated URLs when subscribing to these types of data:

SubscriptionConnection URL
market:futures:funding_rates
market:futures:insurance_funds
market:futures:liquidations
market:futures:long_short_ratios
market:futures:ohlcv
market:futures:open_interests
market:futures:order:events
market:futures:order:snapshots
market:futures:tickers
market:futures:trades
wss://ws.amberdata.com/futures
market:options:liquidations
market:options:ohlcv
market:options:open_interests
market:options:order:events
market:options:order:snapshots
market:options:tickers
market:options:trades
wss://ws.amberdata.com/options
market:spot:ohlcv
market:spot:order:events
market:spot:order:snapshots
market:spot:tickers
market:spot:trades
wss://ws.amberdata.com/spot
market:dex:tradeswss://ws.web3api.io/defi/dex
*any other subscriptionwss://ws.web3api.io

In order to establish a connection between client and server an initial http handshake is required. This is known as subscribing. Subscription requests are performed using JSON-RPC, similar to Geth and Parity.

All subscriptions follow the same pattern, let's first cover what all websocket subscription endpoints share in common before diving into the types of subscriptions and their response formats. To explore these API's, we will use the npm-provided command wscat, but any websocket-client library will work.

Note: If a valid API key is not found in the initial request you will receive a response invalid api key '<api_key>' and the websocket connection will be closed. If you don't have an API Key at this time please see Authentication for more details on obtaining one.

You may optionally include a blockchain-id with the request. If no blockchain id is supplied then it will default to ethereum-mainnet. Refer to the Blockchain Id to obtain a list of blockchain ids.

First, connect to the correct Amberdata endpoint via SSL websocket with your API key:

Connecting

❯ npm install -g wscat
❯ wscat -c "wss://ws.web3api.io" -H "x-api-key: <api-key>" -H "x-amberdata-blockchain-id: ethereum-mainnet"
connected (press CTRL+C to quit)
> 

You are now connected and ready to initiate any websocket request.