PHP Classes

PHP Stock Market API: Get data about stocks using the MarketStack API

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 137 All time: 9,252 This week: 55Up
Version License PHP version Categories
marketstack 1.0.0GNU General Publi...5PHP 5, Web services, Finances
Description 

Author

This class can get data about stocks using the MarketStack API.

It can send HTTP requests to the MarketStack API Web server to get several details of stocks listed in stock exchanges. Currently it can:

- Get the values of one or more stocks
- Get realtime values one or more stocks during the day
- Look up information about one or multiple stock ticker symbols
- Look up information about many stock exchanges
- Look up information about all supported currencies
- Look up information about all supported timezones.

Picture of Dave Smith
  Performance   Level  
Name: Dave Smith is available for providing paid consulting. Contact Dave Smith .
Classes: 51 packages by
Country: United States United States
Age: 59
All time rank: 608 in United States United States
Week rank: 50 Up7 in United States United States Up
Innovation award
Innovation award
Nominee: 32x

Winner: 7x

Example

<?php
/*
example usage
marketStack ver 1.0

You must get an API key from https://marketstack.com/product
and enter it in the marketstack.class.php file

For complete documentation on each endpoint and available paramaters
see https://marketstack.com/documentation
*/

//turning off low level notices
error_reporting(E_ALL ^ E_NOTICE);

//instantiate the class
require('marketstack.class.php');
$market = new marketStack();

//get ticker information for Microsoft symbol MSFT
$market->setEndPoint('tickers','MSFT');
$market->getResponse();

echo
'<strong>'.$market->response->name.'</strong>'.' ('.$market->response->symbol.')'.'<br>';
echo
$market->response->stock_exchange->acronym.'<br>';

//get latest market activity for Microsoft
$market->setEndPoint('eod','latest');
$market->setParam('symbols','MSFT');
$market->getResponse();

$data = $market->response->data[0];

echo
'<hr>';
echo
'<strong>Date: </strong>'.$data->date.'<br>';
echo
'<strong>Open: </strong>$'.$data->open.'<br>';
echo
'<strong>High: </strong>$'.$data->high.'<br>';
echo
'<strong>Low: </strong>$'.$data->low.'<br>';
echo
'<strong>Close: $'.$data->close.'</strong><br>';

//list of supported exchanges
$market->setEndPoint('exchanges');
$market->getResponse();

echo
'<hr>';
echo
'<h4>Marketstack supports the following exchanges:</h4>';

foreach(
$market->response->data as $data ){
    echo
'<strong>'.$data->mic.'</strong> '.$data->name.' ('.$data->acronym.') '.$data->city.' - '.$data->country.'</br>';
}
?>


  Files folder image Files (3)  
File Role Description
Accessible without login Plain text file example.php Example Example Usage
Accessible without login Plain text file license.txt Lic. License
Plain text file marketstack.class.php Class Main Class

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:137
This week:0
All time:9,252
This week:55Up