WebSocket

One socket, many markets. Subscribe to order-book and ticker channels to receive a fresh snapshot on every change — no polling required.

Connect

Open a WebSocket to the realtime endpoint. No authentication is required for public market data.

WSwss://api.majjha.com/ws

Environments

On the play-money site, connect to wss://api-play.majjha.com/ws instead — same protocol, separate venue (see Environments). Against a local engine, use ws://localhost:7890/ws.

Subscribe

Send a JSON command with cmd: "subscribe" and a list of channels. Each channel is <channel>.<market_id>, where the id is the market's internal id (the id field, not the ticker). A single socket may hold up to 64 channels.

→ client sends
{
  "cmd": "subscribe",
  "channels": [
    "orderbook.mkt_btc5m_a1",
    "ticker.mkt_btc5m_a1"
  ]
}

Unsubscribe with the same shape and cmd: "unsubscribe".

→ client sends
{
  "cmd": "unsubscribe",
  "channels": ["ticker.mkt_btc5m_a1"]
}

Channels

  • orderbook.<market_id> — full order-book snapshot on every change.
  • ticker.<market_id> — top-of-book only (best bid/ask, spread, mid).

Server messages

Every push is a JSON frame tagged with a type and the originating channel, with the payload under data.

← orderbook frame
{
  "type": "orderbook",
  "channel": "orderbook.mkt_btc5m_a1",
  "data": {
    "bids": [{ "price": "0.53", "quantity": "120", "order_count": 3 }],
    "asks": [{ "price": "0.55", "quantity": "90", "order_count": 2 }],
    "best_bid": "0.53",
    "best_ask": "0.55",
    "spread": "0.02",
    "mid_price": "0.54"
  }
}
← ticker frame
{
  "type": "ticker",
  "channel": "ticker.mkt_btc5m_a1",
  "data": {
    "market_id": "mkt_btc5m_a1",
    "best_bid": "0.53",
    "best_ask": "0.55",
    "spread": "0.02",
    "mid_price": "0.54"
  }
}

Browser example

subscribe.js
const ws = new WebSocket("wss://api.majjha.com/ws");

ws.onopen = () => {
  ws.send(JSON.stringify({
    cmd: "subscribe",
    channels: ["orderbook.mkt_btc5m_a1", "ticker.mkt_btc5m_a1"],
  }));
};

ws.onmessage = (event) => {
  const frame = JSON.parse(event.data);
  if (frame.type === "ticker") {
    console.log("mid", frame.data.mid_price);
  }
};

Single-market shortcut

The legacy push-only endpoint /ws/markets/{id}streams one market's order book without a subscribe handshake — handy for a single embedded chart.