-
Notifications
You must be signed in to change notification settings - Fork 2
/
crypto-report.html
135 lines (108 loc) · 4.23 KB
/
crypto-report.html
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
<html>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://unpkg.com/ag-grid-community/dist/ag-grid-community.min.js"></script>
<script src="https://dl.dropboxusercontent.com/s/zdxw5g0pycmrdvi/fills.js"></script>
<link rel="stylesheet" href="https://unpkg.com/ag-grid-community/dist/styles/ag-grid.css">
<link rel="stylesheet" href="https://unpkg.com/ag-grid-community/dist/styles/ag-theme-alpine.css">
<script>
//var csv is the CSV file with headers
function transformFills(fillsCsv){
var result = [];
var lines=fillsCsv.split("\n");
var headers=lines[0].split(",");
for(var i=1;i<lines.length;i++){
var obj = {};
var currentline=lines[i].split(",");
if(currentline.length == headers.length) {
for(var j=0;j<headers.length;j++){
obj[headers[j]] = currentline[j];
}
result.push(obj);
}
}
return result;
//return JSON.stringify(result);
}
function processFills(fillsArray) {
var result = {};
for(var fill of fillsArray) {
var product = result[fill["size unit"]] ??= {
"total-amount": 0.0,
"total-cost": 0.0,
"average-cost": 0.0,
};
if((/buy/i).test(fill["side"])) {
product["total-amount"] += +parseFloat(fill["size"]);
product["total-cost"] += +parseFloat(fill["size"]) * parseFloat(fill["price"]);
product["average-cost"] = +parseFloat(product["total-cost"] / product["total-amount"]);
}
}
for(var product in result) {
result[product]["total-amount"] = +parseFloat(result[product]["total-amount"]).toFixed(4);
result[product]["total-cost"] = +parseFloat(result[product]["total-cost"]).toFixed(parseFloat(result[product]["total-cost"]) < 1 ? 4 : 2);
result[product]["average-cost"] = +parseFloat(result[product]["average-cost"]).toFixed(parseFloat(result[product]["average-cost"]) < 1 ? 4 : 2);
}
return result;
}
function convertObjectToHeaders(object, propertyKey) {
var result = [];
var headers = {};
headers[propertyKey] = true;
for(var property in object) {
for(var header in object[property]) {
headers[header] = true;
}
}
for(var header in headers) {
result.push(
{ field: header }
);
}
return result;
}
function convertObjectToRows(object, propertyKey) {
var result = [];
for(var property in object) {
object[property][propertyKey] = property;
result.push(object[property]);
}
return result;
}
var fillsArray = [];
for(var source in fillsCsv) {
fillsArray = [...fillsArray, ...transformFills(fillsCsv[source])];
}
var processed = processFills(fillsArray);
// let the grid know which columns and what data to use
const gridOptions = {
columnDefs: convertObjectToHeaders(processed, "product-id"),
rowData: convertObjectToRows(processed, "product-id")
};
$(document).ready(()=>{
// lookup the container we want the Grid to use
const eGridDiv = document.querySelector('#myGrid');
// create the grid passing in the div to use together with the columns & data we want to use
new agGrid.Grid(eGridDiv, gridOptions);
$.ajax({
crossDomain: true,
url: "https://api.pro.coinbase.com/products/BTC-USD/stats",
method: "GET",
success: (data) => {
console.log(data);
},
error: (error) => {
console.log(error);
}
})
});
//document.write(JSON.stringify(processed));
/*
B=SUM(SUMIF(Coinbase!$G$2:$G, A2, Coinbase!$F$2:$F), SUMIF(AnchorUSD!$G$2:$G, A2, AnchorUSD!$F$2:$F), SUMIF(FixedFloat!$E$2:$E, A2, FixedFloat!$F$2:$F), SUMIF(FixedFloat!$I$2:$I, A2, FixedFloat!$J$2:$J))
G=SUM(SUMPRODUCT(Coinbase!$F$2:$F, Coinbase!$H$2:$H*(Coinbase!$G$2:$G=A2)*(Coinbase!$D$2:$D="BUY")),SUMPRODUCT(AnchorUSD!$F$2:$F, AnchorUSD!$H$2:$H*(AnchorUSD!$G$2:$G=A2)*(AnchorUSD!$D$2:$D="BUY")),SUMPRODUCT(FixedFloat!$F$2:$F, FixedFloat!$G$2:$G*(FixedFloat!$E$2:$E=A2)),-SUMPRODUCT(FixedFloat!$F$2:$F, FixedFloat!$G$2:$G*(FixedFloat!$I$2:$I=A2)))
AVG==IF(B>0, G/B, 0)
*/
</script>
<body style="background-color:#333333; color: #CCCCCC;">
<div id="myGrid" class="ag-theme-alpine"></div>
</body>
</html>