Bit_Happy (OP)
Legendary
Offline
Activity: 2100
Merit: 1040
A Great Time to Start Something!
|
|
January 20, 2012, 10:58:55 PM Last edit: January 21, 2012, 06:48:59 AM by Bit_Happy |
|
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#Authentication1) This URl: https://mtgox.com/api/0/data/ticker.phpReturns the data in a browser, so it must be possible to do a simple script like this (for example) <?php
$jsonurl = "https://mtgox.com/api/0/data/ticker.php"; $json = file_get_contents($jsonurl,0,null,null); $values = json_decode($json, true);
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.
|
|
|
|
|
|
|
|
|
Once a transaction has 6 confirmations, it is extremely unlikely that an attacker without at least 50% of the network's computation power would be able to reverse it.
|
|
|
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
|
|
|
|
senbonzakura
|
|
January 20, 2012, 11:22:41 PM |
|
hope this helps <?php function updateExchangeRate() { $result = False; $url = "https://mtgox.com/api/0/data/ticker.php"; if ($CH = curl_init()) { curl_setopt($CH, CURLOPT_URL, $url); curl_setopt($CH, CURLOPT_RETURNTRANSFER, True); curl_setopt($CH, CURLOPT_SSL_VERIFYHOST, False); curl_setopt($CH, CURLOPT_SSL_VERIFYPEER, False); curl_setopt($CH, CURLOPT_TIMEOUT, 5); curl_setopt($CH, CURLOPT_USERAGENT, "MtGox PHP Client"); if ($output = curl_exec($CH)) { if ($result = json_decode($output, True)) { 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 (OP)
Legendary
Offline
Activity: 2100
Merit: 1040
A Great Time to Start Something!
|
|
January 20, 2012, 11:28:02 PM |
|
Will try it; Thanks senbonzakura.
|
|
|
|
senbonzakura
|
|
January 20, 2012, 11:35:05 PM |
|
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 (OP)
Legendary
Offline
Activity: 2100
Merit: 1040
A Great Time to Start Something!
|
|
January 21, 2012, 12:14:27 AM |
|
...tell us if it works for you.
After the curl, I just needed the variable, so (for example) //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
|
|
|
|
senbonzakura
|
|
January 21, 2012, 12:17:42 AM |
|
excellent I am new to this too, I learn by looking at example code, cant code from scratch , so example code saves me time are you developing a site or just learning php ?
|
|
|
|
Bit_Happy (OP)
Legendary
Offline
Activity: 2100
Merit: 1040
A Great Time to Start Something!
|
|
January 21, 2012, 06:48:25 AM |
|
excellent I am new to this too, I learn by looking at example code, cant code from scratch , so example code saves me time 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.
|
|
|
|
|