File manager - Edit - /home/cipherteam/htdocs/cipherteam.in/API/ew/TopLosers.php
Back
<?php // DataGetter/TopLosers.php header('Access-Control-Allow-Origin: https://sharemarketipo.in'); header('Access-Control-Allow-Methods: GET'); header('Access-Control-Allow-Headers: Content-Type'); if (isset($_GET['exc'])) $exc = $_GET['exc']; else $exc = 'NSE'; if (isset($_GET['icode'])) $icode = $_GET['icode']; else $icode = -44; if (isset($_GET['prd'])) $prd = $_GET['prd']; else $prd = '1D'; // Backward-compat: new endpoint uses negative index codes (-44 = Nifty 500, -29 = Nifty 50). // If the parent passes an old positive icode (e.g. 22115), coerce to default. if (is_numeric($icode) && intval($icode) > 0) $icode = -44; // Backward-compat: map old numeric period codes to new format (1 -> 1D, 7 -> 1W, etc.) $periodMap = ['1' => '1D', '7' => '1W', '30' => '1M', '90' => '3M', '180' => '6M', '365' => '1Y']; $period = $periodMap[strval($prd)] ?? $prd; $apiUrl = 'https://nw.nuvamawealth.com/edelmw-content/content/new-equity/top-gainers-losers?type=loss&exc=' . urlencode($exc) . '&period=' . urlencode($period) . '&index=' . urlencode($icode); /* -------------------- Robust fetch: real timeouts + one retry -------------------- */ $response = false; $httpCode = null; for ($attempt = 1; $attempt <= 2; $attempt++) { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $apiUrl, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 8, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'accept: */*', 'accept-language: en-US,en;q=0.9,gu;q=0.8,zh-TW;q=0.7,zh;q=0.6', 'appidkey: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHAiOjEsImZmIjoiVyIsImJkIjoid2ViLXBjIiwibmJmIjoxNTc5MjQxODMyLCJzcmMiOiJlbXRtdyIsImF2IjoiMS4wLjAuNCIsImFwcGlkIjoiNGZlNjhiNzUzNjc4NGUzNDA3YzNlY2YxOWJlN2M0YWQiLCJpc3MiOiJlbXQiLCJleHAiOjE2MTA3NzgxMzIsImlhdCI6MTU3OTI0MjEzMn0.IR-PKf1Jjr69bsERFmMeuZrZ2RafBDiTGgKA6Ygofdo', 'content-type: application/json', 'origin: https://www.nuvamawealth.com', 'priority: u=1, i', 'referer: https://www.nuvamawealth.com/', 'sec-ch-ua: "Chromium";v="148", "Google Chrome";v="148", "Not/A)Brand";v="99"', 'sec-ch-ua-mobile: ?0', 'sec-ch-ua-platform: "Windows"', 'sec-fetch-dest: empty', 'sec-fetch-mode: cors', 'sec-fetch-site: same-site', 'source: EDEL', 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36', ), )); $response = curl_exec($curl); $errno = curl_errno($curl); $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if ($errno === 0 && $httpCode === 200 && !empty($response)) break; if ($errno === 0 && $httpCode !== 0 && $httpCode < 500) break; } $data = ($httpCode === 200 && !empty($response)) ? json_decode($response, true) : null; $rows = is_array($data) ? ($data['data']['topGnrsLsrs'] ?? []) : []; if (empty($rows)): ?> <div class="empty"> <div class="empty__icon">i</div> <div class="empty__text">No Data Found</div> <div class="empty__sub">Please try a different filter.</div> </div> <?php else: foreach ($rows as $i => $row): $name = htmlspecialchars($row['cname'] ?? '', ENT_QUOTES); $ltp = htmlspecialchars($row['ltp'] ?? '', ENT_QUOTES); $chng = floatval($row['chg'] ?? 0); $chngPer = floatval($row['chgP'] ?? 0); $rank = $i + 1; $delay = number_format(min($i, 20) * 0.03, 2); if ($chng > 0) { $dir = 'up'; $pctLabel = '+' . number_format($chngPer, 2) . '%'; $absLabel = '+' . number_format($chng, 2); } elseif ($chng < 0) { $dir = 'down'; $pctLabel = number_format($chngPer, 2) . '%'; $absLabel = number_format($chng, 2); } else { $dir = 'flat'; $pctLabel = '0.00%'; $absLabel = '0.00'; } ?> <div class="sr" style="animation-delay:<?php echo $delay; ?>s"> <div class="sr__rank"><?php echo $rank; ?></div> <div class="sr__name"><?php echo $name; ?></div> <div class="sr__ltp"><?php echo $ltp; ?></div> <div class="sr__change"> <span class="sr__pct sr__pct--<?php echo $dir; ?>"> <?php if ($dir === 'up'): ?> <svg class="sr__arrow" viewBox="0 0 10 10"><polyline points="2,7 5,3 8,7" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg> <?php elseif ($dir === 'down'): ?> <svg class="sr__arrow" viewBox="0 0 10 10"><polyline points="2,3 5,7 8,3" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg> <?php else: ?> <svg class="sr__arrow" viewBox="0 0 10 10"><line x1="2" y1="5" x2="8" y2="5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg> <?php endif; ?> <?php echo $pctLabel; ?> </span> <span class="sr__abs sr__abs--<?php echo $dir; ?>"><?php echo $absLabel; ?></span> </div> </div> <?php endforeach; endif; ?> <style> .sr { display: flex; align-items: center; padding: 10px 14px 10px 12px; border-bottom: 1px solid var(--accent-hair); gap: 10px; animation: rowIn .3s ease backwards; transition: background .15s ease; } .sr:last-child { border-bottom: none; } .sr:hover { background: var(--accent-softer); } @keyframes rowIn { from { opacity: 0; transform: translateX(-5px); } to { opacity: 1; transform: translateX(0); } } .sr__rank { width: 20px; flex-shrink: 0; font-family: 'JetBrains Mono', monospace; font-size: 10px; font-weight: 600; color: var(--accent-light); text-align: center; line-height: 1; } .sr__name { flex: 1; min-width: 0; font-family: 'DM Sans', sans-serif; font-size: 13px; font-weight: 500; color: var(--accent-deep); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .sr__ltp { flex-shrink: 0; width: 64px; text-align: right; font-family: 'JetBrains Mono', monospace; font-size: 12px; font-weight: 600; color: var(--ink); letter-spacing: -0.01em; } .sr__change { flex-shrink: 0; width: 84px; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; } .sr__pct { display: inline-flex; align-items: center; gap: 3px; font-family: 'JetBrains Mono', monospace; font-size: 11px; font-weight: 700; padding: 3px 8px 3px 5px; border-radius: 999px; white-space: nowrap; letter-spacing: -0.02em; line-height: 1; } .sr__pct--up { color: var(--buy); background: var(--buy-bg); } .sr__pct--down { color: var(--sell); background: var(--sell-bg); } .sr__pct--flat { color: var(--ink-3); background: var(--accent-soft); } .sr__arrow { width: 10px; height: 10px; flex-shrink: 0; } .sr__abs { font-family: 'JetBrains Mono', monospace; font-size: 9.5px; font-weight: 500; letter-spacing: -0.01em; opacity: 0.55; white-space: nowrap; padding-right: 2px; } .sr__abs--up { color: var(--buy); } .sr__abs--down { color: var(--sell); } .sr__abs--flat { color: var(--ink-3); } .empty { padding: 30px 20px; text-align: center; } .empty__icon { width: 48px; height: 48px; margin: 0 auto 12px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-family: 'Fraunces', serif; font-size: 24px; font-style: italic; } .empty__text { font-family: 'Fraunces', serif; font-size: 16px; color: var(--accent-deep); font-weight: 500; } .empty__sub { margin-top: 4px; font-size: 12px; color: var(--accent-dark); opacity: 0.75; } </style>
| ver. 1.4 |
Github
|
.
| PHP 8.2.9 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings