Trades

This document provides example request and subscription payloads for receiving trade data via WebSocket.

WebSocket Endpoint

TypeEndpoint
Publicwss://{region}-api.upbit.com/websocket/v1

Use the endpoint for your region.

RegionEndpoint
Singaporewss://sg-api.upbit.com/websocket/v1
Indonesiawss://id-api.upbit.com/websocket/v1
Thailandwss://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 NameTypeDescriptionRequiredDefault
typeStringData type to receive. Set to trade to receive trade data.Required
codesList:StringList of trading pairs to receive.
Must be requested in uppercase.
Required
is_only_snapshotBooleanProvide snapshot data onlyOptionalfalse
is_only_realtimeBooleanProvide real-time data onlyOptionalfalse
formatStringData 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

Subscription Data Specification

When a new announcement is published or an existing announcement is updated, real-time stream data is returned as follows.

Field NameAbbreviationDescriptionTypeValue Example
typetyData TypesStringtrade
codecdTrading pair codeStringSGD-BTC
trade_pricetpCurrent trade priceDouble
trade_volumetvMost recent trade volumeDouble
ask_bidabBuy/Sell distinctionStringASK : Sell
BID : Buy
prev_closing_pricepcpPrevious day closing priceDouble
changecDirection of price change compared to previous day closing priceStringRISE : Rise
EVEN : Even
FALL : Fall
change_pricecpAbsolute price change compared to previous dayDouble
trade_datetdTrade date (UTC)Stringyyyy-MM-dd
trade_timettmTrade time (UTC)StringHH:mm:ss
trade_timestampttmsTrade timestamp (ms)Long
timestamptmsTimestamp (ms)Long
sequential_idsidTrade number (unique)Long
best_ask_pricebapBest ask priceDouble
best_ask_sizebasBest ask sizeDouble
best_bid_pricebbpBest bid priceDouble
best_bid_sizebbsBest bid sizeDouble
stream_typestStream typeStringSNAPSHOT : Snapshot
REALTIME : Real-time

Examples

Subscription Request Example

[
  {
    "ticket": "test"
  },
  {
    "type": "trade",
    "codes": ["SGD-BTC","SGD-ETH"]
  },
  {
    "format": "DEFAULT"
  }
]

Subscription Data Example

{
  "type": "trade",
  "code": "SGD-BTC",
  "timestamp": 1696585056910,
  "trade_date": "2023-10-06",
  "trade_time": "09:37:36",
  "trade_timestamp": 1696585056846,
  "trade_price": 37625,
  "trade_volume": 8.428e-05,
  "ask_bid": "ASK",
  "prev_closing_price": 37296,
  "change": "RISE",
  "change_price": 329,
  "sequential_id": 1696585056846000,
  "best_ask_price": 32293000,
  "best_ask_size": 0.04414411,
  "best_bid_price": 32291000,
  "best_bid_size": 0.01202163,
  "stream_type": "SNAPSHOT"
}
...
{
  "type": "trade",
  "code": "SGD-ETH",
  "timestamp": 1696585254027,
  "trade_date": "2023-10-06",
  "trade_time": "09:40:53",
  "trade_timestamp": 1696585253974,
  "trade_price": 2224,
  "trade_volume": 0.00210894,
  "ask_bid": "ASK",
  "prev_closing_price": 2192,
  "change": "RISE",
  "change_price": 32,
  "sequential_id": 1696585253974000,
  "best_ask_price": 32293000,
  "best_ask_size": 0.04414411,
  "best_bid_price": 32291000,
  "best_bid_size": 0.01202163,
  "stream_type": "REALTIME"
}

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.nameReasonRecommended Action
INVALID_AUTHMissing authentication information or authentication token verification failureWhen 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_FORMATInvalid request message formatMake sure the request message follows the WebSocket request format. Check the Object structure as well as the type and value of each field.
NO_TICKETMissing ticket fieldMake sure the request message includes a Ticket Object and the ticket field.
NO_TYPEMissing type fieldMake sure the Data Type Object includes the type field and specify the data type to subscribe to.
NO_CODESMissing codes fieldCheck whether the subscribed data type requires the codes field and specify the trading pair codes to receive.
INVALID_PARAMMissing required request field or unsupported valueMake sure all required fields are included and that each field contains a supported value.
Too Many RequestsRequest rate limit exceededWait until another request can be made, then retry. Refer to the Rate Limits section for details.
I'm a teapotRequests are temporarily restricted due to repeated Too Many Requests errorsCheck 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 GroupPolicyApplied By
websocket-connectUp to 5 connections per secondIP
websocket-messageUp to 5 messages per second and 100 messages per minuteConnection

Managing WebSocket Rate Limits

Unlike 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..