Market API

Websocket Introduction#

WebSocket is a new HTML5 protocol that achieves full-duplex data transmission between the client and server, allowing data to be transferred effectively in both directions. A connection between the client and server can be established with just one handshake. The server will then be able to push data to the client according to preset rules. Its advantages include:

  • The WebSocket request header size for data transmission between client and server is only 2 bytes.
  • Either the client or server can initiate data transmission.
  • There's no need to repeatedly create and delete TCP connections, saving resources on bandwidth and server.

Connect#

Connection limit: 3 requests per second (based on API KEY)
When subscribing to a private channel, use the address of the private service

Request limit

The total number of 'subscribe'/'unsubscribe'/'login' requests per connection is limited to 480 times per hour. If there’s a network problem, the system will automatically disable the connection. The connection will break automatically if the subscription is not established or data has not been pushed for more than 30 seconds. To keep the connection stable:

  1. Set a timer of N seconds whenever a response message is received, where N is less than 30.
  2. If the timer is triggered, which means that no new message is received within N seconds, send the String 'ping'.
  3. Expect a 'pong' as a response. If the response message is not received within N seconds, please raise an error or reconnect.

Notification#

WebSocket has introduced a new message type (event = notice). Client will receive the information in the following scenarios:

  • Websocket disconnect for service upgrade 30 seconds prior to the upgrade of the WebSocket service, the notification message will be sent to users indicating that the connection will soon be disconnected. Users are encouraged to establish a new connection to prevent any disruptions caused by disconnection.

Response Example

{
    "event": "notice",
    "code": "64008",
    "msg": "The connection will soon be closed for a service upgrade. Please reconnect.",
    "connId": "a4d3ae55"
}
Sisällysluettelo