Author

Topic: Alt Coins API (Read 485 times)

sr. member
Activity: 386
Merit: 250
November 19, 2013, 10:40:58 PM
#1
I am currently writing a php script to updated the current price of USD/BTC in my www.bitcoins4barter.com shopping cart database. However, I want to start adding more altcoins to the payment method. I'm starting to go a little crazy trying to get the feed to work on other altcoins

1LTC bounty to anyone that can rewrite this following code to include LTC and ZET for the update.

#! /usr/bin/php
$url = "https://bitpay.com/api/rates";
$json = file_get_contents($url);
$data = json_decode($json, TRUE);
$rate = $data[0]["rate"];
$usd_price = 1;    
$bitcoin_price = round( $usd_price / $rate , 8 );
$host="localhost"; // Host name
$username="mydatabase"; // Mysql username
$password="mypasswrd"; // Mysql password
$db_name="database"; // Database name
$tbl_name="currencies"; // Table name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="UPDATE $tbl_name SET value='$bitcoin_price' WHERE title='Bitcoin (BTC)'";
$result=mysql_query($sql);

if($result){
echo "Successful";
}

else {
echo "ERROR";
}

?>
Jump to: