0.1.1 • Published 3 years ago
@cryptosight/api-ws-sdk v0.1.1
CRYPTOSIGHT-API-WS-SDK
The API WS SDK is a simplified NodeJS developer library based on WebSocket to fetch the real-time data from cryptosight.com.
Documentation
Please refer to the official documentation for more detailed description.
Install
$ npm install @cryptosight/api-ws-sdk
Examples
An API key is required to access web socket. Get your free API Key @ cryptosight.com.
const API_WS_SDK = require('@cryptosight/api-ws-sdk')
const ws = new API_WS_SDK({ key: 'YOUR_API_KEY' })
ws.connect() // init connection
ws.onAuth((error) => {
if (error) {
// auth error / fail
} else {
// ready to subscribe channel(s)
ws.subscribe('CHANNEL_ID')
}
})
ws.onMessage((message) => {
const pMessage = JSON.parse(message)
if (pMessage.event) {
// event message
} else {
// channel message
}
})
ws.onOpen(() => {
// connection is opened / reconnect opened
})
ws.onClose(() => {
// connection is closed / reconnect closed / disconnect
})
ws.onError((error) => {
// connection error
})