Bitcoin Forum

Bitcoin => Project Development => Topic started by: conbitcoin.com on June 25, 2011, 09:23:31 PM



Title: Obtain bitcoin value with javascript.
Post by: conbitcoin.com on June 25, 2011, 09:23:31 PM
Hi, i saw this script: http://sanescreen.org/converter/ for converting values.

But i dont know if it is going to be updated with the actual rates every 5 minutes in the following days.

Anyone know about some script to convert dollars to btc ? Or how can i obtain the mtgox value from https://mtgox.com/trade/history with javascript ?

Thanks alot !


Title: Re: Obtain bitcoin value with javascript.
Post by: sakkaku on June 25, 2011, 09:36:20 PM
If you are fetching the values for use in purchases, etc you don't want to do it with javascript.  Also it is somewhat of a rude thing to do if your site grows large because every customer coming to your site will hit the other site with a request.  Even if you somehow cache on the client side it will still be x number of pageviews per hour nailing the 3rd party.


Title: Re: Obtain bitcoin value with javascript.
Post by: conbitcoin.com on June 25, 2011, 10:28:46 PM
I can do it with php caching the result but i dont know how to extract the value from mtgox because it is loaded with javascript.

"<div id="ticker">Sorry, you must have Javascript enabled to use Mt. Gox</div>"

Some tip or web where i can obtain the bitcoin value ?

Thanks alot !


Title: Re: Obtain bitcoin value with javascript.
Post by: riush on June 26, 2011, 05:31:43 AM
not sure what they're planning to do with it but it seems the ticker api is returning data..
https://mtgox.com/code/data/ticker.php

or, you could use the bitcoincharts api http://bitcoincharts.com/about/markets-api/


Title: Re: Obtain bitcoin value with javascript.
Post by: bitfreak! on June 26, 2011, 04:11:37 PM
Hello people's.

You don't want to get the value each time a page is loaded. What you want to do is get the value every hour or every day or something like that, and save it to a database or file. The way I achieved this was to create a PHP script which extracts the ticker info from Mt. Gox and saves it to a file and/or into a database. Next I used Cron Jobs to make the script run automatically every two hours.

I will write a thread that describes how to do this (and provide the project code). BUT FIRST I need a little bit of help. My script was running smoothly until after the Mt. Gox crash. Now that Mt. Gox is back online my script still doesn't seem to be working. I checked the Mt. Gox ticker file manually and it seemed to be providing the json data as it should.

So that led me to believe maybe they were filtering out some of the headers. I was initially using the simple file_get_contents() function to retrieve the ticker data, so I decided to try the cURL functions and modify the header information to spoof my user agent. But that didn't seem to work either. Any help will be appreciated!  ;D

EDIT: Do not worry peoples, I have figured it out! I am writing up a thread on this now. I hope people will find it useful.

EDIT: Here you go: http://forum.bitcoin.org/index.php?topic=22886.0