WebSocket
Base URL
Before Subscription
Before subscription, the user needs to get a connect key, otherwise, the websocket connection will be refused. The full connection steps are listed below:
Get wsApiKey by access REST path "/v3/ws/key", and you will get a response like
{"key":"fx2xW5hoVFbcaanWS"}
Use
fx2xW5hoVFbcaanWS
as a wsApiKey param in ws path, i.e., wss://ws.uat2.loopring.io/v3/ws?wsApiKey=fx2xW5hoVFbcaanWS.
Subscription
Clients can send JSON to subscribe to multiple topics:
In one subscription request, if at least one topic requires the ApiKey, then the
apiKey
filed is required;In one subscription request, the same topic configuration can only occur once;
In one subscription request, if there are any configuration errors, the entire subscription request fails;
If
unsubscribeAll
istrue
, all previous subscriptions will be cancelled;If
sequence
is provided, the relayer will use the same sequence number in its response.
Unsubscription
Clients can send JSON to unsubscribe from multiple topics:
In one unsubscription request, if at least one topic requires the ApiKey, then the
apiKey
filed is required;In one unsubscription request, the same topic configuration can only occur once;
In one unsubscription request, if there are any configuration errors, the entire unsubscription request fails;
If the top-level
unsubscribeAll
istrue
, all previous subscriptions will be cancelled; if the per-topicunsubscribeAll
istrue
, then all subscriptions to that topic will be cancelled;If
sequence
is provided, the relayer will use the same sequence number in its response.Subscribe up to 20 topics in total.
Heartbeat
After a WebSocket connection is established, the relay will send a "ping" message to the client for heartbeat detection every 30 seconds. If the client does not reply with a "pong" message within 2 minutes, the relay will disconnect. If the number of "pong" messages exceeds the number of "ping" messages, the relay will also disconnect.
Response
op
string
Y
"sub" or "unSub"
sequence
integer
N
A client-side sequence number
topics
JSON
Y
Topics and their configurations
result
Y
Subscription result
Result
status
string
Y
Status code
error
N
Error
Error
code
integer
Y
Value
message
string
Y
Error message
Status code
Value
Note
104100
Topic missing
104101
Invalid op code
104102
Invalid topic
104103
Duplicate topic configs
104104
Missing ApiKey
104105
ApiKey mismatched
104112
Invalid ApiKey
104113
Subscription not found
104114
Invalid ApiKey (user not found)
104115
Invalid topic config
104116
exceed maximum subscriptions
Examples
A successful subscription:
A failed subscription:
Another failed subscription:
Last updated