const WebSocket = require("ws");
const API_KEY = "sk_your_api_key";
const ws = new WebSocket(`wss://de.raze.sh/ws/sol?apiKey=${API_KEY}`);
ws.on("open", () => {
console.log("Connected");
// Subscribe to event types
ws.send(JSON.stringify({
action: "subscribe",
subscriptions: ["trade", "deploy", "alert"]
}));
});
ws.on("message", (data) => {
const msg = JSON.parse(data.toString());
switch (msg.type) {
case "welcome":
console.log("Authenticated:", msg.authenticated);
break;
case "event_subscription_confirmed":
console.log("Subscribed to:", msg.event_types);
break;
case "trade":
console.log(`${msg.data.type} ${msg.data.mint} — ${msg.data.solAmount} SOL`);
break;
case "deploy":
console.log(`New token: ${msg.data.name} (${msg.data.symbol}) on ${msg.data.platform}`);
break;
case "alert":
console.log(`Alert: ${msg.data.mint} — ${msg.data.tradeCount} trades, ${msg.data.totalVolumeSol} SOL`);
break;
case "error":
console.error(`Error [${msg.code}]: ${msg.error}`);
break;
}
});
ws.on("close", () => console.log("Disconnected"));
ws.on("error", (err) => console.error("WebSocket error:", err));