Jeremy West spendbitcoins.com (OP)
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
August 08, 2011, 09:55:30 PM |
|
The following code gives my site it's current exchange rate. 2 BTC bounty for the first person who rewrites it to echo the lower of the last price on Mt Gox and the 24-hour weighted average on Mt Gox. Thanks!
|
|
|
|
jackjack
Legendary
Offline
Activity: 1176
Merit: 1257
May Bitcoin be touched by his Noodly Appendage
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
August 08, 2011, 10:05:57 PM Last edit: August 08, 2011, 10:20:26 PM by jackjack |
|
$a=ouvrirpage("https://mtgox.com/code/data/ticker.php"); $res=(json_decode($a, true)); $low = $res['ticker']['low'];
$a=ouvrirpage("http://bitcoincharts.com/t/weighted_prices.json"); $res=(json_decode($a, true)); $day = $res['USD']['24h'];
echo min($low, $day);
function ouvrirpage($site){ $ch = curl_init($site); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($ch); curl_close($ch); return $res; } or if you don't like curl: $a=file_get_contents("https://mtgox.com/code/data/ticker.php"); $res=(json_decode($a, true)); $low = $res['ticker']['low'];
$a=file_get_contents("http://bitcoincharts.com/t/weighted_prices.json"); $res=(json_decode($a, true)); $day = $res['USD']['24h'];
echo min($low, $day);
|
Own address: 19QkqAza7BHFTuoz9N8UQkryP4E9jHo4N3 - Pywallet support: 1AQDfx22pKGgXnUZFL1e4UKos3QqvRzNh5 - Bitcointalk++ script support: 1Pxeccscj1ygseTdSV1qUqQCanp2B2NMM2 Pywallet: instructions. Encrypted wallet support, export/import keys/addresses, backup wallets, export/import CSV data from/into wallet, merge wallets, delete/import addresses and transactions, recover altcoins sent to bitcoin addresses, sign/verify messages and files with Bitcoin addresses, recover deleted wallets, etc.
|
|
|
|
NothinG
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
August 08, 2011, 11:02:51 PM |
|
<?php $a=file_get_contents("https://mtgox.com/code/data/ticker.php"); $res=(json_decode($a, true)); $low = $res['ticker']['low'];
$a=file_get_contents("http://bitcoincharts.com/t/weighted_prices.json"); $res=(json_decode($a, true)); $day = $res['USD']['24h'];
echo min($low, $day); ?>
|
|
|
|
jackjack
Legendary
Offline
Activity: 1176
Merit: 1257
May Bitcoin be touched by his Noodly Appendage
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
August 08, 2011, 11:07:30 PM |
|
While dealing with php files, you always need to put the code between '<?' and '?>'
|
Own address: 19QkqAza7BHFTuoz9N8UQkryP4E9jHo4N3 - Pywallet support: 1AQDfx22pKGgXnUZFL1e4UKos3QqvRzNh5 - Bitcointalk++ script support: 1Pxeccscj1ygseTdSV1qUqQCanp2B2NMM2 Pywallet: instructions. Encrypted wallet support, export/import keys/addresses, backup wallets, export/import CSV data from/into wallet, merge wallets, delete/import addresses and transactions, recover altcoins sent to bitcoin addresses, sign/verify messages and files with Bitcoin addresses, recover deleted wallets, etc.
|
|
|
Jeremy West spendbitcoins.com (OP)
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
August 08, 2011, 11:08:53 PM |
|
<?php $a=file_get_contents("https://mtgox.com/code/data/ticker.php"); $res=(json_decode($a, true)); $low = $res['ticker']['low'];
$a=file_get_contents("http://bitcoincharts.com/t/weighted_prices.json"); $res=(json_decode($a, true)); $day = $res['USD']['24h'];
echo min($low, $day); ?> Hmmm.... Does that code return a value to you? Maybe it's a problem with my server, but on my link it just hangs. Does it return a value for anyone else who clicks on it? http://spendbitcoins.com/jefftest/last-24hr.php
|
|
|
|
jackjack
Legendary
Offline
Activity: 1176
Merit: 1257
May Bitcoin be touched by his Noodly Appendage
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
August 08, 2011, 11:14:03 PM |
|
Nope, you should test with the curl function then
|
Own address: 19QkqAza7BHFTuoz9N8UQkryP4E9jHo4N3 - Pywallet support: 1AQDfx22pKGgXnUZFL1e4UKos3QqvRzNh5 - Bitcointalk++ script support: 1Pxeccscj1ygseTdSV1qUqQCanp2B2NMM2 Pywallet: instructions. Encrypted wallet support, export/import keys/addresses, backup wallets, export/import CSV data from/into wallet, merge wallets, delete/import addresses and transactions, recover altcoins sent to bitcoin addresses, sign/verify messages and files with Bitcoin addresses, recover deleted wallets, etc.
|
|
|
NothinG
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
August 08, 2011, 11:15:44 PM |
|
<?php $a=file_get_contents("https://mtgox.com/code/data/ticker.php"); $res=(json_decode($a, true)); $low = $res['ticker']['low'];
$a=file_get_contents("http://bitcoincharts.com/t/weighted_prices.json"); $res=(json_decode($a, true)); $day = $res['USD']['24h'];
echo min($low, $day); ?> Hmmm.... Does that code return a value to you? Maybe it's a problem with my server, but on my link it just hangs. Does it return a value for anyone else who clicks on it? http://spendbitcoins.com/jefftest/last-24hr.phpI modified it just a tiny bit, tested it on my server and it works. <?php $a=file_get_contents("https://mtgox.com/code/data/ticker.php"); $res=json_decode($a, true); $low = $res['ticker']['low'];
$a=file_get_contents("http://bitcoincharts.com/t/weighted_prices.json"); $res=json_decode($a, true); $day = $res['USD']['24h'];
echo "\$low = ".$low."<br />"; echo "\$day = ".$day."<br />"; ?> For some reason wrapping json_decode() in parenthesis slowed it down a lot.
|
|
|
|
jackjack
Legendary
Offline
Activity: 1176
Merit: 1257
May Bitcoin be touched by his Noodly Appendage
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
August 08, 2011, 11:19:25 PM |
|
<? $a=file_get_contents("http://mtgox.com/code/data/ticker.php"); $res=(json_decode($a, true)); $low = $res['ticker']['low'];
$a=file_get_contents("http://bitcoincharts.com/t/weighted_prices.json"); $res=(json_decode($a, true)); $day = $res['USD']['24h'];
echo min($low, $day); ?> file_get_contents might not work with https http://mtgox.com/code/data/ticker.php is *really* long to respond, too
|
Own address: 19QkqAza7BHFTuoz9N8UQkryP4E9jHo4N3 - Pywallet support: 1AQDfx22pKGgXnUZFL1e4UKos3QqvRzNh5 - Bitcointalk++ script support: 1Pxeccscj1ygseTdSV1qUqQCanp2B2NMM2 Pywallet: instructions. Encrypted wallet support, export/import keys/addresses, backup wallets, export/import CSV data from/into wallet, merge wallets, delete/import addresses and transactions, recover altcoins sent to bitcoin addresses, sign/verify messages and files with Bitcoin addresses, recover deleted wallets, etc.
|
|
|
jackjack
Legendary
Offline
Activity: 1176
Merit: 1257
May Bitcoin be touched by his Noodly Appendage
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
August 08, 2011, 11:25:27 PM |
|
|
Own address: 19QkqAza7BHFTuoz9N8UQkryP4E9jHo4N3 - Pywallet support: 1AQDfx22pKGgXnUZFL1e4UKos3QqvRzNh5 - Bitcointalk++ script support: 1Pxeccscj1ygseTdSV1qUqQCanp2B2NMM2 Pywallet: instructions. Encrypted wallet support, export/import keys/addresses, backup wallets, export/import CSV data from/into wallet, merge wallets, delete/import addresses and transactions, recover altcoins sent to bitcoin addresses, sign/verify messages and files with Bitcoin addresses, recover deleted wallets, etc.
|
|
|
NothinG
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
August 08, 2011, 11:28:31 PM |
|
|
|
|
|
drawoc
Full Member
![*](https://bitcointalk.org/Themes/custom1/images/star.gif) ![*](https://bitcointalk.org/Themes/custom1/images/star.gif)
Offline
Activity: 168
Merit: 100
Firstbits: 175wn
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
August 09, 2011, 12:13:20 AM Last edit: August 09, 2011, 12:46:17 AM by drawoc |
|
http://mtgox.com/code/data/ticker.php looks like it redirects to https to me. Anyway I tried this and I'm getting a similar problem to Jeremy, so I'll try to see if I can fix it. On my machine, specifying http://mtgox.com/code/data/ticker.php results in a 500 on the page, and this in the log: [Mon Aug 08 19:39:18 2011] [error] [client 127.0.0.1] PHP Warning: file_get_contents(http://mtgox.com/code/data/ticker.php): failed to open stream: HTTP request failed! in /var/www/hi.php on line 2
Specifying https://mtgox.com/code/data/ticker.php results in the page hanging forever, and nothing at all in the logs. (not even an acknowledgement of the request, like Apache normally does). Comment the line out that grabs the mt.gox data and the page loads fine. Strangely, stream_get_wrappers() does show that https is available on my machine. Yes, Mt.Gox is up here, just very slow. I don't have the php curl wrapper installed, maybe I'll install it and try the other example. Edit: Yep, the curl one works perfectly fine.
|
Donate: 175WNXmJ1WVhFgVGKUqEhYtAQGRYAvqPA
|
|
|
Jeremy West spendbitcoins.com (OP)
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
August 09, 2011, 09:49:58 PM |
|
$a=ouvrirpage("https://mtgox.com/code/data/ticker.php"); $res=(json_decode($a, true)); $low = $res['ticker']['low'];
$a=ouvrirpage("http://bitcoincharts.com/t/weighted_prices.json"); $res=(json_decode($a, true)); $day = $res['USD']['24h'];
echo min($low, $day);
function ouvrirpage($site){ $ch = curl_init($site); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($ch); curl_close($ch); return $res; } or if you don't like curl: $a=file_get_contents("https://mtgox.com/code/data/ticker.php"); $res=(json_decode($a, true)); $low = $res['ticker']['low'];
$a=file_get_contents("http://bitcoincharts.com/t/weighted_prices.json"); $res=(json_decode($a, true)); $day = $res['USD']['24h'];
echo min($low, $day);
Cool. Got it working with the curl one (never rechecked that one with the <? /?> Last coding I did was GW-Basic in the early 90s. ![Smiley](https://bitcointalk.org/Smileys/default/smiley.gif) And that was just copying and changing code, have never really coded anything from scratch. Anyway, bounty on its way to your signature bitcoin address. Thanks!
|
|
|
|
|