npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dxfeed/api

v1.6.0

Published

This package provides access to dxFeed streaming data

Downloads

3,236

Readme

@dxfeed/api Version

This package provides access to dxFeed streaming data.

Our package is easy to integrate with any modern framework.

Install

npm install @dxfeed/api

NodeJS usage

Install cometd-nodejs-client package

npm install cometd-nodejs-client

and use it in your code

require('cometd-nodejs-client').adapt()
// or
import * as CometdNodejsClient from 'cometd-nodejs-client'
CometdNodejsClient.adapt()

Basic Usage

We have several classes in implementation:

  • Feed (public)
  • Endpoint (private)
  • Subscriptions (private)

The Feed is entry point for configuration and creating subscriptions. Feed manages private classes for connecting and subscribing. The Endpoint is responsible for managing the web socket connection. Subscriptions for managing open subscriptions.

Import package

import Feed from '@dxfeed/api'

Configure & Create connection

Create instance of Feed.

const feed = new Feed()

Provide auth token if needed.

feed.setAuthToken('authToken')

Set web socket address and open connection.

feed.connect('wss://demo.dxfeed.com/webservice/cometd')

Configure & Create subscription

You should specify event types and symbol names.

feed.subscribe<{ value: number }>(
  [EventType.Summary, EventType.Trade] /* event types */,
  ['AEX.IND:TEI'] /* symbols */,
  handleEvent
)

For timed subscription you should also provide time to start subscription from.

For Candle event type along with base symbol, you should specify an aggregation period. You can also set price type. More details: https://kb.dxfeed.com/en/data-access/rest-api.html#candle-symbols

feed.subscribeTimeSeries<{ value: number }>(
  [EventType.Summary, EventType.Trade] /* event types */,
  ['AEX.IND:TEI'] /* symbols */,
  0 /* fromTime */,
  handleEvent
)

Last argument its event handler for process incoming events.

const handleEvent = (event) => {
  /* process event */
}

Close subscription

All subscribe methods return unsubscribe handler, you need to call this method for unsubscribe.

const unsubscribe = feed.subscribe(eventTypes, symbols, handleEvent)

onExit(() => unsubscribe())

Aggregated API

Get TimeSeries

If you want to get TimeSeries events for a given time period, refer to example below.

// inside async function
const events = await feed.getTimeSeries(
  'AAPL{=15m}',
  EventType.Candle,
  fromDate.getTime(),
  toDate.getTime()
)

Subscribe TimeSeries snapshot

If you want to subscribe to TimeSeries events, refer to example below.

const unsubscribe = feed.subscribeTimeSeriesSnapshot('AAPL{=15m}', EventType.Candle, (candles) => {
  // process candles
  chart.setCandles(candles)
})

Close connection

If you need to close the web socket connection

feed.disconnect()