-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (31 loc) · 1.13 KB
/
index.js
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
var express = require("express");
var avanza = require("./avanza.js");
var metrics = {};
var app = express();
app.get('/metrics', function (req, res) {
var ret = '';
for (var code in metrics) {
if (!metrics.hasOwnProperty(code)) continue;
var opt = 'exchange="avanza",code="'+metrics[code].code+'",name="'+metrics[code].name+'"';
if (metrics[code].type) {
opt = opt + ',type="'+metrics[code].type+'"';
}
if (metrics[code].account) {
opt = opt + ',account="'+metrics[code].account+'"';
}
for (var type in metrics[code]) {
if (!metrics[code].hasOwnProperty(type)) continue;
if (type == "name" || type == "type" || type == "account" || type == "code") continue;
var name = 'stock_'+type;
ret = ret + name + "{" + opt + "} " + metrics[code][type] + "\n";
}
}
res.setHeader('Content-Type', 'text/plain');
res.send(ret)
});
app.listen(8582, function () {
console.log('Listening on port 8582')
});
avanza(process.env.EXCH_AZ_USERNAME, process.env.EXCH_AZ_PASSWORD, function (m) {
metrics = m;
});