Jeremy West spendbitcoins.com (OP)
|
|
December 20, 2011, 10:37:21 AM |
|
I use this code to grab my current rates on http://spendbitcoins.com: <?php $a=ouvrirpage("http://mtgox.com/api/0/data/ticker.php"); $res=(json_decode($a, true)); $last = round ($res['ticker']['sell'], 2);
echo $last;
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; }
?>
Normally, this returns the current sell rate at mtgox. The mtgox api is still up, but instead of returning the current sell rate, it is returning 0. Actually, I normally use the tradehill api, but it is down at the moment ( https://api.tradehill.com/APIv1/USD/Ticker). Can anyone tell me how to get my rates up and running again? I hate my site being broken at any time!
|
|
|
|
notme
Legendary
Offline
Activity: 1904
Merit: 1002
|
|
December 20, 2011, 10:44:03 AM Last edit: December 20, 2011, 11:32:23 AM by notme |
|
I use this code to grab my current rates on http://spendbitcoins.com: <?php $a=ouvrirpage("http://mtgox.com/api/0/data/ticker.php"); $res=(json_decode($a, true)); $last = round ($res['ticker']['sell'], 2);
echo $last;
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; }
?>
Normally, this returns the current sell rate at mtgox. The mtgox api is still up, but instead of returning the current sell rate, it is returning 0. Actually, I normally use the tradehill api, but it is down at the moment ( https://api.tradehill.com/APIv1/USD/Ticker). Can anyone tell me how to get my rates up and running again? I hate my site being broken at any time! Edit: moved comment out of quote Visiting that url works fine... I'm not a php expert though. I'd suggest echoing $a, and $res in addition to $last to make sure they are what you think they are.
|
|
|
|
Jeremy West spendbitcoins.com (OP)
|
|
December 20, 2011, 11:29:23 AM |
|
I use this code to grab my current rates on http://spendbitcoins.com: <?php $a=ouvrirpage("http://mtgox.com/api/0/data/ticker.php"); $res=(json_decode($a, true)); $last = round ($res['ticker']['sell'], 2);
echo $last;
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; }
Hmmmm.... I don't know what to expect because I had someone here write this code for me for a 1 BTC bounty. :)
$a returns "redirecting you to http://mtgox.com/api/0/data/ticker.php" and $res doesn't seem to return anything.
At any rate, don't be fooled by the fact that there are now prices on my website. I've put them in manually for now, which is not the way I like to do things. So any help by someone well versed in php is still appreciated. Thanks!
?>
Visiting that url works fine... I'm not a php expert though. I'd suggest echoing $a, and $res in addition to $last to make sure they are what you think they are. Normally, this returns the current sell rate at mtgox. The mtgox api is still up, but instead of returning the current sell rate, it is returning 0. Actually, I normally use the tradehill api, but it is down at the moment ( https://api.tradehill.com/APIv1/USD/Ticker). Can anyone tell me how to get my rates up and running again? I hate my site being broken at any time!
|
|
|
|
blueadept
|
|
December 20, 2011, 02:42:04 PM |
|
I use this code to grab my current rates on http://spendbitcoins.com: <?php $a=ouvrirpage("https://mtgox.com/api/0/data/ticker.php"); ... ?>
Normally, this returns the current sell rate at mtgox. The mtgox api is still up, but instead of returning the current sell rate, it is returning 0. Actually, I normally use the tradehill api, but it is down at the moment ( https://api.tradehill.com/APIv1/USD/Ticker). Can anyone tell me how to get my rates up and running again? I hate my site being broken at any time! Visiting that url works fine... I'm not a php expert though. I'd suggest echoing $a, and $res in addition to $last to make sure they are what you think they are. Hmmmm.... I don't know what to expect because I had someone here write this code for me for a 1 BTC bounty. $a returns "redirecting you to http://mtgox.com/api/0/data/ticker.php" and $res doesn't seem to return anything. At any rate, don't be fooled by the fact that there are now prices on my website. I've put them in manually for now, which is not the way I like to do things. So any help by someone well versed in php is still appreciated. Thanks! Change the "http" to "https" in the URL. Here's what I'm getting: $ wget -O - http://mtgox.com/api/0/data/ticker.php --2011-12-20 09:39:53-- http://mtgox.com/api/0/data/ticker.php Resolving mtgox.com... 72.52.5.67 Connecting to mtgox.com|72.52.5.67|:80... connected. HTTP request sent, awaiting response... 302 Found Location: https://mtgox.com/api/0/data/ticker.php [following] --2011-12-20 09:39:53-- https://mtgox.com/api/0/data/ticker.php Connecting to mtgox.com|72.52.5.67|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 153 [application/json] Saving to: `STDOUT'
0% [ ] 0 --.-K/s {"ticker":{"high":4.5,"low":3.409,"avg":3.815959343,"vwap":3.886831982,"vol":1466100%[======================================>] 153 --.-K/s in 0s
2011-12-20 09:39:54 (2.03 MB/s) - written to stdout [153/153]
$
Edit: Fixed/shortened quotes.
|
|
|
|
Jeremy West spendbitcoins.com (OP)
|
|
December 20, 2011, 04:34:13 PM |
|
Thanks. I'll have a look at that in the morning (my morning). In the meantime, got it working again with the Tradehill api.
|
|
|
|
BinoX
|
|
December 20, 2011, 07:15:00 PM |
|
Weirdly enough I've been having problems getting a php script to get the mtgox api information, but it works fine for all other sites... Possibly there's some kind of extra header in there that's upsetting the php curl implementation?
Edit:
I suspect it's because mtgox are sending the header Content-Type: application/json
and most other places seem to send Content-Type: text/html
|
|
|
|
BinoX
|
|
December 20, 2011, 11:08:23 PM Last edit: December 20, 2011, 11:44:52 PM by BinoX |
|
I have a solution for you. Here is your code that I have updated: This was tested under php 5.2.5 (Windows - IIS) and 5.3.8 (Ubuntu - Apache) <?php
function ouvrirpage($site){ //Make sure the function goes at the top of the page.... $ch = curl_init($site); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, "Something Must Be Here/0.1"); //MtGox seems to REQUIRE this to be short... curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //This was missing
$res = curl_exec($ch); curl_close($ch); return $res; }
$a=ouvrirpage("https://mtgox.com/api/0/data/ticker.php"); ///updated to https $res=(json_decode($a, true)); $last = round($res['ticker']['sell'], 2);
echo $last; ?> Edit: The "MtGox seems to REQUIRE this to be short..." only seems to be true for some versions of php (5.3.6 was fine with the original user agent string), bit of an unusual one that... But you could put whatever you wanted in there, e.g. "Your Web Site MtGox Module/1.0" or whatever
|
|
|
|
adamstgBit
Legendary
Offline
Activity: 1904
Merit: 1037
Trusted Bitcoiner
|
|
December 21, 2011, 12:12:45 AM |
|
I use this code to grab my current rates on http://spendbitcoins.com: <?php $a=ouvrirpage("http://mtgox.com/api/0/data/ticker.php"); $res=(json_decode($a, true)); $last = round ($res['ticker']['sell'], 2);
echo $last;
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; }
?>
Normally, this returns the current sell rate at mtgox. The mtgox api is still up, but instead of returning the current sell rate, it is returning 0. Actually, I normally use the tradehill api, but it is down at the moment ( https://api.tradehill.com/APIv1/USD/Ticker). Can anyone tell me how to get my rates up and running again? I hate my site being broken at any time! you should account for the possibility that the website could be down or to busy, to respond. consider making a corn job that would update a value on your database IF everything checked out.
|
|
|
|
mc_lovin
Legendary
Offline
Activity: 1190
Merit: 1000
www.bitcointrading.com
|
|
December 21, 2011, 04:09:04 PM |
|
My tradehill API ticker died for like 6-12 hours yesterday (or the day before i cant remember) but it started working again. It just said "timed out" instead of showing prices.
|
|
|
|
Jeremy West spendbitcoins.com (OP)
|
|
December 21, 2011, 11:40:08 PM |
|
My tradehill API ticker died for like 6-12 hours yesterday (or the day before i cant remember) but it started working again. It just said "timed out" instead of showing prices.
Yeah. Mine started working again too.
|
|
|
|
|