Skip to content

Instantly share code, notes, and snippets.

@murrekatt
Created May 6, 2013 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save murrekatt/5526153 to your computer and use it in GitHub Desktop.
Save murrekatt/5526153 to your computer and use it in GitHub Desktop.
Simple example to test MtGox Streaming API in the browser.
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;
}
<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