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

pix-apidata

v1.2.8

Published

JavaScript library to connect and stream the stock market data. This is websocket based library with the functionalyties to get eod and live streaming data

Downloads

12

Readme

AccelPix Data API

Introduction

JavaScript library to connect and stream the market data. This is websocket and fallback transport based library with all the functionalyties to get eod and live streaming data

Simple and easy integration with your web application/portal, all heavy weight work are back lifted.

What's new

v1.2.8 : 23-Jan-2024

  1. Greeks Chain Range subscription and unsubscription method.

v1.2.6 : 29-Aug-2022

  1. Option Chain and Option Chain Range subscription and unsubscription method.

v1.2.5 : 15-May-2022

  1. Previous OI added - refer 'Refs snapshot data' section
  2. Master data api with Lot size

v1.2.4 : 28-Jan-2022

  1. Intraducing Option Greeks

v1.2.3 : 21-Aug-2021

  1. New callback for Trade snapshot during subscription, earlier it was provided along with Trade callback
  2. Segment subscription for the entitled user

v1.2.1 : 06-May-2021

  1. Upper and lower price band for EQ market added - refer 'Refs snapshot data' section
  2. Live ticks aggregation which provides current day minutes bar - refer 'History data - Inraday' section

Simple steps to up and running

For Streaming Data

  1. Initialize
  2. Register required callbacks in apidata.callbacks
  3. Do subscribe with symbols list in apidata.stream

For History Data

  1. Initialize
  2. Async call to respective methods exposed in apidata.history

Working sample is available at the bottom of this help page

Installation

npm i pix-apidata --save

Import

const apidata = require("pix-apidata");

Browser

Modules are available in 'apidata' from the bundle.js

<script src=".\src\bundle.js"></script>

Initialize

This should be the first api call before making any other

const apiKey = "api-access-key" //provided by your data vendor
const apiHost = "apidata.accelpix.in" //provided by your data vendor
const scheme = "https" // use either http (default scheme) or https
await apidata.initialize(apiKey, apiHost, scheme) 

// *** IMPORTANT ***

// *** initialize(...) - returns a Promise and wait for it to complete before making any other API calls.

Symbol Master

Use below REST API to get Master Data

(Only for master data download due to larger data size)

https://apidata.accelpix.in/api/hsd/Masters/2?fmt=json

With LOT size

https://apidata.accelpix.in/api/hsd/Masters/3?fmt=json

// response data
// Returns Master[] with following structure
Master {
  xid: 1, // segment id. 1 - EQ, 2 - F&O, 3 - NCD, 5 - MCX and so on
  tkr: '20MICRONS', // ticker name - used to communicate with server for data
  atkr: null, // alternative ticker - used for mapping or display purpose
  ctkr: null, // contract ticker or current name of FUT - used for mapping or display purpose
  exp: 1970-01-01T00:00:00.000Z, // contract expiry or default to UNIX time
  utkr: null, // underlying ticker of F&O contract, eg. NIFTY for NIFTY FUT or NIFTY OPT
  inst: 'EQUITY', // instrument name of the symbol - EQUITY, FUTSTK, FUTIDX, OPTSTK, OPTIDX etc.
  a3tkr: null, // another alternative ticker - used for mapping or display purpose
  sp: '0.00', // strike price of the option contract
  tk: 16921, // exchange defined token of the symbol
  lot: 0 //Lot size
}

Modules available

apidata.history
apidata.stream
apidata.callbacks

Callbacks for live streaming

Trade data

//callback to listen for trade data
apidata.callbacks.onTrade(msg => {
  console.log(msg);
})

//response data
Trade {
  id: 0,
  ticker: 'BANKNIFTY-1',
  segmentId: 2,
  time: 2020-11-16T15:30:00.000Z,
  price: 23560,
  qty: 300,
  volume: 7499525,
  oi: 1503450,
  kind: 'T'
}

Trade snapshot data

//callback to listen for trade snapshot, called during subcription process, 
//listen to onTrade callback for continuouse stream data
apidata.callbacks.onTradeSnapshot(msg => {
  console.log(msg);
})

//response data
Trade {
  id: 0,
  ticker: 'BANKNIFTY-1',
  segmentId: 2,
  time: 2020-11-16T15:30:00.000Z,
  price: 23560,
  qty: 300,
  volume: 7499525,
  oi: 1503450,
  kind: 'T'
}

Best data

//callback to listen for bid, ask and respective qty
apidata.callbacks.onBest(msg => {
  console.log(msg);
})

//response data
Best {
  ticker: 'NIFTY-1',
  segmentId: 2,
  kind: 'B',
  bidPrice: 11766.65,
  bidQty: 300,
  askPrice: 11768.05,
  askQty: 225,
  time: 2061-09-02T07:00:00.000Z
}

Recent change in Refs data

//callback to listen for change in o, h, l, c, oi and avg data
apidata.callbacks.onRefs(msg => {
  console.log(msg);
})

//response data
Refs {
  kind: 'A',
  ticker: 'NIFTY-1',
  segmentId: 2,
  price: 11788.17
}

Refs snapshot data

//callback to listen for o, h, l, c, oi and avg snapshot
apidata.callbacks.onRefsSnapshot(msg => {
  console.log(msg);
})

//response data
RefsSnapshot {
  kind: 'V',
  ticker: 'BANKNIFTY-1',
  segmentId: 2,
  open: 23201.2,
  close: 23110.3,
  high: 23717,
  low: 23183,
  avg: 23470.65,
  oi: 1503450,
  upperBand: 0,
  lowerBand: 0,
  poi: 15898756
}

Option Greek data

//callback to listen for Greeks data
apidata.callbacks.onGreeks(msg => {
  console.log(msg);
})

//response data
Greeks {
  kind: 'G',
  token: 0,
  ticker: 'BANKNIFTY2240737500CE',
  iv: 0.2588011622428894,
  delta: 0.8822246193885803,
  theta: -77.46974182128906,
  vega: 2.561089515686035,
  gamma: 0.0005879841046407819,
  ivvwap: 0.18449798226356506,
  vanna: -3.667503833770752,
  charm: 1.109373927116394,
  speed: -0.000002092838712997036,
  zomma: 0.0009008663473650813,
  color: 0.0002725007652770728,
  volga: 5643.75439453125,
  veta: 2929.610107421875,
  tgr: -131754.828125,
  tv: -30.24874496459961,
  dtr: -0.011387989856302738,
  highiv: 0,
  lowiv: 0,
  twapiv: 0.19661587476730347,
  timestamp: 0  timestamp:1333597502420254464 //Time in nanoseconds from 01-Jan-1980 00:00:00 UTC
}

Greek snapshot data

//callback to listen greek snapshot
apidata.callbacks.onGreekSnapshot(msg => {
  console.log(msg);
})

//response data
Greeks {
  kind: 'G',
  token: 0,
  ticker: 'BANKNIFTY2240737500CE',
  iv: 0.2588011622428894,
  delta: 0.8822246193885803,
  theta: -77.46974182128906,
  vega: 2.561089515686035,
  gamma: 0.0005879841046407819,
  ivvwap: 0.18449798226356506,
  vanna: -3.667503833770752,
  charm: 1.109373927116394,
  speed: -0.000002092838712997036,
  zomma: 0.0009008663473650813,
  color: 0.0002725007652770728,
  volga: 5643.75439453125,
  veta: 2929.610107421875,
  tgr: -131754.828125,
  tv: -30.24874496459961,
  dtr: -0.011387989856302738,
  highiv: 0,
  lowiv: 0,
  twapiv: 0.19661587476730347,
  timestamp:1333597502420254464 //Time in nanoseconds from 01-Jan-1980 00:00:00 UTC
}

Callbacks for connection status

// Fired when connection is successful
apidata.callbacks.onConnected(() => {
  console.log("Connected successfully...");
})

// Fired when the connection is closed after automatic retry or some issues in networking
// Need to re-establish the connection manually
apidata.callbacks.onClosed((err) => {
  console.log("Connected close due to...", err);
})

Live stream subscription

Subscribe to receive updates of segments entitled to you

var needSnapshot = false;
var status = await apidata.stream.subscribeSegments(needSnapshot)
// IMPORTANT NOTE:
// If needSnapshot = true, then buffer the updates received on 'apidata.callbacks.onTradeSnapshot' and 'apidata.callbacks.onRefsSnapshot' before processing. 
// Data transfer is huge and you may get disconnected from server in-case if you don't process the incoming updates as fast enough.
// It's advised to buffer the data then process it once 'apidata.stream.subscribeSegments' method returns.

Subscribe to receive ALL updates of the symbols subscribed

//subscribe single symbol
await apidata.stream.subscribeAll(['NIFTY-1'])
//subscribe multiple symbol
await apidata.stream.subscribeAll(['NIFTY-1','BANKNIFTY-1'])

Subscribe to receive TRADE updates of the symbols subscribed

await apidata.stream.subscribeTrade(['NIFTY-1','BANKNIFTY-1'])

Subscribe to receive REFS and BEST updates of the symbols subscribed

await apidata.stream.subscribeBestAndRefs(['NIFTY-1','INFY-1']);

Subscribe Greek live stream

await apidata.stream.subscribeGreeks(['NIFTY2220318500CE'])

Subscribe Option chain live stream

//params: underlying ticker, ExpiryDate
await apidata.stream.subscribeOptionChain('NIFTY', '20220609');

Unsubscribe live stream

//unsubscribe single symbol
await apidata.stream.unsubscribeAll(['NIFTY-1'])
//unsubscribe multiple symbol
await apidata.stream.unsubscribeAll(['NIFTY-1','BANKNIFTY-1'])

Subscribe and Unsubscribe Greeks data

await apidata.stream.subscribeGreeks(['NIFTY2220318500CE','NIFTY2220318000PE'])
await apidata.stream.unsubscribeGreeks(['NIFTY2220318500CE','NIFTY2220318000PE'])

Subscribe and Unsubscribe Option Chain

//subscribe to full chain
//params: underlying ticker, ExpiryDate
await apidata.stream.subscribeOptionChain('BANKNIFTY','20220901')

//subscribe to range of strikes(CE, PE) considering current spot value(at time of subscribe) as the mid-point, essentially 10 strike(CE,PE) below mid-point and 10 strikes(CE, PE) above mid-point and total of 40 contracts subscribed for the below call.
//params: underlying ticker, ExpiryDate, NoOfStrikes
await apidata.stream.subscribeOptionChainRange('NIFTY','20220901',10)

//unsubscribe the chain
await apidata.stream.unsubscribeOptionChain('NIFTY','20220901')

Subscribe and Unsubscribe Greeks Chain


//subscribe to range of strikes(CE, PE) considering current spot value(at time of subscribe) as the mid-point, essentially 10 strike(CE,PE) below mid-point and 10 strikes(CE, PE) above mid-point and total of 40 contracts subscribed for the below call.
//params: underlying ticker, ExpiryDate, NoOfStrikes

await apidata.stream.subscribeGreeksChainRange('NIFTY','20220901',10)

//unsubscribe the chain
await apidata.stream.unsubscribeGreeksChain('NIFTY','20220901')

History data - Eod

//*** Continues data
//params: ticker, startDate, endDate
await apidata.history.getEod("NIFTY-1", "20200828", "20200901")

//*** Contract data
//params: underlying ticker, startDate, endDate, contractExpiryDate
await apidata.history.getEodContract("NIFTY", "20200828", "20200901", "20201029")

//response data
{
  td: '2020-08-28T00:00:00',
  op: 11630,
  hp: 11708,
  lp: 11617.05,
  cp: 11689.05,
  vol: 260625,
  oi: 488325
}

History data - Inraday

Provides intra-eod bars with the time resolution in minutes (default:'5' mins)

You can set minute resolution to '1', '5', '10' and so on.

Custom minute resolution also supported like '3', '7' and so on.

Passing CURRENT DATE as parameter in 'toDate' will respond the LIVE ticks aggregated upto the time it traded today. Last BAR of the current day may be incomplete. Current day tick aggregation response will always provide complete bar list from the beginning of day.

//*** Continues data
//params: ticker, startDate, endDate, resolution
await apidata.history.getIntraEod("NIFTY-1", "20200828", "20200901", "5")

//*** Contract data
//params: underlying ticker, startDate, endDate, contractExpiryDate
await apidata.history.getIntraEodContract("NIFTY", "20200828", "20200901", "20201029", "5")

//response data
{
  td: '2020-08-28T09:15:00',
  op: 11630,
  hp: 11643.45,
  lp: 11630,
  cp: 11639.8,
  vol: 4575,
  oi: 440475
}

History data - Ticks

Provides back log ticks from the date time specified till current live time, that is the ticks available till request hit the server.

//params: ticker, fromDateTime
await apidata.history.getBackTicks("BANKNIFTY-1", "20201016 15:00:00")

//response data
{
  td: 2020-11-16T15:00:01.000Z,
  pr: 23600,
  vol: 125,
  oi: 1692375
}

Example

var apidata = require('pix-apidata')

const apiKey = "your-api-key"
const apiServer = "apidata.accelpix.in"

apidata.callbacks.onTrade(t => {
  console.log(t);
})
apidata.callbacks.onGreeks(greek => {
  console.log(greek);
})

apidata.initialize(apiKey, apiServer)
  .then(async () => {
    await apidata.stream.subscribeAll(['NIFTY-1'])
    await apidata.stream.subscribeGreeks(["NIFTY2220318500CE"])
    await apidata.stream.subscribeOptionChainRange('NIFTY', '20220609',7)
    await apidata.stream.subscribeGreeksChainRange('NIFTY', '20220609',5)
    // await apidata.stream.unsubscribeOptionChain('NIFTY', '20220609');
    let eod = await apidata.history.getEod('NIFTY 50', '20201001', '20201030')
    console.log(eod);
  })

Powered by ticAnalytics®