0.1.0 • Published 2 years ago

@talib-pro/api-ws-sdk v0.1.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

TALIB-API-WS-SDK

The API WS SDK is a simplified NodeJS developer library based on WebSocket to fetch the real-time data from talib.pro.

Documentation

Please refer to the official documentation for more detailed description.

Install

$ npm install @talib-pro/api-ws-sdk

Examples

No authentication is required at the moment but is subject to change without notice.

const API_WS_SDK = require('@talib-pro/api-ws-sdk')
const ws = new API_WS_SDK()

ws.connect() // init connection

ws.onAuth((error) => {
  if (error) {
    console.error(error) // auth error / fail
  } else {
    // subscribe to channel and indicators with previous data
    ws.subscribe('BINANCE:BTCUSDT|1h', ['RSI', 'MACD', 'CCI:20,hlc3'], true)
    // subscribe to channel and indicators without previous data
    ws.subscribe('BINANCE:ETHUSDT|1h', ['RSI'])
  }
})

ws.onMessage((payload) => {
  console.log(payload) // receive payload
})

ws.onOpen(() => {
  // connection is opened / reconnect opened
})

ws.onClose(() => {
  // connection is closed / reconnect closed / disconnect
})

ws.onError((error) => {
  console.error(error) // connection error
})

API

constructor()

ws.connect()

ws.onAuth(callback)

ws.onMessage(callback)

ws.onOpen(callback)

ws.onClose(callback)

ws.onError(callback)

ws.subscribe(channel)

ws.unsubscribe(channel)

ws.disconnect()