Bitcoin Forum
May 21, 2024, 06:01:33 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Help me with bitcoin api  (Read 1317 times)
iformas (OP)
Newbie
*
Offline Offline

Activity: 19
Merit: 0


View Profile
August 10, 2012, 09:58:59 PM
 #1

hi, i want show in my web the current bitcoin value from mtgox, and i don't know how do it.
I read that with Jquery is possible ($. getJSON)in other parts say that jQuery can read json just inside the same domain.

can someone describe me a method step by step for get the current Bitcoin value and show it in an html?
iformas (OP)
Newbie
*
Offline Offline

Activity: 19
Merit: 0


View Profile
August 14, 2012, 03:06:59 PM
 #2

i make a little proxy for get ticker data

proxy2.php
Code:
<?php
  $ch 
curl_init();
  
curl_setopt($chCURLOPT_RETURNTRANSFER1);
  
curl_setopt($chCURLOPT_USERAGENT"curl/7.21.3 (x86_64-pc-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18");
  
curl_setopt($chCURLOPT_URL'https://mtgox.com/code/data/ticker.php');
  
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  
$output curl_exec($ch);
  
curl_close($ch);
  echo 
json_encode($output);
  
?>

in html file i have
Code:
<script type="text/javascript">
$.getJSON("proxy2.php", function(data) {
console.log(data);
//$('#ticker_mtgox').html(parseFloat(data.ticker.last).toFixed(2) + ' USD');
});
</script>
<li class="current">MtGox: </li>
<li id="ticker_mtgox"></li>

in log i have
Code:
"{\"ticker\":{\"high\":12.17887,\"low\":11.4919,\"avg\":11.931998599,\"vwap\":11.880445695,\"vol\":61162,\"last_all\":12.1,\"last_local\":12.1,\"last\":12.1,\"buy\":12.09999,\"sell\":12.1}}"

 D:
in ticker_mtgox y have nothing

maybe the problem is because I should get something like this
Code:
{"ticker":{"high":12.17887000,"low":11.49190000,"vol":61092.00000000,"last":12.10000000,"buy":12.09999000,"sell":12.10000000,"date":1344913200}}

without the "\" symbols

can help me to fix it..or tell me a way to "ticker_mtgox" work?
kokjo
Legendary
*
Offline Offline

Activity: 1050
Merit: 1000

You are WRONG!


View Profile
August 15, 2012, 07:36:17 AM
 #3

the output from curl_exec is already in json, you are double encoding with json_encode, hence the \"

"The whole problem with the world is that fools and fanatics are always so certain of themselves and wiser people so full of doubts." -Bertrand Russell
gweedo
Legendary
*
Offline Offline

Activity: 1498
Merit: 1000


View Profile
August 15, 2012, 04:21:50 PM
 #4

the output from curl_exec is already in json, you are double encoding with json_encode, hence the \"

I didn't even see that, but I think he mean json_decode to get the json into an array
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!