WebSocket API Introduction

Overview

The Public WebSocket API provides real-time data subscription functionality, supporting subscriptions for order books, K-lines, instrument information, portfolios, and more.

Connection URL

wss://api.monday.trade/v4/public/ws

Connection Requirements

When connecting to the WebSocket server, you may need to include HTTP headers:

  • User-Agent: Recommended to include a User-Agent header to avoid connection issues

  • Origin: Some clients may need to set the Origin header matching the WebSocket URL

Note for Node.js clients: When using the ws library, you can pass headers in the connection options:

const WebSocket = require('ws');
const ws = new WebSocket('wss://api.monday.trade/v4/public/ws', {
  headers: {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36',
    'Origin': 'https://api.monday.trade'
  }
});

Note for Browser clients: Browsers automatically set the Origin header based on the current page URL. The User-Agent is also set automatically by the browser.

Heartbeat Mechanism

Clients can send a "ping" string to keep the connection alive. The server will reply with "pong".

Message Format

Request Message Format

All request messages follow this format:

Response Message Format

Subscribe/Unsubscribe Response

Data Stream Message Format

Subscription Types

The WebSocket API supports the following subscription types:

  1. K-line Data Subscription (kline) - Subscribe to K-line data updates for a specific instrument and interval

  2. Order Book Subscription (orderBook) - Subscribe to order book data updates for a specific instrument

  3. Instrument Information Subscription (instrument) - Subscribe to detailed instrument information updates

  4. Portfolio Subscription (portfolio) - Subscribe to portfolio update notifications for a specific user address

  5. Common Subscription (common) - Subscribe to chain-level common events, including block number changes and market list changes

  6. Instrument Basic Info Subscription (instrumentBasicInfo) - Subscribe to basic instrument information updates

For detailed information about each subscription type, please refer to the corresponding documentation files.

Last updated