Coder Social home page Coder Social logo

prodderman / dxfeed-js-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dxfeed/dxfeed-js-api

0.0 0.0 0.0 4.42 MB

dxFeed JavaScript API

Home Page: https://dxfeed.github.io/dxfeed-js-api/

License: Mozilla Public License 2.0

JavaScript 1.27% TypeScript 98.73%

dxfeed-js-api's Introduction

@dxfeed/api Version

This package provides access to dxFeed streaming data.

Our package is easy to integrate with any modern framework.

Install

yarn add @dxfeed/api

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://tools.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/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 */
}

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

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

Close connection

If you need to close the web socket connection

feed.disconnect()

dxfeed-js-api's People

Contributors

fyzu avatar palmze avatar dependabot[bot] avatar nikolaenkov avatar loginovkonstantin avatar coolassassin avatar feinminen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.