This package provides access to dxFeed streaming data.
Our package is easy to integrate with any modern framework.
yarn add @dxfeed/api
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 Feed from '@dxfeed/api'
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://tools.dxfeed.com/webservice/cometd')
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/display/DS/REST+API#RESTAPI-Candlesymbols.
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 */
}
All subscribe methods return unsubscribe handler, you need to call this method for unsubscribe.
const unsubscribe = feed.subscribe(eventTypes, symbols, handleEvent)
onExit(() => unsubscribe())
If you need to close the web socket connection
feed.disconnect()