Hey Stackoverflow,
I've set myself a little project to celebrate the rise of cryptocurrency (having just been stitched up by a conventional bank myself with some incredibly 'un-Christmassy' charges, the growing use of a decentralized currency was a most welcomed revelation).
Basically, I want to be able to display data on my website from the following API:
http://www.cryptocoincharts.info/v2/api/listCoins
As (at least I believe) this will then enable me to use javascript to carry out my own exchange calculations using the data found there as a base rate, which I can then turn into a form to create as an easy to use exchange calculator.
This is what I have so far...
The example PHP from cryptocoincharts:
// fetch data
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.cryptocoincharts.info/v2/api/listCoins");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$rawData = curl_exec($curl);
curl_close($curl);
// decode to array
$data = json_decode($rawData);
// show data
echo "<pre>";
foreach ($data as $row) echo $row->id." - ".$row->name."\n";
echo "</pre>";
Javascript for the exchange calculations:
<script language="JavaScript">
<!--
function goldConverter(){
document.converter.bitcoin.value = document.converter.gold.value * 0.05019370
document.converter.litecoin.value = document.converter.gold.value * 1.56379100
document.converter.peercoin.value = document.converter.gold.value * 7.52631578
}
function bitcoinConverter(){
document.converter.gold.value = document.converter.bitcoin.value * 19.92281899
document.converter.litecoin.value = document.converter.bitcoin.value * 0.03210000
document.converter.peercoin.value = document.converter.bitcoin.value * 0.00667000
}
</script>
To further clarify my intention is to enable (more or less) real-time automated update of the exchange values using the data from cyrptocoincharts, figures listed above are there for the purpose of testing.
And here is my HTML:
<form name="converter">
<table border="0">
<tr>
<td>Gold (g): </td><td><input type="text" name="gold" onChange="goldConverter()" /></td>
</tr>
<tr>
<td>Bitcoin: </td><td><input type="text" name="bitcoin" onChange="bitcoinConverter()" /></td>
</tr>
<tr>
<td>Litecoin:</td><td><input type="text" name="litecoin" onChange="litecoinConverter()" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="button" value="Convert" /></td>
</tr>
</table>
</form>
Summary:
If anyone could either point me in the right direction (particularly regarding the API), or help me get this to work as a whole, I would really appreciate it and give credit where due, I realize I have a lot of learning to do and this is my first post on stackoverflow, so apologies if I have broken any unwritten rules.
UPDATE:
I have recently discovered money.js which potentially solves my problem, and I am currently attempting to change the data source from OpenExchange Rates API to Cryptocoin Charts API.
UPDATE 2.0:
Now using simple_html_dom.php to scrape the HTML page as seems most straight forward method, however I am receiving the following errors:
Warning: include_once(simple_html_dom.php) [function.include-once]: failed to open stream: No such file or directory in /srv/disk13/1587290/www/bildungsroman.me.pn/index.php on line 22
Warning: include_once() [function.include]: Failed opening 'simple_html_dom.php' for inclusion (include_path='.:/usr/local/php-5.3.22/share/pear') in /srv/disk13/1587290/www/bildungsroman.me.pn/index.php on line 22
Fatal error: Call to undefined function file_get_html() in /srv/disk13/1587290/www/bildungsroman.me.pn/index.php on line 25
My new code is as follows:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!-- page content -->
<?php
include_once('simple_html_dom.php');
$html = file_get_html('http://www.cryptocoincharts.info/v2/api/listCoins');
$result = $html -> find('name');
foreach($result as $element) {
echo $element."<br/>";
}
?>
</body>
</html>
The above PHP script should be in the simple_html_dom.php directory, or use an absolute path instead of the relative path you've used.