Bitcoin Forum
December 03, 2016, 07:47:07 PM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: GoxGrab: fetch Mt. Gox ticker data with PHP and automate it (with source code)  (Read 2904 times)
bitfreak!
Legendary
*
Offline Offline

Activity: 1514


electronic [r]evolution


View Profile WWW
June 26, 2011, 07:10:09 PM
 #1

Good day my fellow Bitcoiners. I figured I should share a simple little script I made for fetching the Mt. Gox ticker data using PHP. I'll also teach you how to automate it using Cron Jobs. I hope this will be useful to some of you. Wink

You should not use a script that sends a request to Mt. Gox every time the page is loaded. That is very bad practice because it puts unnecessary strain on Mt. Gox and your pages will take longer to load all the time.

The solution is to create a stand-alone script that fetches the ticker data and saves it to a file and/or into a database. You then set up something like Cron Jobs to fire the script at your preferred intervals of time.

One hour is about the minimum amount of time you should wait before each request. The script uses the PHP cURL function to retrieve the ticker data and then simply writes it to a file. Saving the data to a database is optional.

If you wish to know more about the script you can simply download it and check the source out yourself (see bottom of post for download). Now lets move on to automation, which is where some people can get stuck.

If you have cPanel you can easily set up Cron Jobs to automate a task. The time stuff is pretty self-explanatory, it dictates the period between each time the script will run. The command part is where you need to input the following:

php -q /home/serverpath/goxgrab/mtgox_update.php

All you need to do is change the first part "/home/serverpath/" to the correct location to your "goxgrab" folder (after you upload it; you might want to install the script before setting up Cron Jobs - see the install.txt file), then submit the Cron Job.

The included mtgox_stats.php file shows you how to extract the ticker data from your local copy and save it as an associative array. This file can easily be included into other scripts that need access to the Mt. Gox ticker data.

Download the project from bitfreak.co.cc: GoxGrab

All feedback is welcome, especially about bugs or suggestions. Donations are also appreciated.  Cheesy

NEXT TIME: Using HTML5 to graph ticker data!

EDIT: Just did some heavy updates. If you have downloaded it already, I suggest you do it again, unless you already figured out how to make the mtgox_stats.php file work properly.

XCN: CYsvPpb2YuyAib5ay9GJXU8j3nwohbttTz | BTC: 18MWPVJA9mFLPFT3zht5twuNQmZBDzHoWF
Cryptonite - 1st mini-blockchain altcoin | BitShop - digital shop script
Web Developer - PHP, SQL, JS, AJAX, JSON, XML, RSS, HTML, CSS
1480794427
Hero Member
*
Offline Offline

Posts: 1480794427

View Profile Personal Message (Offline)

Ignore
1480794427
Reply with quote  #2

1480794427
Report to moderator
1480794427
Hero Member
*
Offline Offline

Posts: 1480794427

View Profile Personal Message (Offline)

Ignore
1480794427
Reply with quote  #2

1480794427
Report to moderator
1480794427
Hero Member
*
Offline Offline

Posts: 1480794427

View Profile Personal Message (Offline)

Ignore
1480794427
Reply with quote  #2

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

Posts: 1480794427

View Profile Personal Message (Offline)

Ignore
1480794427
Reply with quote  #2

1480794427
Report to moderator
1480794427
Hero Member
*
Offline Offline

Posts: 1480794427

View Profile Personal Message (Offline)

Ignore
1480794427
Reply with quote  #2

1480794427
Report to moderator
Keninishna
Hero Member
*****
Offline Offline

Activity: 551



View Profile WWW
June 27, 2011, 05:32:07 PM
 #2

Nice! I was looking for something exactly like this.
bitfreak!
Legendary
*
Offline Offline

Activity: 1514


electronic [r]evolution


View Profile WWW
June 28, 2011, 06:41:17 AM
 #3

Glad to see you found it useful. I couldn't really see anything like this on the forums so I decided to share.  Wink

XCN: CYsvPpb2YuyAib5ay9GJXU8j3nwohbttTz | BTC: 18MWPVJA9mFLPFT3zht5twuNQmZBDzHoWF
Cryptonite - 1st mini-blockchain altcoin | BitShop - digital shop script
Web Developer - PHP, SQL, JS, AJAX, JSON, XML, RSS, HTML, CSS
2501
Hero Member
*****
Offline Offline

Activity: 868


Impossible is Nothing


View Profile WWW
February 27, 2013, 09:50:39 PM
 #4

Do you have a copy and paste version for a joomla site?

Bitrated user: Allex.
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!