Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dxfeed/api

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dxfeed/api

This package provides access to dxFeed streaming data

  • 1.6.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

@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()

FAQs

Package last updated on 31 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc