Bitcoin Forum
December 11, 2016, 04:22:32 AM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Easy way to (currently) get MtGox price into PHP variable?  (Read 4270 times)
Bit_Happy
Legendary
*
Offline Offline

Activity: 1442


A Great Time to Start Something!


View Profile
January 20, 2012, 10:58:55 PM
 #1

Please help w/ an easy question:

Note: I'm not looking to need to Authenticate w/ the full API
https://en.bitcoin.it/wiki/MtGox/API#Authentication

1) This URl:
https://mtgox.com/api/0/data/ticker.php
Returns the data in a browser, so it must be possible to do a simple script like this (for example)

Code:
<?php

$jsonurl 
"https://mtgox.com/api/0/data/ticker.php";
$json file_get_contents($jsonurl,0,null,null);
$values json_decode($jsontrue);

echo 
$values['ticker']['sell'];

?>

The above just gives a blank page.
This must be easy, can someone please tell me what is wrong?
Thank you very much.

15DYJpWJe9H1YofsNQbP9JEWWNn7XPZgbS
1481430152
Hero Member
*
Offline Offline

Posts: 1481430152

View Profile Personal Message (Offline)

Ignore
1481430152
Reply with quote  #2

1481430152
Report to moderator
1481430152
Hero Member
*
Offline Offline

Posts: 1481430152

View Profile Personal Message (Offline)

Ignore
1481430152
Reply with quote  #2

1481430152
Report to moderator
1481430152
Hero Member
*
Offline Offline

Posts: 1481430152

View Profile Personal Message (Offline)

Ignore
1481430152
Reply with quote  #2

1481430152
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1481430152
Hero Member
*
Offline Offline

Posts: 1481430152

View Profile Personal Message (Offline)

Ignore
1481430152
Reply with quote  #2

1481430152
Report to moderator
senbonzakura
Hero Member
*****
Offline Offline

Activity: 602


View Profile
January 20, 2012, 11:22:41 PM
 #2

hope this helps

Code:
<?php
function updateExchangeRate() {
$result False;
$url "https://mtgox.com/api/0/data/ticker.php";

if ($CH curl_init()) {
curl_setopt($CHCURLOPT_URL$url);
curl_setopt($CHCURLOPT_RETURNTRANSFERTrue);
curl_setopt($CHCURLOPT_SSL_VERIFYHOSTFalse);
curl_setopt($CHCURLOPT_SSL_VERIFYPEERFalse);
curl_setopt($CHCURLOPT_TIMEOUT5);
curl_setopt($CHCURLOPT_USERAGENT"MtGox PHP Client");

if ($output curl_exec($CH)) {
if ($result json_decode($outputTrue)) {
if ($result $result['ticker']) {
databaseQuery("UPDATE `mytable`.`misc` SET `value`=:price WHERE `key`='mtgox'"False, array('price' => round($result['last'], 2)));
}
} else {
// JSON decoding failed. //
}
} else {
// cURL connection failed. //
}
} else {
// cURL initialization failed. //
}
$CH NULL;
}
?>

Bit_Happy
Legendary
*
Offline Offline

Activity: 1442


A Great Time to Start Something!


View Profile
January 20, 2012, 11:28:02 PM
 #3

Will try it; Thanks senbonzakura.

15DYJpWJe9H1YofsNQbP9JEWWNn7XPZgbS
senbonzakura
Hero Member
*****
Offline Offline

Activity: 602


View Profile
January 20, 2012, 11:35:05 PM
 #4

the above saves the price on database, and then i get the updated price each time from database.

you can alter it any way you like, good luck, tell us if it works for you.
Bit_Happy
Legendary
*
Offline Offline

Activity: 1442


A Great Time to Start Something!


View Profile
January 21, 2012, 12:14:27 AM
 #5

...tell us if it works for you.

After the curl, I just needed the variable, so  (for example)

Code:
//decode from an object to array
$output_mtgox = json_decode($mtgoxjson);
$output_mtgox_1 = get_object_vars($output_mtgox);
$mtgox_array = get_object_vars($output_mtgox_1['ticker']);

$ask_price= $mtgox_array['sell'];


Yes that helped, thanks  Smiley

15DYJpWJe9H1YofsNQbP9JEWWNn7XPZgbS
senbonzakura
Hero Member
*****
Offline Offline

Activity: 602


View Profile
January 21, 2012, 12:17:42 AM
 #6

excellent Smiley

I am new to this too, I learn by looking at example code, cant code from scratch , so example code saves me time Smiley

are you developing a site or just learning php ?
Bit_Happy
Legendary
*
Offline Offline

Activity: 1442


A Great Time to Start Something!


View Profile
January 21, 2012, 06:48:25 AM
 #7

excellent Smiley

I am new to this too, I learn by looking at example code, cant code from scratch , so example code saves me time Smiley

are you developing a site or just learning php ?

Similar here, learn by example then make changes and learn even more when trying to fix what's broken.   Cheesy

15DYJpWJe9H1YofsNQbP9JEWWNn7XPZgbS
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!