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/wsProduction
wss://ws.mbhq.net/wsLocal Development
# Public port
ws://localhost:8080/ws
# Internal port (with bypass authentication)
ws://localhost:8082/wsQuick Start
Connect to the WebSocket using any WebSocket client:
# Using wscat
wscat -c wss://ws.dev.mbhq.net/wsOnce 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-VNDETH-VNDSOL-VNDXRP-VND
Message Operations
The WebSocket API supports the following operations:
| Operation | Description | Authentication Required |
|---|---|---|
sub | Subscribe to a channel | Depends on channel |
unsub | Unsubscribe from a channel | No |
ping | Keep connection alive | No |
auth | Authenticate the connection | No |
create_order | Create a new order | Yes |
cancel_order | Cancel an existing order | Yes |
bye | Close the connection | No |
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 1000004Error 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
- Authentication - Learn how to authenticate for private channels
- Public Channels - Explore market data channels
- Private Channels - Access account-specific data
- Trading Operations - Create and cancel orders via WebSocket