One Trading API
REST APIWebSocket API
REST APIWebSocket API
  1. WebSocket API
  • Introduction
  • Authenticate
  • Subscribe
  • Ping / Pong
  • Trading
    • Introduction
    • Dead Man Switch (Auto Cancellation)
    • Create Order
    • Cancel All Orders
    • Cancel Order by Client ID
    • Cancel Order by Order ID
    • Margin Update
    • Settlement
    • Funding Payment
    • Order Booked
    • Order Rejected
    • Order Closed
    • Trade Executed
    • Order Fully Filled
    • Balance Adjustment
  • Orderbook
    • Introduction
    • Orderbook Snapshot
    • Orderbook Update
  • Price Ticks
    • Introduction
    • Price Tick
  • Book Ticker
    • Introduction
    • Book Tick
  1. WebSocket API

Ping / Pong

Overview#

To ensure stable and reliable WebSocket connections, we have implemented native ping-pong support in our WebSocket API. This helps detect and close broken connections, preventing clients from holding onto stale sockets.

How It Works#

The WebSocket ping is sent from the client to check if the server is still responsive.
The server responds with a pong message, confirming that the connection is alive.
If a pong response is not received within a certain timeout period, the client should attempt to reconnect.

Best Practices for Ping Management#

A recommended strategy is to send a ping when receiving a heartbeat message from the server. This ensures efficient connection health monitoring without unnecessary traffic.
Example Workflow:
1
The server sends a periodic heartbeat message.
{
  "type": "HEARTBEAT",
  "time": 1738602951685555981
}
2
Upon receiving a heartbeat, the client sends a ping request.
3
The server responds with a pong, confirming that the connection is still active.
4
If no pong response is received within a timeout period, the client should close the socket and reconnect.
Previous
Subscribe
Next
Introduction
Built with