eshan6704 commited on
Commit
20175a7
·
verified ·
1 Parent(s): 5534b57

Update nsepython.py

Browse files
Files changed (1) hide show
  1. nsepython.py +50 -9
nsepython.py CHANGED
@@ -182,23 +182,64 @@ def nse_index():
182
  p=nsefetch('https://iislliveblob.niftyindices.com/jsonfiles/LiveIndicesWatch.json')
183
  return pd.DataFrame(p['data'])
184
 
185
- def index_history(sym,sd,ed):
 
 
 
 
186
  sd = sd.replace("-", "")
187
  ed = ed.replace("-", "")
188
- d={'cinfo':f"{{'name':'{sym}','startDate':'{sd}','endDate':'{ed}','indexName':'{sym}'}}"}
189
- p=json.loads(requests.post('https://niftyindices.com/Backpage.aspx/getHistoricaldatatabletoString', headers=niftyindices_headers, json=d).json()["d"])
 
 
 
 
 
 
 
 
 
 
190
  return pd.DataFrame.from_records(p)
191
 
192
- def index_pe_pb_div(sym,sd,ed):
193
- d={'cinfo':f"{{'name':'{sym}','startDate':'{sd}','endDate':'{ed}','indexName':'{sym}'}}"}
194
- p=json.loads(requests.post('https://niftyindices.com/Backpage.aspx/getpepbHistoricaldataDBtoString', headers=niftyindices_headers, json=d).json()["d"])
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  return pd.DataFrame.from_records(p)
196
 
197
- def index_total_returns(sym,sd,ed):
198
- d={'cinfo':f"{{'name':'{sym}','startDate':'{sd}','endDate':'{ed}','indexName':'{sym}'}}"}
199
- p=json.loads(requests.post('https://niftyindices.com/Backpage.aspx/getTotalReturnIndexString', headers=niftyindices_headers, json=d).json()["d"])
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  return pd.DataFrame.from_records(p)
201
 
 
202
  def nse_bhavcopy(d): return pd.read_csv("https://archives.nseindia.com/products/content/sec_bhavdata_full_"+d.replace("-","")+".csv")
203
  def nse_bulkdeals(): return pd.read_csv("https://archives.nseindia.com/content/equities/bulk.csv")
204
  def nse_blockdeals(): return pd.read_csv("https://archives.nseindia.com/content/equities/block.csv")
 
182
  p=nsefetch('https://iislliveblob.niftyindices.com/jsonfiles/LiveIndicesWatch.json')
183
  return pd.DataFrame(p['data'])
184
 
185
+ import json
186
+ import requests
187
+ import pandas as pd
188
+
189
+ def index_history(sym, sd, ed):
190
  sd = sd.replace("-", "")
191
  ed = ed.replace("-", "")
192
+
193
+ payload = {
194
+ "cinfo": f"{{'name':'{sym}','startDate':'{sd}','endDate':'{ed}','indexName':'{sym}'}}"
195
+ }
196
+
197
+ r = requests.post(
198
+ "https://niftyindices.com/Backpage.aspx/getHistoricaldatatabletoString",
199
+ headers=niftyindices_headers,
200
+ json=payload
201
+ )
202
+
203
+ p = json.loads(r.json()["d"])
204
  return pd.DataFrame.from_records(p)
205
 
206
+
207
+ def index_pe_pb_div(sym, sd, ed):
208
+ sd = sd.replace("-", "")
209
+ ed = ed.replace("-", "")
210
+
211
+ payload = {
212
+ "cinfo": f"{{'name':'{sym}','startDate':'{sd}','endDate':'{ed}','indexName':'{sym}'}}"
213
+ }
214
+
215
+ r = requests.post(
216
+ "https://niftyindices.com/Backpage.aspx/getpepbHistoricaldataDBtoString",
217
+ headers=niftyindices_headers,
218
+ json=payload
219
+ )
220
+
221
+ p = json.loads(r.json()["d"])
222
  return pd.DataFrame.from_records(p)
223
 
224
+
225
+ def index_total_returns(sym, sd, ed):
226
+ sd = sd.replace("-", "")
227
+ ed = ed.replace("-", "")
228
+
229
+ payload = {
230
+ "cinfo": f"{{'name':'{sym}','startDate':'{sd}','endDate':'{ed}','indexName':'{sym}'}}"
231
+ }
232
+
233
+ r = requests.post(
234
+ "https://niftyindices.com/Backpage.aspx/getTotalReturnIndexString",
235
+ headers=niftyindices_headers,
236
+ json=payload
237
+ )
238
+
239
+ p = json.loads(r.json()["d"])
240
  return pd.DataFrame.from_records(p)
241
 
242
+
243
  def nse_bhavcopy(d): return pd.read_csv("https://archives.nseindia.com/products/content/sec_bhavdata_full_"+d.replace("-","")+".csv")
244
  def nse_bulkdeals(): return pd.read_csv("https://archives.nseindia.com/content/equities/bulk.csv")
245
  def nse_blockdeals(): return pd.read_csv("https://archives.nseindia.com/content/equities/block.csv")