PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Dave Smith   PHP Stock Market API   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example Usage
Class: PHP Stock Market API
Get data about stocks using the MarketStack API
Author: By
Last change:
Date: 3 years ago
Size: 1,536 bytes
 

Contents

Class file image Download
<?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>';
}
?>