Spaces:
Running
Running
Update app/nsepythonmodified.py
Browse files- app/nsepythonmodified.py +7 -7
app/nsepythonmodified.py
CHANGED
|
@@ -225,7 +225,7 @@ def index_history(symbol, start_date, end_date):
|
|
| 225 |
data = {'cinfo': f"{{'name':'{symbol}','startDate':'{start_date}','endDate':'{end_date}','indexName':'{symbol}'}}"}
|
| 226 |
payload = nse_session.s.post('https://niftyindices.com/Backpage.aspx/getHistoricaldatatabletoString', headers=niftyindices_headers, json=data).json()
|
| 227 |
payload = json.loads(payload["d"])
|
| 228 |
-
return pd.DataFrame.from_records(payload)
|
| 229 |
|
| 230 |
def index_pe_pb_div(symbol, start_date, end_date):
|
| 231 |
start_date = _fmt_date(start_date)
|
|
@@ -233,7 +233,7 @@ def index_pe_pb_div(symbol, start_date, end_date):
|
|
| 233 |
data = {'cinfo': f"{{'name':'{symbol}','startDate':'{start_date}','endDate':'{end_date}','indexName':'{symbol}'}}"}
|
| 234 |
payload = nse_session.s.post('https://niftyindices.com/Backpage.aspx/getpepbHistoricaldataDBtoString', headers=niftyindices_headers, json=data).json()
|
| 235 |
payload = json.loads(payload["d"])
|
| 236 |
-
return pd.DataFrame.from_records(payload)
|
| 237 |
|
| 238 |
def index_total_returns(symbol, start_date, end_date):
|
| 239 |
start_date = _fmt_date(start_date)
|
|
@@ -241,7 +241,7 @@ def index_total_returns(symbol, start_date, end_date):
|
|
| 241 |
data = {'cinfo': f"{{'name':'{symbol}','startDate':'{start_date}','endDate':'{end_date}','indexName':'{symbol}'}}"}
|
| 242 |
payload = nse_session.s.post('https://niftyindices.com/Backpage.aspx/getTotalReturnIndexString', headers=niftyindices_headers, json=data).json()
|
| 243 |
payload = json.loads(payload["d"])
|
| 244 |
-
return pd.DataFrame.from_records(payload)
|
| 245 |
|
| 246 |
# ------------------------- CSV / BHAV -------------------------
|
| 247 |
def nse_bhavcopy(d): return pd.read_csv("https://archives.nseindia.com/products/content/sec_bhavdata_full_"+d.replace("-","")+".csv")
|
|
@@ -269,11 +269,11 @@ def nse_largedeals(mode="bulk_deals"):
|
|
| 269 |
def nse_largedeals_historical(f,t,mode="bulk_deals"):
|
| 270 |
m = "bulk-deals" if mode=="bulk_deals" else "short-selling" if mode=="short_deals" else "block-deals"
|
| 271 |
p=nsefetch(f'https://www.nseindia.com/api/historical/{m}?from={f}&to={t}')
|
| 272 |
-
return pd.DataFrame(p["data"])
|
| 273 |
|
| 274 |
def nse_stock_hist(f,t,symbol,series="ALL"):
|
| 275 |
url=f"https://www.nseindia.com/api/historical/securityArchives?from={f}&to={t}&symbol={symbol.upper()}&dataType=priceVolumeDeliverable&series={series}"
|
| 276 |
-
return pd.DataFrame(nsefetch(url)['data'])
|
| 277 |
|
| 278 |
def nse_index_live(name="NIFTY 50"):
|
| 279 |
p=nsefetch(f"https://www.nseindia.com/api/equity-stockIndices?index={name.replace(' ','%20')}")
|
|
@@ -282,11 +282,11 @@ def nse_index_live(name="NIFTY 50"):
|
|
| 282 |
def nse_highlow(date_str):
|
| 283 |
date_str = date_str.replace("-", "")
|
| 284 |
url="https://archives.nseindia.com/content/indices/ind_close_all_"+date_str+".csv"
|
| 285 |
-
return pd.read_csv(url, header=0)
|
| 286 |
|
| 287 |
def stock_highlow(date_str):
|
| 288 |
date_str = date_str.replace("-", "")
|
| 289 |
url="https://archives.nseindia.com/content/CM_52_wk_High_low_"+date_str+".csv"
|
| 290 |
-
return pd.read_csv(url, header=2)
|
| 291 |
|
| 292 |
# ------------------------- END OF FILE -------------------------
|
|
|
|
| 225 |
data = {'cinfo': f"{{'name':'{symbol}','startDate':'{start_date}','endDate':'{end_date}','indexName':'{symbol}'}}"}
|
| 226 |
payload = nse_session.s.post('https://niftyindices.com/Backpage.aspx/getHistoricaldatatabletoString', headers=niftyindices_headers, json=data).json()
|
| 227 |
payload = json.loads(payload["d"])
|
| 228 |
+
return pd.DataFrame.from_records(payload).to_html()
|
| 229 |
|
| 230 |
def index_pe_pb_div(symbol, start_date, end_date):
|
| 231 |
start_date = _fmt_date(start_date)
|
|
|
|
| 233 |
data = {'cinfo': f"{{'name':'{symbol}','startDate':'{start_date}','endDate':'{end_date}','indexName':'{symbol}'}}"}
|
| 234 |
payload = nse_session.s.post('https://niftyindices.com/Backpage.aspx/getpepbHistoricaldataDBtoString', headers=niftyindices_headers, json=data).json()
|
| 235 |
payload = json.loads(payload["d"])
|
| 236 |
+
return pd.DataFrame.from_records(payload).to_html()
|
| 237 |
|
| 238 |
def index_total_returns(symbol, start_date, end_date):
|
| 239 |
start_date = _fmt_date(start_date)
|
|
|
|
| 241 |
data = {'cinfo': f"{{'name':'{symbol}','startDate':'{start_date}','endDate':'{end_date}','indexName':'{symbol}'}}"}
|
| 242 |
payload = nse_session.s.post('https://niftyindices.com/Backpage.aspx/getTotalReturnIndexString', headers=niftyindices_headers, json=data).json()
|
| 243 |
payload = json.loads(payload["d"])
|
| 244 |
+
return pd.DataFrame.from_records(payload).to_html()
|
| 245 |
|
| 246 |
# ------------------------- CSV / BHAV -------------------------
|
| 247 |
def nse_bhavcopy(d): return pd.read_csv("https://archives.nseindia.com/products/content/sec_bhavdata_full_"+d.replace("-","")+".csv")
|
|
|
|
| 269 |
def nse_largedeals_historical(f,t,mode="bulk_deals"):
|
| 270 |
m = "bulk-deals" if mode=="bulk_deals" else "short-selling" if mode=="short_deals" else "block-deals"
|
| 271 |
p=nsefetch(f'https://www.nseindia.com/api/historical/{m}?from={f}&to={t}')
|
| 272 |
+
return pd.DataFrame(p["data"]).to_html()
|
| 273 |
|
| 274 |
def nse_stock_hist(f,t,symbol,series="ALL"):
|
| 275 |
url=f"https://www.nseindia.com/api/historical/securityArchives?from={f}&to={t}&symbol={symbol.upper()}&dataType=priceVolumeDeliverable&series={series}"
|
| 276 |
+
return pd.DataFrame(nsefetch(url)['data']).to_html()
|
| 277 |
|
| 278 |
def nse_index_live(name="NIFTY 50"):
|
| 279 |
p=nsefetch(f"https://www.nseindia.com/api/equity-stockIndices?index={name.replace(' ','%20')}")
|
|
|
|
| 282 |
def nse_highlow(date_str):
|
| 283 |
date_str = date_str.replace("-", "")
|
| 284 |
url="https://archives.nseindia.com/content/indices/ind_close_all_"+date_str+".csv"
|
| 285 |
+
return pd.read_csv(url, header=0).to_html()
|
| 286 |
|
| 287 |
def stock_highlow(date_str):
|
| 288 |
date_str = date_str.replace("-", "")
|
| 289 |
url="https://archives.nseindia.com/content/CM_52_wk_High_low_"+date_str+".csv"
|
| 290 |
+
return pd.read_csv(url, header=2).to_html()
|
| 291 |
|
| 292 |
# ------------------------- END OF FILE -------------------------
|