Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.unitedmarket.ai/llms.txt

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

The public real-time API is exposed through the backend Socket.IO endpoint.
NetworkSocket.IO URL
Mainnethttps://backend.themarketunited.com
Testnethttps://backend-develop.themarketunited.com
United Market is currently in sandbox/development stage. All funds, balances, markets, and trades are for testing only and do not represent real money.
Use the Socket.IO client protocol. Do not connect with a plain WebSocket client.

Install Client

npm install socket.io-client

Connect

import { io } from "socket.io-client";

const socket = io("https://backend.themarketunited.com", {
  transports: ["websocket", "polling"],
  reconnection: true,
});
For testnet:
const socket = io("https://backend-develop.themarketunited.com", {
  transports: ["websocket", "polling"],
  reconnection: true,
});

Subscribe to a Market

Join a market room with the market conditionId.
const conditionId = "0xd19487c4038d0dce2edeb510a21d6f8534e09d8065d40cb9e10ad2652d86a276";

socket.on("connect", () => {
  socket.emit("join:market", conditionId);
});

socket.emit("leave:market", conditionId);

Client Events

EventPayloadDescription
join:marketconditionId: stringSubscribe to one market room.
leave:marketconditionId: stringUnsubscribe from one market room.
join:activitynoneSubscribe to global trade activity.
leave:activitynoneUnsubscribe from global trade activity.

Server Events

EventDescription
orderbook:updateEmitted when market orderbook state changes.
trade:newEmitted when a trade is confirmed on-chain.
ob:snapshotL2 orderbook snapshot for an outcome token.
price:snapshotLatest bid, ask, and midpoint for an outcome.

orderbook:update

type OrderbookUpdatePayload = {
  conditionId: string;
  orderbook: {
    type:
      | "order:new"
      | "order:cancelled"
      | "order:matched"
      | "order:filled"
      | "order:settlement";
    orderHash: string;
    tokenId: string;
    timestamp: number;
    data: Record<string, unknown>;
  };
};
After this event, clients can refetch GET /markets/{id}/orderbook or GET /markets/{id}/trading.

trade:new

type TradeNewPayload = {
  conditionId: string;
  trade: {
    orderHash: string;
    tokenId: string;
    timestamp: number;
    data: {
      maker: string;
      taker: string;
      makerAmountFilled: string;
      takerAmountFilled: string;
      fee: string;
      txHash: string;
    };
  };
};

ob:snapshot

type ObSnapshotPayload = {
  conditionId: string;
  tokenId: string;
  bids: Array<[price: number, size: number]>;
  asks: Array<[price: number, size: number]>;
  timestamp: number;
};

price:snapshot

type PriceSnapshotPayload = {
  conditionId: string;
  outcomeId: string;
  tokenId: string;
  bid: number | null;
  ask: number | null;
  mid: number | null;
  timestamp: number;
};

Reconnection

Socket.IO reconnects automatically when configured with reconnection: true. Re-emit join:market subscriptions after reconnecting if your client manages rooms outside a persistent component.