General
URL
Channels should use the domain:
wss://plasma-relay-backend.timex.io/socket/relay
How to Connect
Open up a websocket connection to the websocket URI.
Message encoding
Each message sent and received via the TimeX websocket channel is encoded in JSON format.
A token symbol must always be uppercase and an address must always be lowercase (i.e. BTC or 0xb18e6e42cd252b78731f4eec48a7d1cf6a0b3849 is valid, btc or 0x5E0EBAEd421589102AB78622e2F0cc6B632dc462 is invalid).
Message types
All requests include requestId
. This is a random unique identifier that will be sent by the server in messages, so the client can appropriately respond when multiple submissions are made.
Subscribe to Channels
To receive data from a channel on any account event you have to send a "subscribe" message.
// request
{
"type": "SUBSCRIBE",
"requestId": "uniqueID",
"pattern": "pattern",
"snapshot": false
}
// response
{
"type": "SUBSCRIBED",
"requestId": "uniqueID",
"subscriptionId": "5435a742-eed1-4874-951e-eefdfb559234",
"payload": null
}
You will receive updates to the pattern
events with the corresponding subscriptionId
. A list of all patterns can be found here.
Unsubscribe to Channels
To stop receiving data from a channel you must send an "unsubscribe" message.
// request
{
"type": "UNSUBSCRIBE",
"requestId": "uniqueID",
"subscriptionId": "5435a742-eed1-4874-951e-eefdfb559234"
}
// response
{
"type": "UNSUBSCRIBED",
"requestId": "uniqueID",
"subscriptionId": "5435a742-eed1-4874-951e-eefdfb559234",
"payload": null
}
Subscribe account to Channels
To receive data from a channel for all account events you must send a "subscribe account" message.
// request
{
"type": "ACCOUNT_SUBSCRIBE",
"requestId": "uniqueID",
"account": "account's wallet address",
"auth": {
"id": "3DE4C63C868C4A7591EE6CCEDF2487DB",
"secret": "RXQ4EYLOGULVA5MA"
},
"snapshot": false
}
// response
{
"type": "SUBSCRIBED",
"requestId": "uniqueID",
"subscriptionId": "864ff046-ba40-4c7b-95cb-cf75f9059916",
"payload": null
}
Unsubscribe account to Channels
To stop receiving data from a channel on all account events you must send an "unsubscribe" message for the account.
// request
{
"type": "UNSUBSCRIBE",
"requestId": "uniqueID",
"subscriptionId": "account's wallet address"
}
// response
{
"type": "UNSUBSCRIBED",
"requestId": "uniqueID",
"subscriptionId": "0xb18e6e42cd252b78731f4eec48a7d1cf6a0b3849",
"payload":null
}
Snapshot
Upon subscribing to a channel an initial snapshot can be sent. For this you must send a "subscribe" message with field snapshot
as true.
// request
{
"type": "SUBSCRIBE",
"requestId": "uniqueID",
"pattern": "pattern",
"snapshot": true
}
// response
{
"type": "SUBSCRIBED",
"requestId": "uniqueID",
"subscriptionId": "5435a742-eed1-4874-951e-eefdfb559234",
"payload": {
"snapshot":{
// data for snapshot
}
}
}
REST message
// request
{
"type": "REST",
"requestId": "uniqueID",
"stream": "stream",
"auth": {
"id": "api key",
"secret": "api secret"
},
"payload": {
// payload data
}
}
A list of all streams can be found here.
Error message
The error message has the following format:
{
"requestId": "uniqueID",
"status": "ERROR",
"message": "message"
}
Update message
The message for all events has the format:
{
"type": "MESSAGE",
"subscriptionId": "c14c2e0a-87cf-40d5-984c-043b0cd33daa",
"message": {
"id": 1267438,
"event": {
// event data
},
"payload": {
// payload data
}
}
}