-
Notifications
You must be signed in to change notification settings - Fork 2
/
spk_aggregate.js
44 lines (27 loc) · 1020 Bytes
/
spk_aggregate.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
const orders = require("./orders.json")
const ordersStripe = require("./orders_stripe.json");
const fetch = require("node-fetch");
const combined = {};
async function getHBDPrice() {
return (await fetch("https://min-api.cryptocompare.com/data/price?fsym=HBD&tsyms=USD")).json()
}
getHBDPrice().then(price => {
for (const order of orders) {
let user = combined[order.userId] || {userId: order.userId, total: 0};
user.total += order.usd_value;
combined[order.userId] = user;
}
for (const order of ordersStripe) {
let user = combined[order.userId] || {userId: order.userId, total: 0};
user.total += order.usd_value;
combined[order.userId] = user;
}
let totalHBD = 0;
for (const user of Object.keys(combined)) {
combined[user].totalHBD = (combined[user].total / price.USD) * 1.10;
totalHBD += combined[user].totalHBD;
}
require("fs").writeFileSync("spk_total.json", JSON.stringify(combined, null, true))
console.table(combined)
console.log(totalHBD)
})