Trading API

WebSocket Trading API is a real-time trading gateway based on the WebSocket protocol. By establishing a persistent connection, WebSocket provides more stable execution latency compared to REST APIs.

Address

wss://stream-hk.osl.com/ws/v5/trade
wss://stream-hk.oslsandbox.com/ws/v5/trade

Generic Message Format

Request

{
  "id": "request-id",
  "op": "operation type",
  "args": { ... },
  "timestamp": 1787042800000,
  "validTimeWindow": 5000
}
FieldTypeRequiredDescription
idstringNoRequest ID, returned as-is in the response
opstringYesOperation type
argsobjectDepends on opBusiness parameters
timestamplongNoClient request timestamp (Unix milliseconds), used for request expiry validation; must be used together with validTimeWindow
validTimeWindowlongNoValid time window (milliseconds). If provided, it must be greater than 0, otherwise the request is rejected (Param error). When the server receives the request, it is rejected (Timestamp request expired) if |serverTime - timestamp| exceeds this window. No expiry validation is performed when timestamp or validTimeWindow is not provided

Note: the envelope-level timestamp here is different from login's args.timestamp (the HMAC signature timestamp); they serve different purposes and do not affect each other.

Response

{
  "id": "request-id",
  "op": "operation type",
  "code": 0,
  "msg": "",
  "data": [...],
  "inTime": 1787060806850,
  "outTime": 1787060806856
}
FieldTypeDescription
idstringRequest ID
opstringOperation type
codeint0 indicates success, non-zero is an error code
msgstringError message (not returned on success)
dataobject/arrayBusiness data (returned on success, omitted when null)
inTimelongTimestamp (milliseconds) when the server received the request; omitted when null
outTimelongServer timestamp (milliseconds)

Connection Lifecycle

  1. Login must be completed within 30 seconds after the connection is established, otherwise a Login timeout is returned and the connection is closed.
  2. The connection is closed after being idle (no data received) for 30 seconds, returning a Reader idle timeout.
  3. On service shutdown, a countdown notification will be broadcast for 60 seconds at 10-second intervals. Upon receiving this message, the client should initiate a reconnection to a new node to prevent service disruption caused by unexpected disconnects when the countdown expires. Below is the message format the client will receive:
    {"code":30017,"msg":"Service is going down for maintenance, connection will close in 30 seconds. Please reconnect.","outTime":"1787126511945"}

Error Codes

codemsg
30001{field} doesn't exist
30002Unrecognized request:{message}
30003INVALID op:{op}
30004User not logged in/User must be logged in
30005Login failure
30006request too many
30007request over limit,connection close
30011Invalid ACCESS_KEY
30013Invalid ACCESS_TIMESTAMP
30014Timestamp request expired
30015Invalid sign
30016Param error
30017Service is going down for maintenance, connection will close in {n} seconds. Please reconnect.
30018Internal error
30019Reader idle timeout
30020Login timeout
30021Your API Key does not have trading permission
30022Invalid account
30023Already logged in
30024Forbidden
30025Request processing timeout, please retry

Trading error codes (for single-order failures within the data array) are negative numbers.