Bitcoin Forum
April 26, 2024, 08:12:18 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Last price from Mt Gox json  (Read 1349 times)
Jeremy West spendbitcoins.com (OP)
Hero Member
*****
Offline Offline

Activity: 700
Merit: 501



View Profile WWW
August 07, 2011, 08:15:43 PM
 #1

Can anyone help? I'm trying to grab the last price from Mt Gox using the following code:

<?php
    $url = 'https://mtgox.com/api/0/data/ticker.php';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_REFERER, $url);
    $json = curl_exec($ch);
    curl_close($ch);
    echo $json;//['ticker']['last'];
?>

and it's just hanging. Can anyone spot an error or if it's completely wrong just give me the right code? 1 BTC bounty if it works!

Thanks!

1714119138
Hero Member
*
Offline Offline

Posts: 1714119138

View Profile Personal Message (Offline)

Ignore
1714119138
Reply with quote  #2

1714119138
Report to moderator
Be very wary of relying on JavaScript for security on crypto sites. The site can change the JavaScript at any time unless you take unusual precautions, and browsers are not generally known for their airtight security.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714119138
Hero Member
*
Offline Offline

Posts: 1714119138

View Profile Personal Message (Offline)

Ignore
1714119138
Reply with quote  #2

1714119138
Report to moderator
1714119138
Hero Member
*
Offline Offline

Posts: 1714119138

View Profile Personal Message (Offline)

Ignore
1714119138
Reply with quote  #2

1714119138
Report to moderator
jackjack
Legendary
*
Offline Offline

Activity: 1176
Merit: 1233


May Bitcoin be touched by his Noodly Appendage


View Profile
August 07, 2011, 08:41:51 PM
Last edit: August 10, 2011, 06:45:42 PM by jackjack
 #2

Here's what I usually use
Code:
<?php
$a
=ouvrirpage("https://mtgox.com/code/data/ticker.php");
$res=json_decode($atrue);
echo 
$res['ticker']['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;
}
?>

Maybe MtGox needs an useragent header

Own address: 19QkqAza7BHFTuoz9N8UQkryP4E9jHo4N3 - Pywallet support: 1AQDfx22pKGgXnUZFL1e4UKos3QqvRzNh5 - Bitcointalk++ script support: 1Pxeccscj1ygseTdSV1qUqQCanp2B2NMM2
Pywallet: instructions. Encrypted wallet support, export/import keys/addresses, backup wallets, export/import CSV data from/into wallet, merge wallets, delete/import addresses and transactions, recover altcoins sent to bitcoin addresses, sign/verify messages and files with Bitcoin addresses, recover deleted wallets, etc.
wumpus
Hero Member
*****
Offline Offline

Activity: 812
Merit: 1022

No Maps for These Territories


View Profile
August 07, 2011, 08:42:47 PM
 #3

Yeah, you should use https://mtgox.com/code/data/ticker.php ... The URL that you use requires logging in.


Bitcoin Core developer [PGP] Warning: For most, coin loss is a larger risk than coin theft. A disk can die any time. Regularly back up your wallet through FileBackup Wallet to an external storage or the (encrypted!) cloud. Use a separate offline wallet for storing larger amounts.
markm
Legendary
*
Offline Offline

Activity: 2940
Merit: 1090



View Profile WWW
August 08, 2011, 01:50:33 AM
 #4

I read somewhere too that useragents that actually send a useragent field might be favoured over those  that do not?

(Dunno if bots would actually be requred to pretend to be (vanilla ?) browsers in order to be permitted to use the bot-enabling API though, has anyone tried being honest about which version of which bot is making the request?)

-MarkM-

Browser-launched Crossfire client now online (select CrossCiv server for Galactic  Milieu)
Free website hosting with PHP, MySQL etc: http://hosting.knotwork.com/
antares
Hero Member
*****
Offline Offline

Activity: 518
Merit: 500


View Profile
August 08, 2011, 11:41:29 PM
 #5

acutally a user agent seems not to be required. In my android App I don't use one either. And It would not really make sense, at least when using the MtGox API, as this one is intended for non-browser traffic
brandon@sourcewerks
Member
**
Offline Offline

Activity: 62
Merit: 10



View Profile
August 10, 2011, 04:00:59 PM
 #6

Just wanted to get it out there,  BOTs are easily written to appear as browsers or even do it the dirty way and run in the browser.

The useragent is configurable in the HTTP headers that you send with the request.  Also, MT.Gox likes a unique user-agent.
alkhdaniel
Member
**
Offline Offline

Activity: 114
Merit: 10


View Profile
August 10, 2011, 05:20:53 PM
 #7

Code:
<?php
$opts 
= array(
  
'http'=> array(
    
'method'=>   "GET",
    
'user_agent'=>    "MozillaXYZ/1.0"));
$context stream_context_create($opts);
$json file_get_contents('https://mtgox.com/code/data/ticker.php'false$context);
$json json_decode($json);
echo 
$json->{'ticker'}->{'last'};
?>

Jeremy West spendbitcoins.com (OP)
Hero Member
*****
Offline Offline

Activity: 700
Merit: 501



View Profile WWW
August 10, 2011, 09:06:06 PM
 #8

Sorry, forgot to post here that I already got this working with help from another thread. Thanks!

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!