Spaces:
Running
Running
Update app/nsepythonmodified.py
Browse files- app/nsepythonmodified.py +24 -8
app/nsepythonmodified.py
CHANGED
|
@@ -220,24 +220,40 @@ def nse_index(): return pd.DataFrame(nsefetch('https://iislliveblob.niftyindices
|
|
| 220 |
|
| 221 |
# ------------------------- INDEX FUNCTIONS -------------------------
|
| 222 |
def index_history(symbol, start_date, end_date):
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 =
|
| 232 |
-
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).to_html()
|
| 237 |
|
| 238 |
def index_total_returns(symbol, start_date, end_date):
|
| 239 |
-
start_date =
|
| 240 |
-
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"])
|
|
|
|
| 220 |
|
| 221 |
# ------------------------- INDEX FUNCTIONS -------------------------
|
| 222 |
def index_history(symbol, start_date, end_date):
|
| 223 |
+
# Convert frontend format → NSE expected format
|
| 224 |
+
start_date = datetime.strptime(start_date, "%d-%m-%Y").strftime("%d%m%Y")
|
| 225 |
+
end_date = datetime.strptime(end_date, "%d-%m-%Y").strftime("%d%m%Y")
|
| 226 |
+
|
| 227 |
+
data = {
|
| 228 |
+
'cinfo': (
|
| 229 |
+
f"{{'name':'{symbol}',"
|
| 230 |
+
f"'startDate':'{start_date}',"
|
| 231 |
+
f"'endDate':'{end_date}',"
|
| 232 |
+
f"'indexName':'{symbol}'}}"
|
| 233 |
+
)
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
payload = nse_session.s.post(
|
| 237 |
+
'https://niftyindices.com/Backpage.aspx/getHistoricaldatatabletoString',
|
| 238 |
+
headers=niftyindices_headers,
|
| 239 |
+
json=data
|
| 240 |
+
).json()
|
| 241 |
+
|
| 242 |
payload = json.loads(payload["d"])
|
| 243 |
+
|
| 244 |
return pd.DataFrame.from_records(payload).to_html()
|
| 245 |
|
| 246 |
def index_pe_pb_div(symbol, start_date, end_date):
|
| 247 |
+
start_date = datetime.strptime(start_date, "%d-%m-%Y").strftime("%d%m%Y")
|
| 248 |
+
end_date = datetime.strptime(end_date, "%d-%m-%Y").strftime("%d%m%Y")
|
| 249 |
data = {'cinfo': f"{{'name':'{symbol}','startDate':'{start_date}','endDate':'{end_date}','indexName':'{symbol}'}}"}
|
| 250 |
payload = nse_session.s.post('https://niftyindices.com/Backpage.aspx/getpepbHistoricaldataDBtoString', headers=niftyindices_headers, json=data).json()
|
| 251 |
payload = json.loads(payload["d"])
|
| 252 |
return pd.DataFrame.from_records(payload).to_html()
|
| 253 |
|
| 254 |
def index_total_returns(symbol, start_date, end_date):
|
| 255 |
+
start_date = datetime.strptime(start_date, "%d-%m-%Y").strftime("%d%m%Y")
|
| 256 |
+
end_date = datetime.strptime(end_date, "%d-%m-%Y").strftime("%d%m%Y")
|
| 257 |
data = {'cinfo': f"{{'name':'{symbol}','startDate':'{start_date}','endDate':'{end_date}','indexName':'{symbol}'}}"}
|
| 258 |
payload = nse_session.s.post('https://niftyindices.com/Backpage.aspx/getTotalReturnIndexString', headers=niftyindices_headers, json=data).json()
|
| 259 |
payload = json.loads(payload["d"])
|