Author

Topic: Obtain bitcoin value with javascript. (Read 2893 times)

legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
June 26, 2011, 11:11:37 AM
#5
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!  Grin

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
member
Activity: 73
Merit: 10
June 26, 2011, 12:31:43 AM
#4
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/
newbie
Activity: 22
Merit: 0
June 25, 2011, 05:28:46 PM
#3
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.

"
Sorry, you must have Javascript enabled to use Mt. Gox
"

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

Thanks alot !
member
Activity: 70
Merit: 10
June 25, 2011, 04:36:20 PM
#2
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.
newbie
Activity: 22
Merit: 0
June 25, 2011, 04:23:31 PM
#1
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 !
Jump to: