Skip to content

Instantly share code, notes, and snippets.

@AndyMoreland
Last active December 16, 2015 06:49
Show Gist options
  • Save AndyMoreland/5394654 to your computer and use it in GitHub Desktop.
Save AndyMoreland/5394654 to your computer and use it in GitHub Desktop.
Expects socket.io-client, mongodb and ws to be installed with npm.
var WebSocket = require('ws')
var io = require('socket.io-client');
var MongoClient = require('mongodb').MongoClient;
console.log("Building websocket");
ws = io.connect('https://socketio.mtgox.com/mtgox')
console.log(ws);
ws.on('open', function () {
console.log("opened");
});
ws.on('error', function (data) {
console.log(data);
})
ws.on('connect', function (data) {
console.log('connected')
});
var data_collection;
MongoClient.connect("mongodb://127.0.0.1:27017/mtgox", function (err, db) {
console.log("connected to mongodb");
console.log(err);
data_collection = db.collection('mtgox_ticker');
});
ws.on('message', function (message) {
if (data_collection)
data_collection.insert(message, function (err, docs) {});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment