Created
May 30, 2017 11:42
-
-
Save christiannwamba/a40d1dd4fe818f887aada2d8258a66b9 to your computer and use it in GitHub Desktop.
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 ds = require('deepstream.io-client-js') | |
var data = require('./data.json'); | |
var client = ds('APP-URL').login() | |
client.rpc.provide( 'price-chart', ( request, response ) => { | |
console.log(data); | |
response.send( formattedData( data.bpi ) ); | |
}); | |
var curPrice = client.record.getRecord('BTC/price'); | |
curPrice.whenReady((record) => { | |
setInterval(() => { | |
var price = 1200 * (0.99 + Math.random() / 10) | |
console.log('setting...') | |
record.set('price', price, (err) => { | |
if (err) { | |
console.log(err) | |
return | |
} | |
console.log('Set price to', price) | |
}) | |
}, getRandom(1000, 3000)) | |
}) | |
function getRandom(min, max) { | |
min = Math.ceil(min); | |
max = Math.floor(max); | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
function formattedData(data) { | |
var nArray = []; | |
var iArray = Object.keys(data); | |
iArray.forEach(x => { | |
var nObject = {y: data[x]} | |
nArray.push(nObject) | |
}) | |
return nArray; | |
} | |
console.log('Running') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment