PHP Classes

File: examples/server-endpoint.php

Recommend this page to a friend!
  Packages of Besim Huskic   InvestorySpot Stock Ticker   examples/server-endpoint.php   Download  
File: examples/server-endpoint.php
Role: Example script
Content type: text/plain
Description: php file
Class: InvestorySpot Stock Ticker
Fetch stock quotes and display them in a ticker
Author: By
Last change:
Date: 4 months ago
Size: 670 bytes
 

Contents

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