Bitcoin Forum
June 08, 2024, 08:29:58 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Alt Coins API  (Read 466 times)
randayh (OP)
Sr. Member
****
Offline Offline

Activity: 386
Merit: 250


View Profile WWW
November 20, 2013, 03:40:58 AM
 #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
<?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";
}

?>
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!