This document provides example request and subscription payloads for receiving order book data via WebSocket.
WebSocket Endpoint
| Type | Endpoint |
|---|---|
| Public | wss://{region}-api.upbit.com/websocket/v1 |
Use the endpoint for your region.
| Region | Endpoint |
|---|---|
| Singapore | wss://sg-api.upbit.com/websocket/v1 |
| Indonesia | wss://id-api.upbit.com/websocket/v1 |
| Thailand | wss://th-api.upbit.com/websocket/v1 |
Request Message Format
To request announcement data, after establishing a WebSocket connection, create a JSON Object with the structure below and include it as a Data Type Object in the request message.
For the complete WebSocket request message specification, including the Ticket and Format Objects, refer to the WebSocket Usage and Error Guide.
| Field Name | Type | Description | Required | Default |
|---|---|---|---|---|
| type | String | Data type to receive. Set to orderbook to receive orderbook data. | Required | |
| codes | List:String | List of trading pairs to receive. Must be requested in uppercase. | Required | |
| is_only_snapshot | Boolean | Provide snapshot data only | Optional | false |
| is_only_realtime | Boolean | Provide real-time data only | Optional | false |
| format | String | Data format to receive.DEFAULT: Default format.SIMPLE: Simplified format with abbreviated field names.JSON_LIST: List format.SIMPLE_LIST: List format with abbreviated field names. | Required |
Custom function for Orderbook Unit quantity is addedYou can adjust the quantity of Orderbook Units only for orderbook-type packets. Please input the market code and unit quantity as follows.
Format: {code}.{count}
Example: SGD-BTC.5, SGD-ETH.5
Supported values for count: 1, 5, 15, 30
If an unsupported value is specified, it defaults to 30.
Subscription Data Specification
When a new announcement is published or an existing announcement is updated, real-time stream data is returned as follows.
| Field Name | Abbreviation | Description | Type | Value Example |
|---|---|---|---|---|
| type | ty | Type | String | orderbook |
| code | cd | Trading pair code | String | SGD-BTC |
| total_ask_size | tas | Total ask size | Double | |
| total_bid_size | tbs | Total bid size | Double | |
| orderbook_units | obu | Orderbook units | List of Objects | |
| orderbook_units.ask_price | obu.ap | The lowest sell (ask) price in the orderbook | Double | |
| orderbook_units.bid_price | obu.bp | The highest buy (bid) price in the orderbook | Double | |
| orderbook_units.ask_size | obu.as | Sell (ask) quantity at the corresponding ask price | Double | |
| orderbook_units.bid_size | obu.bs | Buy (bid) quantity at the corresponding bid price | Double | |
| timestamp | tms | Timestamp (ms) | Long | |
| stream_type | st | Stream type | String | SNAPSHOT: Snapshot REALTIME: Real-time |
Examples
Subscription Request Example
[
{
"ticket": "test"
},
{
"type": "orderbook",
"codes": ["SGD-BTC","SGD-ETH"]
},
{
"format": "DEFAULT"
}
]Subscription Data Example
[
{
"type": "orderbook",
"code": "SGD-BTC",
"timestamp": 1746602359173,
"total_ask_size": 0.68780013,
"total_bid_size": 0.78754733,
"orderbook_units": [
{
"ask_price": 125056.0,
"bid_price": 124743.0,
"ask_size": 0.17,
"bid_size": 0.17
},
{
"ask_price": 125207.0,
"bid_price": 124332.0,
"ask_size": 0.09,
"bid_size": 0.09
},
{
"ask_price": 125416.0,
"bid_price": 124167.0,
"ask_size": 0.2,
"bid_size": 0.2
},
{
"ask_price": 126661.0,
"bid_price": 122917.0,
"ask_size": 0.01210697,
"bid_size": 0.01844114
},
{
"ask_price": 126786.0,
"bid_price": 122716.0,
"ask_size": 0.01142233,
"bid_size": 0.0175997
},
{
"ask_price": 126997.0,
"bid_price": 122577.0,
"ask_size": 0.01442522,
"bid_size": 0.02204438
},
{
"ask_price": 127288.0,
"bid_price": 122283.0,
"ask_size": 0.0139072,
"bid_size": 0.02114427
},
{
"ask_price": 127451.0,
"bid_price": 122002.0,
"ask_size": 0.01378211,
"bid_size": 0.0203521
},
{
"ask_price": 127946.0,
"bid_price": 121665.0,
"ask_size": 0.0128153,
"bid_size": 0.01977116
},
{
"ask_price": 127970.0,
"bid_price": 121504.0,
"ask_size": 0.0084267,
"bid_size": 0.0129707
},
{
"ask_price": 128351.0,
"bid_price": 121372.0,
"ask_size": 0.00766313,
"bid_size": 0.04750075
},
{
"ask_price": 128649.0,
"bid_price": 121263.0,
"ask_size": 0.00716242,
"bid_size": 0.0123517
},
{
"ask_price": 128849.0,
"bid_price": 120969.0,
"ask_size": 0.00690843,
"bid_size": 0.01155361
},
{
"ask_price": 128956.0,
"bid_price": 120643.0,
"ask_size": 0.00732903,
"bid_size": 0.01096038
},
{
"ask_price": 129000.0,
"bid_price": 120436.0,
"ask_size": 0.03875968,
"bid_size": 0.01039539
},
{
"ask_price": 129066.0,
"bid_price": 120095.0,
"ask_size": 0.00655781,
"bid_size": 0.01010256
},
{
"ask_price": 129228.0,
"bid_price": 119824.0,
"ask_size": 0.00684494,
"bid_size": 0.00948499
},
{
"ask_price": 129231.0,
"bid_price": 119618.0,
"ask_size": 0.00626955,
"bid_size": 0.00903197
},
{
"ask_price": 129515.0,
"bid_price": 119279.0,
"ask_size": 0.00595153,
"bid_size": 0.00853212
},
{
"ask_price": 129579.0,
"bid_price": 119120.0,
"ask_size": 0.0064701,
"bid_size": 0.00172935
},
{
"ask_price": 130312.0,
"bid_price": 118969.0,
"ask_size": 0.00553463,
"bid_size": 0.0080544
},
{
"ask_price": 130535.0,
"bid_price": 118613.0,
"ask_size": 0.00450619,
"bid_size": 0.00770287
},
{
"ask_price": 130797.0,
"bid_price": 118290.0,
"ask_size": 0.00413189,
"bid_size": 0.00712616
},
{
"ask_price": 131288.0,
"bid_price": 118107.0,
"ask_size": 0.00452539,
"bid_size": 0.00674375
},
{
"ask_price": 131399.0,
"bid_price": 117808.0,
"ask_size": 0.00369111,
"bid_size": 0.00658978
},
{
"ask_price": 131510.0,
"bid_price": 117595.0,
"ask_size": 0.00417261,
"bid_size": 0.0060327
},
{
"ask_price": 131727.0,
"bid_price": 117300.0,
"ask_size": 0.00342738,
"bid_size": 0.00566733
},
{
"ask_price": 131821.0,
"bid_price": 117156.0,
"ask_size": 0.00392284,
"bid_size": 0.00538776
},
{
"ask_price": 131867.0,
"bid_price": 116805.0,
"ask_size": 0.00326427,
"bid_size": 0.00533339
},
{
"ask_price": 132107.0,
"bid_price": 116593.0,
"ask_size": 0.00382137,
"bid_size": 0.00494292
}
],
"stream_type": "SNAPSHOT"
}
]Error Information
If an error occurs after establishing a WebSocket connection and sending a request, the response is returned in the following JSON format.
{
"error": {
"name": "ERROR_CODE",
"message": "ERROR_MESSAGE"
}
}The main error codes that may be returned are listed below.
error.name | Reason | Recommended Action |
|---|---|---|
INVALID_AUTH | Missing authentication information or authentication token verification failure | When using a Private WebSocket endpoint, make sure you are connected to the correct endpoint and that the Authorization header contains a valid authentication token. |
WRONG_FORMAT | Invalid request message format | Make sure the request message follows the WebSocket request format. Check the Object structure as well as the type and value of each field. |
NO_TICKET | Missing ticket field | Make sure the request message includes a Ticket Object and the ticket field. |
NO_TYPE | Missing type field | Make sure the Data Type Object includes the type field and specify the data type to subscribe to. |
NO_CODES | Missing codes field | Check whether the subscribed data type requires the codes field and specify the trading pair codes to receive. |
INVALID_PARAM | Missing required request field or unsupported value | Make sure all required fields are included and that each field contains a supported value. |
Too Many Requests | Request rate limit exceeded | Wait until another request can be made, then retry. Refer to the Rate Limits section for details. |
I'm a teapot | Requests are temporarily restricted due to repeated Too Many Requests errors | Check the restriction period included in the response and retry after the specified time has passed. |
Rate Limits
APIs are grouped into Rate Limit groups. APIs within the same group share the same per-second request limit.
The maximum number of requests allowed per Rate Limit group may change after prior notice according to service policy, and additional restrictions may be applied depending on service conditions. For details, refer to Rate Limits.
| Rate Limit Group | Policy | Applied By |
|---|---|---|
websocket-connect | Up to 5 connections per second | IP |
websocket-message | Up to 5 messages per second and 100 messages per minute | Connection |
Managing WebSocket Rate LimitsUnlike REST API responses, WebSocket does not provide the number of remaining requests. Clients should track the number of WebSocket connection attempts and data request messages they send to ensure compliance with the applicable rate limits. If a rate limit is reached, wait for an appropriate period before sending another request..
