<?php
/**
* AJAX endpoint for JS auto-refresh.
*
* Called by the setInterval script in the README.
* Returns rendered ticker/table HTML.
*/
require_once __DIR__ . '/../vendor/autoload.php';
use InvestorySpot\StockTicker\StockTicker;
$ticker = new StockTicker(__DIR__ . '/cache');
$ticker->set_refresh(300);
$ticker->set_colors('#00a32a', '#d63638');
$symbols = isset($_POST['symbols']) ? $_POST['symbols'] : 'AAPL,GOOGL,MSFT';
$display = isset($_POST['display']) ? $_POST['display'] : 'ticker';
$quotes = $ticker->get_quotes($symbols);
if ($display === 'table') {
echo $ticker->render_table($quotes);
} else {
echo $ticker->render_ticker($quotes);
}
|