UNPKG

nepse-data-module

Version:

A npm package to provide historical daily data for nepse until May 1st 2021 (which will be updated time to time).

47 lines (42 loc) 1.27 kB
const fix_data_format = (data)=>{ let grouped_data=[] data.t.forEach((value,index)=>{ grouped_data.push({ t:value, o:data.o[index], h:data.h[index], l:data.l[index], c:data.c[index], v:data.v[index] }) }); return grouped_data } const getIndexNames = ()=>{ return [ "Nepse", "Banking", "DevBanks", "Finance", "Hotels_and_Tourism", "Hydropower", "LifeInsurance", "Microfinance", "MutualFund", "NonLifeInsurance", "Others", "Trading" ] } const getIndex = (index_name='Nepse',from=Math.round(new Date()/1000),to=Math.round(new Date()/1000))=>{ if(!getIndexNames().includes(index_name)){throw 'Index name not found!';} const raw_index = require(`./rawdata/${index_name}.json`) let grouped_index={ name : index_name, data : fix_data_format(raw_index).filter((data)=>{ return data.t >= Math.round(new Date(from)/1000) && data.t <= Math.round(new Date(to)/1000) }) }; return grouped_index; } module.exports= {getIndex,getIndexNames}