<h1>Current Stock Information for AAPL</h1> <?php require_once 'class.stockMarketAPI.php'; $StockMarketAPI = new StockMarketAPI(); $StockMarketAPI->symbol = 'AAPL'; $StockMarketAPI->stat = 'all'; print_r($StockMarketAPI->getData()); ?> <hr> <?php $start = '2013-1-1'; $end = '2013-12-31'; ?> <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'); print_r($StockMarketAPI->getData());
<?php require_once 'php-stock-market-api/class.stockMarketAPI.php'; $stock_symbols = array("AAPL", "XOM", "MSFT", "GOOGL", "JNJ", "WFC", "WMT", "GE", "PG", "JPM", "CVX", "VZ", "FB", "KO", "PFE", "T", "ORCL", "BAC"); $all_stock_data = array(); $StockMarketAPI = new StockMarketAPI(); $StockMarketAPI->symbol = $stock_symbols; $stock_data = $StockMarketAPI->getData(); $all_stock_data_json = json_encode(array_values($stock_data)); header("Cache-Control: no-cache, must-revalidate"); header("Expires: Fri, 01 Jul 2013 00:00:00 GMT"); // Date in the past header("Content-type: application/JSON; charset=utf-8"); $anydata = empty($all_stock_data_json) ? 'false' : 'true'; ?> {"status": <?php echo $anydata; ?> , "all_stock_data": <?php echo $all_stock_data_json; ?> }
<?php require_once 'php-stock-market-api/class.stockMarketAPI.php'; date_default_timezone_set('America/Los_Angeles'); $stock_symbol = $_GET['stock_symbol']; $start = date("m-d-Y", strtotime('-4 week')); $end = date("m-d-Y"); $StockMarketAPI = new StockMarketAPI(); $StockMarketAPI->symbol = $stock_symbol; $StockMarketAPI->history = array('start' => $start, 'end' => $end, 'interval' => 'd'); $hisorical_data = $StockMarketAPI->getData()[$stock_symbol]; array_shift($hisorical_data); //first element is header names, shift them off the array $historical_stock_data = json_encode($hisorical_data); header("Cache-Control: no-cache, must-revalidate"); header("Expires: Fri, 01 Jul 2013 00:00:00 GMT"); // Date in the past header("Content-type: application/JSON; charset=utf-8"); $anydata = empty($historical_stock_data) ? 'false' : 'true'; ?> {"status": <?php echo $anydata; ?> , "historical_stock_data": <?php echo $historical_stock_data; ?> }
<th>Symbol</th> <th>Shares</th> <th>Name</th> <th>Price</th> <th>Change</th> <th>High</th> <th>Low</th> <th>Avg</th> <th>Action</th> </tr> <?php $sql = "SELECT stock_symbol, SUM(shares) FROM transaction WHERE user_id = '{$user_id}' GROUP BY stock_symbol HAVING SUM(shares) < 0;;"; $result = mysqli_query($db, $sql); while ($row = mysqli_fetch_array($result)) { require_once 'includes/class.stockMarketAPI.php'; $StockMarketAPI = new StockMarketAPI(); $StockMarketAPI->symbol = $row['stock_symbol']; $shares = -1 * $row['SUM(shares)']; $info = $StockMarketAPI->getData(); echo "<tr>"; echo "<td name='sell_stock_symbol'>", $StockMarketAPI->symbol, "</td>"; echo "<td name='sell_shares'>", $shares, "</td>"; foreach ($info as $i) { echo "<td>", $i[name], "</td>"; echo "<td name='unit_price'>", $i[price], "</td>"; echo "<td>", $i[change], "</td>"; echo "<td>", $i[fiftytwo_week_high], "</td>"; echo "<td>", $i[fiftytwo_week_low], "</td>"; echo "<td>", $i[fiftyday_moving_avg], "</td>"; echo "<td>"; echo "<input class='input-xs' type='number' name='ammount' min=1 size='1'>";
<thead> <tr> <td>Date</td> <td>Open</td> <td>High</td> <td>Low</td> <td>Close</td> <td>Volume</td> <td>Sdj_close</td> </tr> </thead> <?php $start = "01-01-2015"; $end = ""; require_once 'includes/class.stockMarketAPI.php'; $StockAPI = new StockMarketAPI(); $StockAPI->symbol = $_GET["symbol"]; $StockAPI->history = array('start' => $start, 'end' => $end, 'interval' => 'd'); $his_info = $StockAPI->getData(); foreach ($his_info as $row) { for ($x = 1; $x < sizeof($row); $x++) { echo "<tr>"; echo "<td>", $row[$x][date], "</td>"; echo "<td>", $row[$x][open], "</td>"; echo "<td>", $row[$x][high], "</td>"; echo "<td>", $row[$x][low], "</td>"; echo "<td>", $row[$x][close], "</td>"; echo "<td>", $row[$x][volume], "</td>"; echo "<td>", $row[$x][adj_close], "</td>"; echo "</tr>"; }