The Coinpaprika async API.
Example node client:
import WebSocket from "ws";
try {
const ws = new WebSocket("wss://streaming.coinpaprika.com/ticks", {
headers: {
Authorization: "API-TOKEN",
},
});
const pingInterval = 120;
const subscribePayload = {
event: "subscribe",
ids: ["btc-bitcoin", "eth-ethereum" ],
quotes: ["BTC", "USD"]
};
let heartbeat: NodeJS.Timeout;
ws.on("open", () => {
heartbeat = setTimeout(
(ws: WebSocket) => {
ws.terminate();
},
2 * pingInterval * 1000,
ws
);
ws.send(JSON.stringify(subscribePayload));
});
ws.on("ping", () => {
clearTimeout(heartbeat);
});
ws.on("message", (data) => {
console.log(data.toString());
});
ws.on("error", (err) => {
console.log(`error on ws ${err}`);
});
} catch (e) {
console.log("no websocket srv");
}
Production api with ticker data
Accepts the following message:
Subscribe to a topic on a single or multiple currencies.
{
"event": "subscribe",
"ids": [
"btc-bitcoin",
"eth-ethereum"
],
"quotes": [
"USD",
"BTC"
]
}
{
"event": "unsubscribe",
"ids": [
"btc-bitcoin",
"eth-ethereum"
]
}
Messages that you receive from the API
Available only on servers:
Accepts the following message:
{
"id": "cfx-conflux-network",
"sym": "CFX",
"ts": 1676916987,
"quotes": {
"USD": {
"m": 608286188,
"p": 0.2909436491331033,
"v24h": 801851299.5519149
}
}
}
Ping server to determine whether connection is alive
Client can ping server to determine whether connection is alive, server responds with pong. This is an application level ping as opposed to default ping in websockets standard which is server initiated
Pong is a response to ping message
Server pong response to a ping to determine whether connection is alive. This is an application level pong as opposed to default pong in websockets standard which is sent by client in response to a ping
Subscribe to a topic on a single or multiple currencies.
Client originated ID reflected in response message.