Looking to grab the latest stock market data? There’s a surprising lack of stock market APIs out there and even fewer that work consistently or affordable. Never fear, the PHP Stock Market API is here!
The PHP Stock Market API is a simple PHP class that uses the Yahoo! Finance API allowing you to retrieve up to 20 current data points for a particular symbol. It’s simple to implement and doesn’t require you to learn how to use the Yahoo! API.
Download Now (Version 1.3) Fork on GitHub
PHP Stock Market API Usage
With just a few lines of code, you can easily retrieve 20 current data points. Here’s how it works:
<?php require_once('class.stockMarketAPI.php'); ?> <h1>Current Stock Information for AAPL</h1> <?php $StockMarketAPI = new StockMarketAPI; $StockMarketAPI->symbol = 'AAPL'; ?> <pre><?php print_r($StockMarketAPI->getData());?></pre> <?php $start = '01-01-2013'; $end = '01-07-2013'; ?> <h1>Historical Stock Information for AAPL (<?php echo $start ?> - <?php echo $end ?>)</h1> <?php $StockMarketAPI = new StockMarketAPI; $StockMarketAPI->symbol = 'AAPL'; $StockMarketAPI->history = array( 'start' => $start, 'end' => $end, 'interval' => 'd' // Daily ); ?> <pre><?php print_r($StockMarketAPI->getData());?></pre> <hr> <h1>Stock Information for AAPL, MSFT, GOOGL</h1> <?php $StockMarketAPI = new StockMarketAPI; $StockMarketAPI->symbol = array('AAPL', 'MSFT', 'GOOGL'); ?> <pre><?php print_r($StockMarketAPI->getData());?></pre>