mirror of
https://github.com/seigler/cryptohistory.org
synced 2025-07-27 01:36:11 +00:00
added currency support checking
This commit is contained in:
parent
6bf60b716e
commit
27cd5fa4e8
3 changed files with 52 additions and 16 deletions
17
index.php
17
index.php
|
@ -1,10 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
ini_set('display_errors', 1);
|
//ini_set('display_errors', 1);
|
||||||
error_reporting(E_ALL);
|
//error_reporting(E_ALL);
|
||||||
|
|
||||||
require_once 'vendor/autoload.php';
|
require_once 'vendor/autoload.php';
|
||||||
require_once 'vendor/seigler/neat-charts/src/NeatCharts/NeatChart.php';
|
|
||||||
require_once 'vendor/seigler/neat-charts/src/NeatCharts/LineChart.php';
|
|
||||||
|
|
||||||
use phpFastCache\CacheManager;
|
use phpFastCache\CacheManager;
|
||||||
|
|
||||||
|
@ -20,19 +18,18 @@ $router->map('GET', '/', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// map cryptocurrency stuff
|
// map cryptocurrency stuff
|
||||||
$router->map( 'GET', '/charts/[dark|light:theme]/[a:curA]-[a:curB]/[7d|24h:duration]/[svg|png:format]', function($theme, $curA, $curB, $duration, $format) {
|
$router->map( 'GET', '/charts/[dark|light:theme]/[a:curA]-[btc:curB]/[a:duration]/[svg|png:format]', function($theme, $curA, $curB, $duration, $format) {
|
||||||
require __DIR__ . '/views/chart.php';
|
require __DIR__ . '/views/chart.php';
|
||||||
renderChart(
|
return renderChart(
|
||||||
$theme,
|
$theme,
|
||||||
strtoupper($curB.'_'.$curA),
|
$curA,
|
||||||
60 * 60 * 24 * ($duration == '7d' ? 7 : 1),
|
$curB,
|
||||||
($duration == '7d' ? 1800 : 300),
|
$duration,
|
||||||
$format,
|
$format,
|
||||||
800,
|
800,
|
||||||
200,
|
200,
|
||||||
12
|
12
|
||||||
);
|
);
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// match current request url
|
// match current request url
|
||||||
|
|
|
@ -22,15 +22,53 @@ function getJson($url) {
|
||||||
|
|
||||||
function renderChart(
|
function renderChart(
|
||||||
$theme,
|
$theme,
|
||||||
$pair,
|
$currencyA,
|
||||||
$dataDuration = (7 * 24 * 60 * 60),
|
$currencyB,
|
||||||
$dataResolution = 1800,
|
$duration,
|
||||||
$format = 'svg',
|
$format = 'svg',
|
||||||
$width = 800,
|
$width = 800,
|
||||||
$height = 200,
|
$height = 200,
|
||||||
$fontSize = 12
|
$fontSize = 12
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
$durations = [
|
||||||
|
// '30d'=> [
|
||||||
|
// 'duration' => 60 * 60 * 24 * 30,
|
||||||
|
// 'resolution' => 7200 // 2h
|
||||||
|
// ],
|
||||||
|
'7d'=> [
|
||||||
|
'duration' => 60 * 60 * 24 * 7,
|
||||||
|
'resolution' => 1800 // 30m
|
||||||
|
],
|
||||||
|
'24h' => [
|
||||||
|
'duration' => 60 * 60 * 24 * 1,
|
||||||
|
'resolution' => 900 // 15m
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
if (array_key_exists($duration, $durations)) {
|
||||||
|
$dataDuration = $durations[$duration]['duration'];
|
||||||
|
$dataResolution = $durations[$duration]['resolution'];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$supportedCurrencies = CacheManager::get('poloniex-supported-currencies');
|
||||||
|
if (is_null($supportedCurrencies)) {
|
||||||
|
$supportedCurrenciesJson = getJson('https://poloniex.com/public?command=returnCurrencies');
|
||||||
|
foreach ($supportedCurrenciesJson as $key => $value) {
|
||||||
|
if ($value->delisted == 0) {
|
||||||
|
$supportedCurrencies[] = strtolower($key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CacheManager::set('poloniex-supported-currencies', $supportedCurrencies, 60 * 60 * 24 * 7); // asking once a week doesn't seem like too much
|
||||||
|
}
|
||||||
|
if ($currencyB != 'btc' || !in_array($currencyA, $supportedCurrencies)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pair = strtoupper($currencyB . '_' . $currencyA); // poloniex you strange
|
||||||
|
|
||||||
$chartCacheKey = 'poloniex-'.$theme.'-'.$pair.'-'.$dataDuration.'-'.$format;
|
$chartCacheKey = 'poloniex-'.$theme.'-'.$pair.'-'.$dataDuration.'-'.$format;
|
||||||
|
|
||||||
$result = CacheManager::get($chartCacheKey);
|
$result = CacheManager::get($chartCacheKey);
|
||||||
|
@ -88,4 +126,5 @@ function renderChart(
|
||||||
header('Content-Disposition: inline; filename="Dash-chart-' . gmdate('Y-m-d\THis+0', $startTime) . '--' . gmdate('Y-m-d\THis+0') . '.png"');
|
header('Content-Disposition: inline; filename="Dash-chart-' . gmdate('Y-m-d\THis+0', $startTime) . '--' . gmdate('Y-m-d\THis+0') . '.png"');
|
||||||
}
|
}
|
||||||
echo $result;
|
echo $result;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,16 +54,16 @@
|
||||||
<section>
|
<section>
|
||||||
<h2>Poloniex Dash/BTC Price</h2>
|
<h2>Poloniex Dash/BTC Price</h2>
|
||||||
<figure>
|
<figure>
|
||||||
<img src="/charts/dark/dash/7d/svg" alt="Poloniex Dash/BTC price">
|
<img src="/charts/dark/dash-btc/7d/svg" alt="Poloniex Dash/BTC price">
|
||||||
<figcaption>7 Day Dash price in BTC <code>http://cryptohistory.org/charts/dark/dash-btc/7d/svg</code></figcaption>
|
<figcaption>7 Day Dash price in BTC <code>http://cryptohistory.org/charts/dark/dash-btc/7d/svg</code></figcaption>
|
||||||
</figure>
|
</figure>
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<h2>Build your own chart:</h2>
|
<h2>Build your own chart:</h2>
|
||||||
<p>The URL is flexible:<br>
|
<p>The URL is flexible:<br>
|
||||||
<code>http://cryptohistory.org/charts/{theme}/{currency}/{timespan}/{format}</code>.</p>
|
<code>http://cryptohistory.org/charts/{theme}/{currency}-btc/{timespan}/{format}</code>.</p>
|
||||||
<p>Theme: <code>dark</code> or <code>light</code>. (More planned)</p>
|
<p>Theme: <code>dark</code> or <code>light</code>. (More planned)</p>
|
||||||
<p>Currency: anything active on Poloniex.</p>
|
<p>Currency: anything active on Poloniex. Prices are all in bitcoin.</p>
|
||||||
<p>Timespan: <code>30d</code>, <code>7d</code>, or <code>24h</code>. (More planned)</p>
|
<p>Timespan: <code>30d</code>, <code>7d</code>, or <code>24h</code>. (More planned)</p>
|
||||||
<p>Format: <code>svg</code> (best) or <code>png</code>.</p>
|
<p>Format: <code>svg</code> (best) or <code>png</code>.</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue