PHP code example of nishantwebdev / nse-stock-data-php
1. Go to this page and download the library: Download nishantwebdev/nse-stock-data-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nishantwebdev / nse-stock-data-php example snippets
use NseData\StockClient;
use NseData\DateRange;
// Initialize the NSE client
$nse = new StockClient();
try {
// Get equity details for a stock
$equityDetails = $nse->getEquityDetails('TCS');
echo "Company: " . $equityDetails->info->companyName . "\n";
echo "Last Price: ₹" . $equityDetails->priceInfo->lastPrice . "\n";
echo "Change: " . $equityDetails->priceInfo->change . " (" . $equityDetails->priceInfo->pChange . "%)\n";
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
$testDate = new DateTime('2024-01-26'); // Republic Day
$isHoliday = $nse->checkHoliday($testDate);
echo "Is " . $testDate->format('Y-m-d') . " a holiday? " . ($isHoliday ? 'Yes' : 'No');