Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: WorldOfBitcoin on October 11, 2012, 05:30:39 AM



Title: Storing price history on a site. MTgox alternitives to cron job
Post by: WorldOfBitcoin on October 11, 2012, 05:30:39 AM
 I am building a site where I need to store bitcoin USD trade prices in a set time intervals into a SQL database. So I have a database I can throw transactions against and get trading price at the time of Transaction.  I think I could do this with a php script to returns MTgox last price but the finest time intervals a Cron Job is hourly.

I read in some other forms you could just have a php script run on an infinite loop with a sleep 5 second.  But I don’t like the sound of that would it really be 24/7? Dont really want to doxx MTgox. If it ever stopped would I need to start it back up? I need something extremely dependable and as close to real time pricing is preferred. What kind of options are out there?

This sounds to me like something a web socket would be for. Is it possible to connect to MTgox’s websocket 24/7 and store data in this in this fashion?


Title: Re: Storing price history on a site. MTgox alternitives to cron job
Post by: gweedo on October 11, 2012, 06:06:51 AM
Yes it is possible, I would write a python script or a java application that just takes the web socket stream and add it to your database.


Title: Re: Storing price history on a site. MTgox alternitives to cron job
Post by: exotime on October 19, 2012, 12:18:45 PM
You may wish to ask MtGox nicely if they have an API feed somewhere. If you started hitting their website every five seconds for a scripting purpose, and they find out, I doubt they'll be terribly happy. Bandwidth isn't cheap, if their sysadmin is decent he'll just block your IP.


Title: Re: Storing price history on a site. MTgox alternitives to cron job
Post by: Girhes on October 19, 2012, 06:38:02 PM
Cron jobs could be run every minute actually. I you want a better resolution you can make a client in any language that polls the API every 10-15 seconds, and use a simple cron script to make sure it is running.


Title: Re: Storing price history on a site. MTgox alternitives to cron job
Post by: BitcoinRate.com on October 19, 2012, 11:03:58 PM
You want to get the price of the latest trade, or the most recent best bid and best ask?

If the former, check out this script written in Python that uses the HTTP Rest API and a sqlite database (you could replace that of course). Also note the 10 second delay that is built in between requests.

http://cahier2.ww7.be/bitcoinmirror/phantomcircuit/mtgox.py

It should give you an idea on how to implement this (if you want the most recent best bid ans ask you could change some things like the url to be called and the handling of the json).

You could start this script of with a cronjob, and to be sure it keeps running do a restart hourly through a cronjob.

Does this help you?