Skip to main content

Documentation Index

Fetch the complete documentation index at: https://hypernode-docs.polynode.dev/llms.txt

Use this file to discover all available pages before exploring further.

Install

npm install ws

Basic connection

import WebSocket from "ws";

const ws = new WebSocket("wss://hyper.polynode.dev/ws?key=pn_live_YOUR_KEY");

ws.on("open", () => {
  // Subscribe to orders and fills
  ws.send(JSON.stringify({
    action: "subscribe",
    filters: { action_types: ["order", "fill"] }
  }));
});

ws.on("message", (raw) => {
  const event = JSON.parse(raw.toString());

  // Skip protocol messages
  if (event.action) return;

  // Every event has a consensus field
  const layer = event.consensus; // "pre" or "confirmed"

  if (event.type === "order") {
    const d = event.data;
    console.log(
      `[${layer}] ORDER ${event.asset} ${d.side === "B" ? "BUY" : "SELL"} ${d.sz}@${d.px} [${d.tif}]`
    );
  }

  if (event.type === "fill") {
    const d = event.data;
    console.log(
      `[${layer}] FILL ${event.asset} ${d.side === "B" ? "BUY" : "SELL"} ${d.sz}@${d.px} ${d.dir} PnL=${d.closedPnl}`
    );
  }
});

ws.on("close", () => console.log("Disconnected"));
ws.on("error", (err) => console.error("Error:", err.message));

Track a wallet

ws.send(JSON.stringify({
  action: "subscribe",
  id: "whale-tracker",
  filters: {
    addresses: ["0xd071d6d6ea52f5aa34b79e47f908ee48c8215837"]
  }
}));

Pre-consensus cancel detection

ws.send(JSON.stringify({
  action: "subscribe",
  id: "early-cancels",
  filters: {
    action_types: ["cancel", "cancelByCloid", "batchModify"],
    assets: ["BTC", "ETH"]
  }
}));

ws.on("message", (raw) => {
  const event = JSON.parse(raw.toString());
  if (event.action) return;

  if (event.consensus === "pre") {
    console.log(`PRE-CONSENSUS: ${event.type} on ${event.asset} by ${event.user?.slice(0, 10)}`);
  }
});

L4 Order Book (REST)

const resp = await fetch("https://hyper.polynode.dev/v2/l4book?coin=BTC", {
  headers: { "x-api-key": "pn_live_YOUR_KEY" }
});
const book = await resp.json();

console.log(`BTC: ${book.bid_count} bids, ${book.ask_count} asks`);

// Find the largest order
const allOrders = [...book.bids, ...book.asks];
const biggest = allOrders.reduce((max, o) =>
  parseFloat(o.sz) > parseFloat(max.sz) ? o : max
);
console.log(`Largest: ${biggest.sz}@${biggest.limitPx} by ${biggest.user}`);

Multiple subscriptions

// Track BTC orders
ws.send(JSON.stringify({
  action: "subscribe",
  id: "btc",
  filters: { action_types: ["order", "fill"], assets: ["BTC"] }
}));

// Track ETH pre-consensus
ws.send(JSON.stringify({
  action: "subscribe",
  id: "eth-pre",
  filters: { action_types: ["cancel", "batchModify"], assets: ["ETH"] }
}));

// Unsubscribe from ETH later
ws.send(JSON.stringify({ action: "unsubscribe", id: "eth-pre" }));