Custom Websocket Client
Create Custom Websocket client to connect with CAYC Exchange Server
For an easier way to use websockets with CAYC Exchange
- Nodejs and NPM installed
- Nodejs version >= 12
You need to import
ws
library and create a connection with CAYC Exchange, For e.gconst WebSocket = require('ws');
const API_URL = 'https://api.cayc.exchange'
// Public connection
const publicSocket = new WebSocket(`${API_URL}/stream`);
You need to authenticate through the api either using Bearer token or with API key and Secret which you can obtain from the guide
API Expires field just used to define the validity of the connection.
const WebSocket = require('ws');
const API_URL = 'https://api.cayc.exchange'
// Bearer Token
const privateSocket = new WebSocket(`${API_URL}/stream?authorization=${BEARER_TOKEN}`);
// HMAC Authentication
const privateSocket = new WebSocket(`${API_URL}/stream?api-key=${API_KEY}&api-signature=${API_SIGNATURE}&api-expires=${API_EXPIRES}`);
// Bearer Token
privateSocket.send(
JSON.stringify({
op: 'auth',
args: [{
authorization: BEARER_TOKEN
}]
})
);
// HMAC Authentication
privateSocket.send(
JSON.stringify({
op: 'auth',
args: [{
'api-key': API_KEY,
'api-signature': API_SIGNATURE,
'api-expires': API_EXPIRES
}]
})
);
For a detailed documentation and to learn how it works with CAYC Network, Please visit the Repository
Last modified 11mo ago