Bitcoin Forum
May 06, 2024, 01:54:25 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Grab the price of bitcoin?  (Read 1638 times)
joeyjoe (OP)
Full Member
***
Offline Offline

Activity: 224
Merit: 100


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).
1714960465
Hero Member
*
Offline Offline

Posts: 1714960465

View Profile Personal Message (Offline)

Ignore
1714960465
Reply with quote  #2

1714960465
Report to moderator
1714960465
Hero Member
*
Offline Offline

Posts: 1714960465

View Profile Personal Message (Offline)

Ignore
1714960465
Reply with quote  #2

1714960465
Report to moderator
1714960465
Hero Member
*
Offline Offline

Posts: 1714960465

View Profile Personal Message (Offline)

Ignore
1714960465
Reply with quote  #2

1714960465
Report to moderator
Even in the event that an attacker gains more than 50% of the network's computational power, only transactions sent by the attacker could be reversed or double-spent. The network would not be destroyed.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714960465
Hero Member
*
Offline Offline

Posts: 1714960465

View Profile Personal Message (Offline)

Ignore
1714960465
Reply with quote  #2

1714960465
Report to moderator
1714960465
Hero Member
*
Offline Offline

Posts: 1714960465

View Profile Personal Message (Offline)

Ignore
1714960465
Reply with quote  #2

1714960465
Report to moderator
error
Hero Member
*****
Offline Offline

Activity: 588
Merit: 500



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;
}

3KzNGwzRZ6SimWuFAgh4TnXzHpruHMZmV8
ne1
Member
**
Offline Offline

Activity: 84
Merit: 10


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
Merit: 500



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: 726
Merit: 500



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 (OP)
Full Member
***
Offline Offline

Activity: 224
Merit: 100


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:  

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