WebSocket API
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/wsHeartbeat 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:
{
"id": <number>, // Request ID for matching responses
"method": "SUBSCRIBE" | "UNSUBSCRIBE",
"params": {
// Specific parameters vary by subscription type
}
}Response Message Format
Subscribe/Unsubscribe Response
Data Stream Message Format
Subscription Types
1. K-line Data Subscription (kline)
Subscribe to K-line data updates for a specific instrument and interval.
Subscribe Request
Unsubscribe Request
Parameter Description
chainId(required): Chain IDinstrument(required): Instrument address (lowercase)expiry(required): Expiry timestampinterval(required): K-line interval. Supported values:1m- 1 minute5m- 5 minutes15m- 15 minutes30m- 30 minutes1h- 1 hour4h- 4 hours8h- 8 hours12h- 12 hours1d- 1 day1w- 1 week1M- 1 month
type(required): Must be"kline"
Data Stream Message
2. Order Book Subscription (orderBook)
Subscribe to order book data updates for a specific instrument.
Subscribe Request
Unsubscribe Request
Parameter Description
chainId(required): Chain IDinstrument(required): Instrument address (lowercase)expiry(required): Expiry timestamptype(required): Must be"orderBook"
Data Stream Message
Order Book Data Structure:
chainId(top-level): Chain ID of the order book updateinstrument(top-level): Instrument address corresponding to the updateexpiry(top-level): Expiry timestampdata: Map of order book entries, keyed by tick ID (string). Each entry contains:blockInfo: Block informationheight: Block heighttimestamp: Block timestamp
bids: Buy order list (sorted by price from high to low)asks: Sell order list (sorted by price from low to high)Each order item contains:
tick: Price tickprice: Price (string format)baseSize: Base asset quantityquoteSize: Quote asset quantitybaseSum: Cumulative base asset quantityquoteSum: Cumulative quote asset quantity
3. Instrument Information Subscription (instrument)
Subscribe to detailed instrument information updates.
Subscribe Request
Unsubscribe Request
Parameter Description
chainId(required): Chain IDinstrument(required): Instrument address (lowercase)expiry(required): Expiry timestamptype(required): Must be"instrument"
Data Stream Messages
When subscribing to instrument, you will receive two types of messages:
3.1 Instrument Information (instrument)
Complete instrument information update:
Instrument Information Data Structure
instrumentAddr: Instrument addresssymbol: Trading pair symbolmarket: Market informationinfo: Market basic information (address, type, beacon)config: Market configuration (daily interest rate, feeder sources)feeder: Market feeder information (aggregators, heartbeats)
condition: Instrument condition statussetting: Instrument settingsinitialMarginRatio: Initial margin ratiomaintenanceMarginRatio: Maintenance margin ratioquoteParam: Quote parameters (min margin amount, fee ratios, etc.)
spotPrice: Spot priceamms: Array of AMM states, containing:expiry: Expiry timestamptimestamp: Timestampstatus: AMM statustick: Current ticksqrtPX96: Square root price in X96 formatliquidity: Current liquiditytotalLiquidity: Total liquiditytotalShort: Total short positionsopenInterests: Open interesttotalLong: Total long positionsinvolvedFund: Involved fund amountfeeIndex: Fee indexprotocolFee: Protocol feelongSocialLossIndex: Long social loss indexshortSocialLossIndex: Short social loss indexlongFundingIndex: Long funding indexshortFundingIndex: Short funding indexinsuranceFund: Insurance fund amountsettlementPrice: Settlement pricemarkPrice: Mark pricefairPrice: Fair priceblockInfo: Block information (height, timestamp)
base: Base token information (symbol, address, decimals, name)quote: Quote token information (symbol, address, decimals, name)blockInfo: Block information (height, timestamp)placePaused: Whether placing orders is pausedfundingHour: Funding hourdisableOrderRebate: Whether order rebate is disabledinstrumentType: Instrument typemarketType: Market type (e.g., "perp")minTradeValue: Minimum trade valueminOrderValue: Minimum order valueminRangeValue: Minimum range valuedisplayBase: Display base token informationdisplayQuote: Display quote token informationminTickDelta: Minimum tick delta
3.2 Market Pair Info Changed (marketPairInfoChanged)
Market pair information update (prices, volumes, etc.):
Note: This message is sent when market pair information (prices, volumes, etc.) changes. It provides a lightweight update focused on market data, while the instrument message provides complete instrument state information.
Market Pair Info Changed Data Structure
instrumentAddr: Instrument addressexpiry: Expiry timestampsymbol: Trading pair symbol (e.g., "ETH/USD")fullSymbol: Full trading pair symbol with expiry (e.g., "ETH/USD-PERP")baseToken: Base token informationsymbol: Token symboladdress: Token addressdecimals: Token decimalsprice: Current token priceimage: Token image URL
quoteToken: Quote token informationsymbol: Token symboladdress: Token addressdecimals: Token decimalsprice: Current token priceimage: Token image URL
markPrice: Mark price (string)fairPrice: Fair price (string)spotPrice: Spot price (string)fairPriceChange24h: Fair price change percentage over 24 hours (string)baseVolume24h: Base token volume over 24 hours (string)quoteVolume24h: Quote token volume over 24 hours (string)volume24hUsd: Total volume in USD over 24 hours (string)openInterests: Open interest amount (string)openInterestsUsd: Open interest in USD (string)tvl: Total value locked (string)tvlUsd: Total value locked in USD (string)longOi: Long open interest (string)shortOi: Short open interest (string)periods1hFunding: 1-hour periods funding ratelong: Long funding rateshort: Short funding rate
last1hFunding: Last 1-hour funding ratelong: Long funding rateshort: Short funding rate
fundingRatePerHour: Funding rate per hour (string)poolFee24h: Pool fee over 24 hours (string)maxLeverage: Maximum leverage (number)updateTime: Last update timestamp (number)marketType: Market type (e.g., "perp")condition: Instrument condition status (number)ammStatus: AMM status (number)
4. Portfolio Subscription (portfolio)
Subscribe to portfolio update notifications for a specific user address.
Subscribe Request
Unsubscribe Request
Parameter Description
chainId(required): Chain IDuserAddress(required): User address (lowercase)type(required): Must be"portfolio"
Data Stream Message
Portfolio Update Description:
This message is pushed when a user's orders, range orders, positions, or gates change
The
typefield indicates the change type:order: Order changerange: Range order changeposition: Position changegate: Gate change
After receiving this message, clients should call the corresponding REST API to fetch the latest portfolio details
5. Common Subscription (common)
Subscribe to chain-level common events, including block number changes and market list changes.
Subscribe Request
Unsubscribe Request
Parameter Description
chainId(required): Chain IDtype(required): Must be"common"
Data Stream Message Types
5.1 Block Number Changed (blockNumChanged)
5.2 Market List Changed (marketListChanged)
Note: To receive individual market pair information updates (marketPairInfoChanged), you need to subscribe to the instrument type instead. The common subscription only provides blockNumChanged and marketListChanged messages.
6. Instrument Basic Info Subscription (instrumentBasicInfo)
Subscribe to basic instrument information updates.
Subscribe Request
Unsubscribe Request
Parameter Description
chainId(required): Chain IDinstrument(required): Instrument address (lowercase)expiry(required): Expiry timestamptype(required): Must be"instrumentBasicInfo"
Note: This subscription type is defined in the code, but the current implementation returns immediately without sending data stream messages.
Error Handling
Connection Errors
If the connection fails, the WebSocket will trigger an error event. Clients should implement a reconnection mechanism.
Common connection issues:
Connection Timeout:
Check your network connection and firewall settings
Verify the WebSocket URL is correct
Unexpected Server Response:
Ensure you're using the correct protocol (
wss://for secure connections)Verify the server endpoint is accessible
Message Format Errors
If the message format is incorrect, the server may not respond or return an error. Please ensure:
JSON format is correct
All required parameters are provided
Parameter types are correct (e.g.,
chainIdis a number,instrumentis a string)
Best Practices
Connection Management
Implement automatic reconnection mechanism
Use heartbeat to keep connection alive
Handle network interruptions
Subscription Management
Subscribe to required data streams immediately after connection is established
Unsubscribe from all subscriptions before disconnecting
Use unique request IDs to track subscription status
Data Processing
Validate received data format
Handle data update frequency to avoid excessive UI refreshes
For
portfoliosubscriptions, actively fetch the latest data after receiving notifications
Performance Optimization
Only subscribe to needed data streams
Unsubscribe from unnecessary subscriptions promptly
Use data caching appropriately
Example Code
Browser JavaScript Example
Node.js TypeScript Example
Changelog
Support for K-line, order book, instrument information, portfolio, and common event subscriptions
Heartbeat mechanism support
Multi-chain subscription support
Last updated