const ws = new WebSocket("wss://api.easierprop.com/ws?apiKey=sk_your_key");
ws.onopen = () => {
console.log("Connected to Easier Prop WebSocket");
// Stream live quotes
ws.send(JSON.stringify({
type: "subscribe",
channel: "quotes",
account_id: "70f60784-20f1-45ba-9a04-8e01c0b810c3",
symbols: ["EURUSD", "GBPUSD", "USDJPY"],
interval_ms: 500
}));
// Monitor order fills
ws.send(JSON.stringify({
type: "subscribe",
channel: "orders",
account_id: "70f60784-20f1-45ba-9a04-8e01c0b810c3"
}));
// Track live P&L
ws.send(JSON.stringify({
type: "subscribe",
channel: "profit",
account_id: "70f60784-20f1-45ba-9a04-8e01c0b810c3",
interval_ms: 1000
}));
// Heartbeat for account health
ws.send(JSON.stringify({
type: "subscribe",
channel: "heartbeat",
account_id: "70f60784-20f1-45ba-9a04-8e01c0b810c3"
}));
// Price alert
ws.send(JSON.stringify({
type: "price_alert",
account_id: "70f60784-20f1-45ba-9a04-8e01c0b810c3",
symbol: "EURUSD",
direction: "above",
target_price: 1.09000
}));
};
ws.onmessage = (event) => {
const msg = JSON.parse(event.data);
switch (msg.type) {
case "subscribed":
console.log(`Subscribed to ${msg.channel}`);
break;
case "quote":
console.log(`${msg.data.symbol}: ${msg.data.bid} / ${msg.data.ask}`);
break;
case "order_update":
console.log(`Order ${msg.data.ticket}: ${msg.data.orderType} ${msg.data.symbol} P&L=${msg.data.profit}`);
break;
case "profit":
console.log(`Equity: ${msg.data.equity} | Profit: ${msg.data.profit}`);
break;
case "heartbeat":
console.log(`Heartbeat: balance=${msg.balance} equity=${msg.equity} positions=${msg.position_count}`);
break;
case "new_position":
console.log(`New position: ${msg.data.ticket} ${msg.data.orderType} ${msg.data.symbol}`);
break;
case "alert_registered":
console.log(`Alert registered: ${msg.alert_id} (${msg.alert_type})`);
break;
case "price_alert_triggered":
console.log(`Price alert! ${msg.symbol} crossed ${msg.target_price} (${msg.direction})`);
break;
case "spread_alert_triggered":
console.log(`Spread alert! ${msg.symbol} spread=${msg.spread_pips} pips`);
break;
case "pl_alert_triggered":
console.log(`P&L alert! ${msg.condition} ${msg.threshold}, current=${msg.current_value}`);
break;
case "error":
console.error(`Error: ${msg.message}`);
break;
}
};
ws.onclose = () => console.log("Disconnected");