Created
May 6, 2013 16:17
Simple example to test MtGox Streaming API in the browser.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
div#status { | |
padding-bottom: 1em; | |
} | |
div#log { | |
word-wrap: break-word; | |
padding-bottom: 1em; | |
} | |
.notice { | |
color: #00FF33; | |
font-weight: bold; | |
} | |
.error { | |
color: #FF0000; | |
font-weight: bold; | |
} | |
.message { | |
font-size: smaller; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<link href="mtgox.css" type="text/css" rel="stylesheet" /> | |
</head> | |
<body> | |
<h2>MtGox Streaming API</h2> | |
<div id="status"> | |
</div> | |
<div id="log"> | |
</div> | |
<script src="https://socketio.mtgox.com/socket.io/socket.io.js"></script> | |
<script> | |
var uri = 'ws://socketio.mtgox.com/mtgox'; | |
var conn = io.connect(uri); | |
conn.on('connect', function() { | |
var e = document.getElementById('status'); | |
e.innerHTML = e.innerHTML + '<div class="notice">Connected to ' + uri + '</div>'; | |
}); | |
conn.on('message', function(data) { | |
var e = document.getElementById('log'); | |
e.innerHTML = e.innerHTML + '<div class="message">' + JSON.stringify(data) + '</div>'; | |
}); | |
conn.on('error', function(data) { | |
var e = document.getElementById('status'); | |
e.innerHTML = e.innerHTML + '<div class="error">ERROR: ' + data + '</div>'; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment