-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdegironode.js
143 lines (83 loc) · 3.07 KB
/
degironode.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//node js
const DeGiro = require('degiro');
var app = require("express")();
var bodyParser = require("body-parser");
//Set view engine to ejs
app.set("view engine", "ejs");
//Tell Express where we keep our index.ejs
app.set("views", __dirname + "/views");
//Use body-parser
app.use(bodyParser.urlencoded({ extended: false }));
//Instead of sending Hello World, we render index.ejs
var user = "Ralph";
app.listen(8080, () => { console.log("Server online on http://localhost:8080"); });
var arraynumbers = [];
var arrayprices = [];
var arrayarray = [];
var arraynames = [];
var arrayvalues = [];
var arrayquantity = [];
var arrayinleg = [];
clear();
//setInterval(clear, 60000);
function clear()
{
//empty values before fetching them again via the DeGiro API
arraynumbers = [];
arrayprices = [];
arrayarray = [];
arraynames = [];
arrayvalues = [];
arrayquantity = [];
arrayinleg = [];
arraywinst = [];
d = [];
totaleinleg = [];
//only fetch when the values are empty to make sure no double arrays are displayed
if (arrayarray = [])
{
Giro();
}
}
function Giro(){
(async () => {const degiro = DeGiro.create({username: 'username', password: 'password'});
await degiro.login();
obj = JSON.stringify(await degiro.getPortfolio());
jsonData = JSON.parse(obj);
for (var i = 0; i < jsonData.portfolio.length; i++) {
portfoliodata = jsonData.portfolio[i];
portfolionummers = jsonData.portfolio[i].id;
var portfolionameoutput1 = await degiro.getProductsByIds(portfolionummers);
var naamproducten = portfolionameoutput1.data[portfolionummers].name;
portfoliohoeveelheid = portfoliodata.value[2].value;
portfolioprijzen = portfoliodata.value[3].value;
var portfoliovalues = portfoliodata.value[4].value;
portfoliowinst = portfoliodata.value[7].value;
//console.log(portfolionummers + " " + naamproducten + " " + portfoliovalues + " " + portfolioprijzen);
var array = [portfolionummers, naamproducten , portfoliovalues , portfolioprijzen];
arraynumbers.push(jsonData.portfolio[i].id);
arrayquantity.push(jsonData.portfolio[i].value[2].value);
arrayvalues.push(jsonData.portfolio[i].value[4].value);
arrayprices.push(jsonData.portfolio[i].value[3].value);
arrayinleg.push(Math.abs(jsonData.portfolio[i].value[6].value.EUR));
arraynames.push(portfolionameoutput1.data[portfolionummers].name);
arrayarray.push(array);
app.get("/", (req, res) => { res.render("index", { username: user, cart: arrayarray, prijzen: arrayprices, namen: arraynames, values: arrayvalues, datum: d, hoeveelheid: arrayquantity, inleg: arrayinleg }); });
}})()
console.log("data refresh!")
}
/*
function sum(input){
if (toString.call(input) !== "[object Array]")
return false;
var total = 0;
for(var i=0;i<input.length;i++)
{
if(isNaN(input[i])){
continue;
}
total += Number(input[i]);
}
return total;
}
*/