Bitcoin Forum

Bitcoin => Bitcoin Discussion => Topic started by: alkhdaniel on June 15, 2011, 02:34:37 PM



Title: Simple php script to get data from mtgox.
Post by: alkhdaniel on June 15, 2011, 02:34:37 PM
Two simple scripts to display some statistics from mtgox, not much more to say really.
These scripts will work without the json extension installed, you only need php to be able to use this.

Mtgoxtrade
Desctiption: Fetches https://mtgox.com/code/data/getTrades.php and convert some data into variables for easier usage. (Don't include this on a highly visited page since it uses alot of resources (because mtgox's gettrades.php is a huge file)
Example page (http://91.215.158.89/~twyxgiv/bitcoin/mtgoxtrade/mtgoxtrade.php)
Download (http://solidfiles.net/d/4bc38/)
Usage:
Include mtgoxtrade.class to your php file and use the following variables:
$price(x) Get the price of the x'th last transaction (x=0 will get the latest transaction, x=99 will get the 100th last transaction)
$avgprice(x) Gets the average price of the last x transaction (x=99 will give you the avg of last 100 transactions)
$high Gets you the "high" of how many transactions you specified to read (changed with the $chunk variable inside mtgoxtrade.class)
$low Same as $high but for lowest transaction

There's also some variables that you can change in the .class file, just read the commented lines to see what they do.


Mtgoxtick
Description: Fetches https://mtgox.com/code/data/ticker.php and convert some data into variables for easier usage. Use this instead of Mtgoxtrade if what you're looking for is provided by this script since it uses alot less resources.
Example page (http://91.215.158.89/~twyxgiv/bitcoin/mtgoxtick/mtgoxtick.php)
Download (http://solidfiles.net/d/1deb6/)
Usage:
Include mtgoxtick.class to your php file and use the following variables:
$high Gets the "high" from mtgox (in usd) (last 24hrs i believe? not sure).
$low Gets the "low" from mtgox (in usd).
$vol Gets the volume of money in the market right now (in btc)
$buy Gets the highest buy price (in usd).
$sell Gets the loewst sell price (in usd)
$last Gets the price of the last bitcoin sold (in usd)

If you like this or use this, please donate to 1Awyxgawq52mkYmiAQ9v4sLPXxStVsSGy8 (even a bitcent would be nice)


Title: Re: Simple php script to get data from mtgox.
Post by: ukbitco.in on June 15, 2011, 03:41:06 PM
Thanks,

I like.


Title: Re: Simple php script to get data from mtgox.
Post by: charliesheen on June 16, 2011, 04:52:04 AM
I could have used this a week ago.


Title: Re: Simple php script to get data from mtgox.
Post by: alkhdaniel on July 14, 2011, 03:38:22 PM
alkhdaniel, great! I was looking for something like this.
But I can't download it from solidfiles. :( Could you re-upload them plz?
http://www.multiupload.com/H87JSOELJW (contains both ticker & trade)
I think this is the exact same script (just looked through it fast before rarring/uploading), might have changed some small detail but doubt it.
If your server accepts JSON and you have some experience in coding you should go with the bitcoinusa.com-code since it's a little bit cleaner than mine though, also mine might not always work (it doesn't send HTTP_USER_AGENT to the server and it seems like mtgox needs this sometimes, atleast there was some problems with the script after the hack a half month ago but i believe it works flawlessly now again). Might fix this little problem if there was some more interest in it though.

~Daniel.


Title: Re: Simple php script to get data from mtgox.
Post by: AlexNeto on July 14, 2011, 11:54:46 PM
Thank You guys!


Title: Re: Simple php script to get data from mtgox.
Post by: brandon@sourcewerks on July 15, 2011, 01:40:04 AM
Quote
(Don't include this on a highly visited page since it uses alot of resources (because mtgox's gettrades.php is a huge file)

Can be done by using a messaging queue (activeMQ) similar to getting data from the twitter firehose. Setup a background process to cache the file every few minutes.  If not, lke OP says, you best have at least 1-2GB memory and plenty of CPU cycles to handle processing multiple page loads. 

Nice job alkhdaniel  :)


Title: Re: Simple php script to get data from mtgox.
Post by: Leon on July 15, 2011, 02:02:34 AM
Very well done!