Bitcoin Forum
January 19, 2017, 07:40:26 PM *
News: Latest stable version of Bitcoin Core: 0.13.2  [Torrent]. (New!)
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Grab the price of bitcoin?  (Read 1458 times)
joeyjoe
Full Member
***
Offline Offline

Activity: 224


View Profile
September 22, 2011, 03:41:54 PM
 #1

Wheres a good place to return the current price of bitcoins. Im preferbly after a PHP script that just returns the price, or some TCP connection or somthing?

the reason is so i can use it to display the price on my arudino

Bitcoin PHP programmer for hire! (HTML / CSS / JQuery / AJAX / .NET).
1484854826
Hero Member
*
Offline Offline

Posts: 1484854826

View Profile Personal Message (Offline)

Ignore
1484854826
Reply with quote  #2

1484854826
Report to moderator
1484854826
Hero Member
*
Offline Offline

Posts: 1484854826

View Profile Personal Message (Offline)

Ignore
1484854826
Reply with quote  #2

1484854826
Report to moderator
1484854826
Hero Member
*
Offline Offline

Posts: 1484854826

View Profile Personal Message (Offline)

Ignore
1484854826
Reply with quote  #2

1484854826
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
error
Hero Member
*****
Offline Offline

Activity: 574



View Profile
September 22, 2011, 11:44:25 PM
 #2

You'll need to do your own error checking; this isn't particularly robust.

Code:
function mtgox()
{
        $mtgox = file_get_contents("https://www.mtgox.com/code/data/ticker.php");
        if (!$mtgox) return 0;
        $mtgox = json_decode($mtgox);
        return $mtgox->ticker->last;
}

15UFyv6kfWgq83Pp3yhXPr8rknv9m6581W
ne1
Member
**
Offline Offline

Activity: 85


View Profile WWW
September 23, 2011, 12:29:31 AM
 #3

That sound cool, is love to have an arguing mtgox ticker.  I've got an arduino, Ethernet shield and an lcd.  Love to see where you get with this.

pent
Hero Member
*****
Offline Offline

Activity: 490



View Profile
September 23, 2011, 01:14:34 PM
 #4

You'll need to do your own error checking; this isn't particularly robust.

Code:
function mtgox()
{
        $mtgox = file_get_contents("https://www.mtgox.com/code/data/ticker.php");
        if (!$mtgox) return 0;
        $mtgox = json_decode($mtgox);
        return $mtgox->ticker->last;
}
not ideal. I'll advice to use volume-based rate. In this script it calculates average volume-based rate for last 3 hours.
Code:
<?
$ch=curl_init('https://mtgox.com/code/data/getTrades.php');
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($ch,CURLOPT_TIMEOUT,15);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
$headers = array(
//      "Host: mtdox.com",
        "User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.112 Safari/534.30",
        "Accept: */*",
        "Accept-Language: en-US;q=0.8,en;q=0.4",
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$ret=curl_exec($ch);
if (curl_errno($ch)!=0) {
    echo curl_error($ch);
    curl_close($ch);
    exit;
}
curl_close($ch);

$o=json_decode($ret,true);
if (!is_array($o)) exit("Invalid data");

$o1=array_reverse($o);
$start=$o1[0]['date'];
$end=$start-3*60*60;
$total_btc=0;
$total_usd=0;
$cnt=0;
for (reset($o1);list(,$v)=each($o1);) {
    if ($v['date']<$end) break;
    $total_usd=$total_usd + $v['price']*$v['amount'];
    $total_btc+=$v['amount'];
    $cnt++;
}

if ($total_usd <=0 || $total_btc<=0) exit("Zero volume");

$rate=$total_usd / $total_btc;

echo "Rate is $rate USD/BTC\n";

Also, mtgox has some 'vwap' key in ticker array. I don't know what exact meaning it has, but it is near to the value my script provides. Maybe for different time period.
Cryptoman
Hero Member
*****
Offline Offline

Activity: 728



View Profile
September 23, 2011, 01:18:10 PM
 #5

OP, how are you able to run a PHP script on an Arduino?

"A small body of determined spirits fired by an unquenchable faith in their mission can alter the course of history." --Gandhi
joeyjoe
Full Member
***
Offline Offline

Activity: 224


View Profile
September 27, 2011, 11:56:40 AM
 #6

OP, how are you able to run a PHP script on an Arduino?

Run a PHP script on a webserver, and grab the webserver text to the arduino then display on LCD.

I have managed to connect the arduino directly to the ticker, but have to work out a way to parse the output more easily,

Bitcoin PHP programmer for hire! (HTML / CSS / JQuery / AJAX / .NET).
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!