Author

Topic: JQuery and mtgox ticker not playing nicely (Read 3007 times)

donator
Activity: 2772
Merit: 1019
June 12, 2011, 06:26:00 AM
#10
MTGox has a websockets interface that you might be able to use instead.
http://websocket.org/ - THe official website
http://caniuse.com/#feat=websockets - Lookup browser support



here's the forum topic with lots of info (also on the currently existing bugs):

http://forum.bitcoin.org/index.php?topic=5855.0
member
Activity: 84
Merit: 10
MTGox has a websockets interface that you might be able to use instead.
http://websocket.org/ - THe official website
http://caniuse.com/#feat=websockets - Lookup browser support

newbie
Activity: 7
Merit: 0
Easy, yes, but I have neither a reliable server nor a reliable IP.  I was hoping to rely on mtgox.
member
Activity: 84
Merit: 10
I had a similar problem - so had to create a proxy script to run on my server. Pretty easy to do actually.
newbie
Activity: 3
Merit: 0
Your best bet would be to cache the ticker to your server at certain intervals and query that as json. Undecided
newbie
Activity: 7
Merit: 0
Quote
In the mean time, that means that you'll have to have your server grab the data and act as a proxy.

Darn, I was hoping to avoid that.  Ah well.

Thank you for your help!
legendary
Activity: 1204
Merit: 1015
But it -is- cross domain, so json isn't an option, right?

Firefox gives neither an error nor the javascript alert and chrome fails as expected with the following:

Code:
XMLHttpRequest cannot load https://mtgox.com/code/data/ticker.php. Origin http://[___MY_SITE___] is not allowed by Access-Control-Allow-Origin.
That actually depends on the site. That said, it appears that MtGox supports neither CORS or JSONP. You'll have to ask him about it.

In the mean time, that means that you'll have to have your server grab the data and act as a proxy.
newbie
Activity: 7
Merit: 0
But it -is- cross domain, so json isn't an option, right?

Firefox gives neither an error nor the javascript alert and chrome fails as expected with the following:

Code:
XMLHttpRequest cannot load https://mtgox.com/code/data/ticker.php. Origin http://[___MY_SITE___] is not allowed by Access-Control-Allow-Origin.
legendary
Activity: 1204
Merit: 1015
dataType: 'jsonp'

The dataType should just be 'json', since that's all your getting back. Besides, unless you control the server giving you the data, you shouldn't use jsonp.
newbie
Activity: 7
Merit: 0
Any thoughts on why this fails?

Code:









In firefox 4.0.1, I get this error:

Code:
Error: invalid label
Source File: https://mtgox.com/code/data/ticker.php?callback=jQuery1610765425372311095_1307774805819&_=1307774805835
Line: 1, Column: 1
Source Code:
{"ticker":{"high":28.601,"low":20.01,"vol":98283,"buy":21.751,"sell":21.8156,"last":21.8158}}

In chrome 12.0.742.91, I get these errors:

Code:
ticker.php: -1Resource interpreted as Script but transferred with MIME type text/html.
ticker.php: 1Uncaught SyntaxError: Unexpected token :
Jump to: