Moonbase Docs

WebSocket Overview

Real-time market data and account updates via WebSocket

Introduction

The Moonbase WebSocket API provides real-time access to market data and account updates. WebSocket connections offer event-driven responses without the need to poll the server, making it the most efficient way to receive up-to-date information.

Connection Endpoints

Development

wss://ws.dev.mbhq.net/ws

Production

wss://ws.mbhq.net/ws

Local Development

# Public port
ws://localhost:8080/ws

# Internal port (with bypass authentication)
ws://localhost:8082/ws

Quick Start

Connect to the WebSocket using any WebSocket client:

# Using wscat
wscat -c wss://ws.dev.mbhq.net/ws

Once connected, you'll receive a welcome message:

{
  "type": "message",
  "connection_id": "abc123...",
  "internal": false
}

Available Channels

Public Channels (No authentication required)

  • book - Real-time orderbook updates with bids and asks
  • trades - Trade execution data
  • ticker - Best bid/ask price updates

Private Channels (Authentication required)

  • orders - User-specific order updates and trade matches
  • portfolio - Real-time portfolio updates including balances and statistics

Internal Channels

  • events - Raw exchange events (internal use only, requires internal authentication)

Supported Products

All public channels support the following trading pairs:

  • BTC-VND
  • ETH-VND
  • SOL-VND
  • XRP-VND

Message Operations

The WebSocket API supports the following operations:

OperationDescriptionAuthentication Required
subSubscribe to a channelDepends on channel
unsubUnsubscribe from a channelNo
pingKeep connection aliveNo
authAuthenticate the connectionNo
create_orderCreate a new orderYes
cancel_orderCancel an existing orderYes
byeClose the connectionNo

Message Format

Standard JSON Format

All messages use JSON format:

{
  "op": "sub",
  "channel": "book",
  "product": "BTC-VND"
}

Human-Friendly Format (Development)

For easier testing, simple text commands are also supported:

sub book BTC-VND
sub trades BTC-VND
unsub book BTC-VND
auth 1000004

Error Handling

When an error occurs, you'll receive an error message:

{
  "channel": "book",
  "type": "error",
  "message": "given channel/product is unsupported",
  "code": 400
}

Common error codes:

  • 400 - Bad request (invalid parameters, unsupported channel)
  • 401 - Unauthorized (authentication required or failed)
  • 500 - Internal server error

Next Steps