Bitcoin Forum
April 24, 2024, 06:56:27 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Having trouble grabbing bitcoin price  (Read 1734 times)
Jeremy West spendbitcoins.com (OP)
Hero Member
*****
Offline Offline

Activity: 700
Merit: 501



View Profile WWW
December 20, 2011, 10:37:21 AM
 #1

I use this code to grab my current rates on http://spendbitcoins.com:

Code:
<?php
$a
=ouvrirpage("http://mtgox.com/api/0/data/ticker.php");
$res=(json_decode($atrue));
$last round ($res['ticker']['sell'], 2);

echo 
$last;

function 
ouvrirpage($site){
$ch curl_init($site);
curl_setopt($chCURLOPT_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($chCURLOPT_RETURNTRANSFER1);
$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!

1713941787
Hero Member
*
Offline Offline

Posts: 1713941787

View Profile Personal Message (Offline)

Ignore
1713941787
Reply with quote  #2

1713941787
Report to moderator
Transactions must be included in a block to be properly completed. When you send a transaction, it is broadcast to miners. Miners can then optionally include it in their next blocks. Miners will be more inclined to include your transaction if it has a higher transaction fee.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713941787
Hero Member
*
Offline Offline

Posts: 1713941787

View Profile Personal Message (Offline)

Ignore
1713941787
Reply with quote  #2

1713941787
Report to moderator
1713941787
Hero Member
*
Offline Offline

Posts: 1713941787

View Profile Personal Message (Offline)

Ignore
1713941787
Reply with quote  #2

1713941787
Report to moderator
1713941787
Hero Member
*
Offline Offline

Posts: 1713941787

View Profile Personal Message (Offline)

Ignore
1713941787
Reply with quote  #2

1713941787
Report to moderator
notme
Legendary
*
Offline Offline

Activity: 1904
Merit: 1002


View Profile
December 20, 2011, 10:44:03 AM
Last edit: December 20, 2011, 11:32:23 AM by notme
 #2

I use this code to grab my current rates on http://spendbitcoins.com:

Code:
<?php
$a
=ouvrirpage("http://mtgox.com/api/0/data/ticker.php");
$res=(json_decode($atrue));
$last round ($res['ticker']['sell'], 2);

echo 
$last;

function 
ouvrirpage($site){
$ch curl_init($site);
curl_setopt($chCURLOPT_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($chCURLOPT_RETURNTRANSFER1);
$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.

https://www.bitcoin.org/bitcoin.pdf
While no idea is perfect, some ideas are useful.
Jeremy West spendbitcoins.com (OP)
Hero Member
*****
Offline Offline

Activity: 700
Merit: 501



View Profile WWW
December 20, 2011, 11:29:23 AM
 #3

I use this code to grab my current rates on http://spendbitcoins.com:

Code:
<?php
$a
=ouvrirpage("http://mtgox.com/api/0/data/ticker.php");
$res=(json_decode($atrue));
$last round ($res['ticker']['sell'], 2);

echo 
$last;

function 
ouvrirpage($site){
$ch curl_init($site);
curl_setopt($chCURLOPT_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($chCURLOPT_RETURNTRANSFER1);
$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 ratedon't be fooled by the fact that there are now prices on my website. I've put them in manually for nowwhich is not the way I like to do thingsSo any help by someone well versed in php is still appreciatedThanks!

?>


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

Activity: 225
Merit: 101


View Profile
December 20, 2011, 02:42:04 PM
 #4

I use this code to grab my current rates on http://spendbitcoins.com:

Code:
<?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. Smiley

$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:

Code:
$ 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.

Like my posts?  Connect with me on LinkedIn and endorse my "Bitcoin" skill.
Decentralized, instant off-chain payments.
Jeremy West spendbitcoins.com (OP)
Hero Member
*****
Offline Offline

Activity: 700
Merit: 501



View Profile WWW
December 20, 2011, 04:34:13 PM
 #5

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

Activity: 140
Merit: 100


View Profile
December 20, 2011, 07:15:00 PM
 #6

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

Activity: 140
Merit: 100


View Profile
December 20, 2011, 11:08:23 PM
Last edit: December 20, 2011, 11:44:52 PM by BinoX
 #7

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)

Code:
<?php

function ouvrirpage($site){  //Make sure the function goes at the top of the page....
 $ch curl_init($site);
 curl_setopt($chCURLOPT_RETURNTRANSFER1);
 curl_setopt($chCURLOPT_USERAGENT"Something Must Be Here/0.1"); //MtGox seems to REQUIRE this to be short...
 curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);  //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($atrue));
$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 Offline

Activity: 1904
Merit: 1037


Trusted Bitcoiner


View Profile WWW
December 21, 2011, 12:12:45 AM
 #8

I use this code to grab my current rates on http://spendbitcoins.com:

Code:
<?php
$a
=ouvrirpage("http://mtgox.com/api/0/data/ticker.php");
$res=(json_decode($atrue));
$last round ($res['ticker']['sell'], 2);

echo 
$last;

function 
ouvrirpage($site){
$ch curl_init($site);
curl_setopt($chCURLOPT_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($chCURLOPT_RETURNTRANSFER1);
$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 Offline

Activity: 1190
Merit: 1000


www.bitcointrading.com


View Profile WWW
December 21, 2011, 04:09:04 PM
 #9

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

Activity: 700
Merit: 501



View Profile WWW
December 21, 2011, 11:40:08 PM
 #10

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.

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!