@dxfeed/dxlink-websocket-client
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

@dxfeed/dxlink-websocket-client

Client implementation for the dxLink WebSocket transport protocol.

Install

npm install @dxfeed/dxlink-websocket-client

Usage

Import library into your project.

import { DXLinkWebSocketClient } from '@dxfeed/dxlink-websocket-client'

Client

Create instance of the client.

const client = new DXLinkWebSocketClient()

Connect to the server.

client.connect('wss://demo.dxfeed.com/dxlink-ws')

Provide auth token if required by the server.

client.setAuthToken(token)

Channels

Open isolated channel to service within single connection.

const channel = client.openChannel('FEED', {
  contract: 'AUTO',
})

Send message to the channel.

channel.send({
  type: 'FEED_SUBSCRIPTION',
  add: [
    {
      type: 'Quote',
      symbol: 'AAPL',
    },
  ],
})

Add subscription to the channel.

const sub1 = {
  type: 'Quote',
  symbol: 'AAPL',
}

channel.subscription({
  add: [sub1],
})

Remove subscription from the channel.

channel.subscription({
  remove: [sub1],
})

Receive messages from the channel.

channel.addMessageListener((message) => {
  if (message.type === 'FEED_DATA') {
    console.log(message.data)
  }
})

Package Sidebar

Install

npm i @dxfeed/dxlink-websocket-client

Homepage

dxfeed.com/

Weekly Downloads

125

Version

0.3.0

License

MPL-2.0

Unpacked Size

152 kB

Total Files

20

Last publish

Collaborators

  • mvkvl
  • vitaliymatveev
  • dvpetrov