Last active
December 16, 2015 06:49
-
-
Save AndyMoreland/5394654 to your computer and use it in GitHub Desktop.
Expects socket.io-client, mongodb and ws to be installed with npm.
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
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