Created
May 12, 2015 01:07
-
-
Save julianeon/2b4b0ebc45bb08251d30 to your computer and use it in GitHub Desktop.
To subscribe to Bitstamp's activity.
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 moment= require('moment'); | |
var ws = new WebSocket('wss://s1.ripple.com:443/'); | |
var bitstamp = "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"; | |
var account = bitstamp; | |
var info_subscribe={ | |
command: "subscribe", | |
accounts: [bitstamp] | |
}; | |
ws.on('open', function() { | |
ws.send(JSON.stringify(info_subscribe)); | |
}); | |
ws.on('message', function(data, flags) { | |
//console.log(flags); | |
//console.log(data); | |
var mom=moment().format('HH:mm:ss'); | |
console.log(mom); | |
words=JSON.parse(data); | |
//console.log(words["engine_result"]); | |
//console.log(words["ledger_hash"]); | |
//console.log(words["transaction"]["hash"]); | |
// | |
var tx=words["transaction"]; | |
if (tx) { | |
var results=tx["hash"]; | |
var taker=tx["TakerGets"] | |
//console.log(results); | |
//console.log(taker); | |
if (taker) { | |
console.log(taker); | |
var curr=taker["currency"]; | |
var val=taker["value"]; | |
var longval=JSON.stringify(val); | |
var line=curr + ' ' + longval; | |
console.log(line); | |
} | |
} | |
// flags.binary will be set if a binary data is received | |
// flags.masked will be set if the data was masked | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment