import WebSocket from "ws";
const ws = new WebSocket("wss://hyper.polynode.dev/ws?key=pn_live_YOUR_KEY");
const ASSETS = ["BTC", "ETH", "SOL", "HYPE", "DOGE"];
const stats: Record<string, { orders: number; fills: number; volume: number }> = {};
for (const a of ASSETS) stats[a] = { orders: 0, fills: 0, volume: 0 };
ws.on("open", () => {
for (const asset of ASSETS) {
ws.send(JSON.stringify({
action: "subscribe",
filters: { assets: [asset], action_types: ["order", "fill"] }
}));
}
});
ws.on("message", (raw) => {
const event = JSON.parse(raw.toString());
if (!stats[event.asset]) return;
if (event.type === "order") stats[event.asset].orders++;
if (event.type === "fill") {
stats[event.asset].fills++;
stats[event.asset].volume += parseFloat(event.data.sz) * parseFloat(event.data.px);
}
});
// Print stats every 10 seconds
setInterval(() => {
console.clear();
console.log("Asset Orders Fills Volume");
console.log("------- ------ ----- ------");
for (const [asset, s] of Object.entries(stats)) {
console.log(`${asset.padEnd(10)}${String(s.orders).padEnd(9)}${String(s.fills).padEnd(9)}$${Math.round(s.volume).toLocaleString()}`);
}
}, 10000);