-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathstreaming.js
More file actions
50 lines (44 loc) · 1.11 KB
/
streaming.js
File metadata and controls
50 lines (44 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var app = require('http').createServer(handler);
var io = require('socket.io').listen(app);
var fs = require('fs');
var last;
var tick;
var https = require('https');
var options = {
host: 'stream-fxpractice.oanda.com',
// subscribe up to 10 instruments
// update accountId
path: '/v1/quote?accountId=<your account ID>&instruments=EUR_USD%2CUSD_CAD',
method: 'GET',
// update access token
headers: {"Authorization" : "Bearer <your access token>"},
};
var request = https.request(options, function(response){
response.on("data", function(chunk){
tick = chunk.toString();
});
response.on("end", function(){
console.log("Disconnected");
});
});
request.end();
app.listen(1337, '127.0.0.1');
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
};
io.sockets.on('connection', function (socket) {
setInterval(function(){
if (tick !== last) {
socket.emit('news', tick);
last = tick;
}
}, 0.001);
});