PHP Classes

File: examples/basic.php

Recommend this page to a friend!
  Packages of Besim Huskic   InvestorySpot Stock Ticker   examples/basic.php   Download  
File: examples/basic.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: 808 bytes
 

Contents

Class file image Download
<?php
// Require Composer autoloader (run `composer install` first)
require_once __DIR__ . '/../vendor/autoload.php';

use InvestorySpot\StockTicker\StockTicker;

// Optional API keys for fallback providers
define('ALPHAVANTAGE_API_KEY', 'demo');
define('FINNHUB_API_KEY', '');

$ticker = new StockTicker(__DIR__ . '/cache');
$ticker->set_refresh(300);
$ticker->set_colors('#00a32a', '#d63638');

$quotes = $ticker->get_quotes('AAPL,GOOGL,MSFT,AMZN,NVDA');

if (empty($quotes)) {
    echo "No data returned.\n";
    exit;
}

echo "=== Provider status ===\n";
print_r($ticker->get_provider_status());

echo "\n=== Raw quotes ===\n";
print_r($quotes);

echo "\n=== Table output ===\n";
echo $ticker->render_table($quotes) . "\n";

echo "\n=== Ticker output ===\n";
echo $ticker->render_ticker($quotes) . "\n";