Update nsepython.py
Browse files- nsepython.py +0 -228
nsepython.py
CHANGED
|
@@ -216,231 +216,3 @@ def stock_hist(f,t,symbol,series="ALL"):
|
|
| 216 |
def nse_index_live(name="NIFTY 50"):
|
| 217 |
p=nsefetch(f"https://www.nseindia.com/api/equity-stockIndices?index={name.replace(' ','%20')}")
|
| 218 |
return {"data":df_from_data(p.pop("data")) if "data" in p else pd.DataFrame(), "rem":df_from_data([p])}
|
| 219 |
-
def indices_list():
|
| 220 |
-
indices
|
| 221 |
-
|
| 222 |
-
import json
|
| 223 |
-
|
| 224 |
-
def build_indices_html():
|
| 225 |
-
|
| 226 |
-
p=indices()
|
| 227 |
-
|
| 228 |
-
data_df = p["data"]
|
| 229 |
-
dates_df = p["dates"]
|
| 230 |
-
|
| 231 |
-
# Convert to JSON for JS
|
| 232 |
-
data_json = json.dumps(data_df.to_dict(orient="records"), ensure_ascii=False)
|
| 233 |
-
dates_json = json.dumps(dates_df.to_dict(orient="records"), ensure_ascii=False)
|
| 234 |
-
|
| 235 |
-
DEFAULT_KEY = "INDICES ELIGIBLE IN DERIVATIVES"
|
| 236 |
-
DEFAULT_SYMBOL = "NIFTY 50"
|
| 237 |
-
|
| 238 |
-
html = f"""
|
| 239 |
-
<!DOCTYPE html>
|
| 240 |
-
<html>
|
| 241 |
-
<head>
|
| 242 |
-
<meta charset="UTF-8">
|
| 243 |
-
<title>NSE Indices Dashboard</title>
|
| 244 |
-
|
| 245 |
-
<style>
|
| 246 |
-
body {{
|
| 247 |
-
font-family: Arial, sans-serif;
|
| 248 |
-
padding: 20px;
|
| 249 |
-
}}
|
| 250 |
-
.scroll-table {{
|
| 251 |
-
width: 100%;
|
| 252 |
-
overflow: auto;
|
| 253 |
-
border: 1px solid #ccc;
|
| 254 |
-
max-height: 450px;
|
| 255 |
-
margin-bottom: 20px;
|
| 256 |
-
}}
|
| 257 |
-
table {{
|
| 258 |
-
border-collapse: collapse;
|
| 259 |
-
width: max-content;
|
| 260 |
-
min-width: 100%;
|
| 261 |
-
}}
|
| 262 |
-
th, td {{
|
| 263 |
-
border: 1px solid #ddd;
|
| 264 |
-
padding: 8px;
|
| 265 |
-
white-space: nowrap;
|
| 266 |
-
}}
|
| 267 |
-
th {{
|
| 268 |
-
background-color: #007bff;
|
| 269 |
-
color: white;
|
| 270 |
-
position: sticky;
|
| 271 |
-
top: 0;
|
| 272 |
-
z-index: 5;
|
| 273 |
-
}}
|
| 274 |
-
#datesTable {{
|
| 275 |
-
margin-bottom: 25px;
|
| 276 |
-
width: max-content;
|
| 277 |
-
border: 1px solid #ccc;
|
| 278 |
-
}}
|
| 279 |
-
|
| 280 |
-
.chart-grid {{
|
| 281 |
-
display: grid;
|
| 282 |
-
grid-template-columns: 1fr 1fr;
|
| 283 |
-
grid-template-rows: 200px 200px;
|
| 284 |
-
gap: 20px;
|
| 285 |
-
width: 100%;
|
| 286 |
-
}}
|
| 287 |
-
|
| 288 |
-
.chart-box {{
|
| 289 |
-
width: 100%;
|
| 290 |
-
height: 100%;
|
| 291 |
-
border: 1px solid #ccc;
|
| 292 |
-
}}
|
| 293 |
-
|
| 294 |
-
#chart365 {{
|
| 295 |
-
grid-column: 1 / 3;
|
| 296 |
-
}}
|
| 297 |
-
|
| 298 |
-
select {{
|
| 299 |
-
padding: 6px;
|
| 300 |
-
margin: 8px 0;
|
| 301 |
-
}}
|
| 302 |
-
</style>
|
| 303 |
-
|
| 304 |
-
</head>
|
| 305 |
-
<body>
|
| 306 |
-
|
| 307 |
-
<h2>NSE Indices Dashboard</h2>
|
| 308 |
-
|
| 309 |
-
<!-- DATES TABLE -->
|
| 310 |
-
<h3>Reference Dates</h3>
|
| 311 |
-
<table id="datesTable"></table>
|
| 312 |
-
|
| 313 |
-
<hr>
|
| 314 |
-
|
| 315 |
-
<!-- Dropdown for Key -->
|
| 316 |
-
<label><b>Select Index Category:</b></label>
|
| 317 |
-
<select id="keyDropdown"></select>
|
| 318 |
-
|
| 319 |
-
<div id="altTableSection" class="scroll-table">
|
| 320 |
-
<table id="altTable"></table>
|
| 321 |
-
</div>
|
| 322 |
-
|
| 323 |
-
<hr>
|
| 324 |
-
|
| 325 |
-
<!-- Dropdown for Charts -->
|
| 326 |
-
<label><b>Select Index for Charts:</b></label>
|
| 327 |
-
<select id="chartDropdown"></select>
|
| 328 |
-
|
| 329 |
-
<div class="chart-grid">
|
| 330 |
-
<iframe id="chartToday" class="chart-box"></iframe>
|
| 331 |
-
<iframe id="chart30" class="chart-box"></iframe>
|
| 332 |
-
<iframe id="chart365" class="chart-box"></iframe>
|
| 333 |
-
</div>
|
| 334 |
-
|
| 335 |
-
<script>
|
| 336 |
-
const records = {data_json};
|
| 337 |
-
const dates = {dates_json};
|
| 338 |
-
const DEFAULT_KEY = "{DEFAULT_KEY}";
|
| 339 |
-
const DEFAULT_SYMBOL = "{DEFAULT_SYMBOL}";
|
| 340 |
-
|
| 341 |
-
const keyDropdown = document.getElementById("keyDropdown");
|
| 342 |
-
const chartDropdown = document.getElementById("chartDropdown");
|
| 343 |
-
|
| 344 |
-
// ------------------- Build Dates Table -------------------
|
| 345 |
-
function buildDatesTable() {{
|
| 346 |
-
const table = document.getElementById("datesTable");
|
| 347 |
-
const row = dates[0];
|
| 348 |
-
let header = "<tr>";
|
| 349 |
-
Object.keys(row).forEach(k => header += `<th>${{k}}</th>`);
|
| 350 |
-
header += "</tr>";
|
| 351 |
-
let body = "<tr>";
|
| 352 |
-
Object.values(row).forEach(v => body += `<td>${{v}}</td>`);
|
| 353 |
-
body += "</tr>";
|
| 354 |
-
table.innerHTML = header + body;
|
| 355 |
-
}}
|
| 356 |
-
buildDatesTable();
|
| 357 |
-
|
| 358 |
-
// ------------------- Populate Key Dropdown -------------------
|
| 359 |
-
const keyList = [...new Set(records.map(r => r.key))];
|
| 360 |
-
keyList.forEach(k => {{
|
| 361 |
-
const opt = document.createElement("option");
|
| 362 |
-
opt.value = k;
|
| 363 |
-
opt.textContent = k;
|
| 364 |
-
if (k === DEFAULT_KEY) opt.selected = true;
|
| 365 |
-
keyDropdown.appendChild(opt);
|
| 366 |
-
}});
|
| 367 |
-
|
| 368 |
-
// ------------------- Populate Chart Dropdown -------------------
|
| 369 |
-
function populateChartDropdown(keyVal) {{
|
| 370 |
-
chartDropdown.innerHTML = "";
|
| 371 |
-
records.filter(r => r.key === keyVal).forEach(r => {{
|
| 372 |
-
const opt = document.createElement("option");
|
| 373 |
-
opt.value = r.indexSymbol;
|
| 374 |
-
opt.textContent = r.index;
|
| 375 |
-
if (r.index === DEFAULT_SYMBOL) opt.selected = true;
|
| 376 |
-
chartDropdown.appendChild(opt);
|
| 377 |
-
}});
|
| 378 |
-
}}
|
| 379 |
-
|
| 380 |
-
// ------------------- Build Filtered Table -------------------
|
| 381 |
-
function buildAltTable(keyName) {{
|
| 382 |
-
const table = document.getElementById("altTable");
|
| 383 |
-
const div = document.getElementById("altTableSection");
|
| 384 |
-
|
| 385 |
-
const filtered = records.filter(r => r.key === keyName);
|
| 386 |
-
if (!filtered.length) {{
|
| 387 |
-
table.innerHTML = "<tr><td>No Data</td></tr>";
|
| 388 |
-
div.style.display = "none";
|
| 389 |
-
return;
|
| 390 |
-
}}
|
| 391 |
-
|
| 392 |
-
const hiddenCols = [
|
| 393 |
-
"key", "chartTodayPath", "chart30dPath", "chart365dPath",
|
| 394 |
-
"date365dAgo","date30dAgo","previousDay","oneWeekAgo","oneMonthAgoVal",
|
| 395 |
-
"oneWeekAgoVal","oneYearAgoVal","index","indicativeClose"
|
| 396 |
-
];
|
| 397 |
-
|
| 398 |
-
const columns = Object.keys(filtered[0]).filter(c => !hiddenCols.includes(c));
|
| 399 |
-
|
| 400 |
-
let header = "<tr>";
|
| 401 |
-
columns.forEach(c => header += `<th>${{c}}</th>`);
|
| 402 |
-
header += "</tr>";
|
| 403 |
-
|
| 404 |
-
let rows = "";
|
| 405 |
-
filtered.forEach(obj => {{
|
| 406 |
-
rows += "<tr>";
|
| 407 |
-
columns.forEach(c => rows += `<td>${{obj[c]}}</td>`);
|
| 408 |
-
rows += "</tr>";
|
| 409 |
-
}});
|
| 410 |
-
|
| 411 |
-
table.innerHTML = header + rows;
|
| 412 |
-
div.style.display = "block";
|
| 413 |
-
}}
|
| 414 |
-
|
| 415 |
-
// ------------------- Load Charts -------------------
|
| 416 |
-
function loadCharts(symbol) {{
|
| 417 |
-
const row = records.find(r => r.indexSymbol === symbol);
|
| 418 |
-
if (!row) return;
|
| 419 |
-
document.getElementById("chartToday").src = row.chartTodayPath;
|
| 420 |
-
document.getElementById("chart30").src = row.chart30dPath;
|
| 421 |
-
document.getElementById("chart365").src = row.chart365dPath;
|
| 422 |
-
}}
|
| 423 |
-
|
| 424 |
-
// Event listeners
|
| 425 |
-
keyDropdown.addEventListener("change", () => {{
|
| 426 |
-
const keyVal = keyDropdown.value;
|
| 427 |
-
buildAltTable(keyVal);
|
| 428 |
-
populateChartDropdown(keyVal);
|
| 429 |
-
loadCharts(chartDropdown.value);
|
| 430 |
-
}});
|
| 431 |
-
|
| 432 |
-
chartDropdown.addEventListener("change", () => {{
|
| 433 |
-
loadCharts(chartDropdown.value);
|
| 434 |
-
}});
|
| 435 |
-
|
| 436 |
-
// ------------------- Initial Load -------------------
|
| 437 |
-
buildAltTable(DEFAULT_KEY);
|
| 438 |
-
populateChartDropdown(DEFAULT_KEY);
|
| 439 |
-
loadCharts(records.find(r => r.index === DEFAULT_SYMBOL).indexSymbol);
|
| 440 |
-
|
| 441 |
-
</script>
|
| 442 |
-
|
| 443 |
-
</body>
|
| 444 |
-
</html>
|
| 445 |
-
"""
|
| 446 |
-
return html
|
|
|
|
| 216 |
def nse_index_live(name="NIFTY 50"):
|
| 217 |
p=nsefetch(f"https://www.nseindia.com/api/equity-stockIndices?index={name.replace(' ','%20')}")
|
| 218 |
return {"data":df_from_data(p.pop("data")) if "data" in p else pd.DataFrame(), "rem":df_from_data([p])}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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