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.4 : 28-Jan-2022
- Intraducing Option Greeks
v1.2.3 : 21-Aug-2021
- New callback for Trade snapshot during subscription, earlier it was provided along with Trade callback
- Segment subscription for the entitled user
v1.2.1 : 06-May-2021
- Upper and lower price band for EQ market added - refer 'Refs snapshot data' section
- Live ticks aggregation which provides current day minutes bar - refer 'History data - Inraday' section
Simple steps to up and running
For Streaming Data
- Initialize
- Register required callbacks in apidata.callbacks
- Do subscribe with symbols list in apidata.stream
For History Data
- Initialize
- 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
// 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
}
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
}
Option Greek data
//callback to listen for Greeks data
apidata.callbacks.onGreeks(msg => {
console.log(msg);
})
//response data
Greeks {
charm:14.932405471801758,
color:0.001146425143815577,
delta:0.03447486460208893,
dtr:-1.9232227802276611,
gamma:0.00012514894478954375,
iv:0.25891607999801636,
ivvwap:0.2617481052875519,
kind:'G',
speed:-0.28718340396881104,
tgr:1595.013916015625,
theta:-3.4568727016448975,
ticker:'NIFTY2220318500CE',
tv:-27622.068359375,
vega:1.7974374294281006,
veta:63964.1015625,
volga:0.000022048308892408386,
zomma:3.660402683181019e-7
}
Greek snapshot data
//callback to listen greek snapshot
apidata.callbacks.onGreekSnapshot(msg => {
console.log(msg);
})
//response data
Greeks {
charm:15.915078163146973
color:0.0011443555122241378
delta:0.03245270624756813
dtr:-1.9513144493103027
gamma:0.00011992053623544052
iv:0.259033739566803
ivvwap:0.26151764392852783
kind:'G'
speed:-0.3105531930923462
tgr:1725.9541015625
theta:-3.3120052814483643
ticker:'NIFTY2220318500CE'
tv:-27618.33203125
vega:1.6973202228546143
veta:68671.4140625
volga:0.000022329975763568655
zomma:3.58668728495104e-7
}
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']);
Unsubscribe live stream
//unsubscribe single symbol
await apidata.stream.unsubscribeAll(['NIFTY-1'])
//unsubscribe multiple symbol
await apidata.stream.unsubscribeAll(['NIFTY-1','BANKNIFTY-1'])
Subscribe Greek live stream
await apidata.stream.subscribeGreeks(['NIFTY2220318500CE'])
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"])
let eod = await apidata.history.getEod('NIFTY 50', '20201001', '20201030')
console.log(eod);
})