const WebSocket = require('ws');
function urlencode(options) {
return encodeURIComponent(JSON.stringify(options))
'channel': "deribit.BTC-PERPETUAL.trade",
const url = `wss://pro.cryptostats.dev:8443?options=${urlencode(subscription)}`
const ws = new WebSocket(url)
ws.on('open', function open() {
ws.on('close', function incoming(data) {
ws.on('message', function incoming(data) {
// Helper Functions for subscribing to new channels
async function send(action, channel){
ws.send(JSON.stringify(message))
async function subscribe(channel){
send("subscribe", channel)
async function unsubscribe(channel){
send("unsubsribe", channel)