1.0.0 • Published 4 years ago

pix-apidata-test v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

Introduction

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

Installation

npm i pix-apidata --save

Then...

Import module

const api = require("./apidata");

Initialize

const apiKey = "api-access-key" //privided by your data vendor
api.initialize(apiKey, ["host address/ip"]) 

Modules available

api.history
api.stream
api.callbacks

Callbacks for live streaming

Trade

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

//response data
{
  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

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

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

Refs data which has changed now

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

Refs snapshot data

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

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

Live stream subscription

Subscibe to receive ALL updates of the symbols subscibed

 api.stream.subscribeAll(['NIFTY-1']);

Subscibe to receive TRADE updates of the symbols subscibed

 api.stream.subscribeTrade(['NIFTY-1','BANKNIFTYNIFTY-1']);

Subscibe to receive REFS and BEST updates of the symbols subscibed

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

History data - Eod

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

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

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

History data - Inraday

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

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

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

History data - Ticks

//params: ticker, fromDateTime
api.history.getBackTicks("NIFTY-1", "20201116 15:00:00")

//response data
{
  tkr: 'BANKNIFTY-1',
  tm: 2020-11-16T15:00:01.000Z,
  pr: 23600,
  qt: 125,
  oi: 1692375
}