-
Notifications
You must be signed in to change notification settings - Fork 10
/
functions-display.php
117 lines (91 loc) · 3.82 KB
/
functions-display.php
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
<?php
// Function to build the table for a singular source, e.g.'paper', 'binance' or 'bitfinex'
// $array is an array with the data, which needs to be properly set up first to match the headers
function build_table($array,$fiat = "dollar",$fiatExchangeDataUSD = "1") {
// Start the table
$html = '<table>';
// Add the header row, predefined for prettier headers than array keys
$html .= '<thead>';
$html .= '<tr class= "header green">';
$html .= '<th class="name">' .'Coin Name' . '</th>';
$html .= '<th>' .'Buyin<br>Price' . '</th>';
$html .= '<th>' .'Price' . '</td>';
$html .= '<th>' .'Change<br>1hour' . '</th>';
$html .= '<th>' .'Change<br>24hours' . '</th>';
$html .= '<th>' .'Change<br>7days' . '</th>';
$html .= '<th>' .'Profit' . '</th>';
$html .= '<th>' .'Profit %' . '</th>';
$html .= '<th>' .'Exit<br>Profit' . '</th>';
$html .= '<th>' .'Exit<br>Profit %' . '</th>';
$html .= '</tr>';
$html .= '</thead>';
// Add the content row of the table with a loop depending on the array's content
$html .= '<tbody>';
foreach($array as $key=>$value) {
$html .= '<tr class= "row">';
foreach($value as $key2=>$value2){
if ($key2 === array_key_first($array["$key"])) {
$html .= '<td class="name">' . "$value2" . '</td>';
}
else {
if(strpos($key2,"percent") !== false) {
$html .= '<td class="value">' . number_format($value2, 2, '.', ',') . ' %' . '</td>';
}
else {
if ($fiat == "euro") {
$html .= '<td class="value">' . '€ ' . number_format(($value2*$fiatExchangeDataUSD), 2, '.', ',') . '</td>';
}
else {
$html .= '<td class="value">' . '$ ' . number_format($value2, 2, '.', ',') . '</td>';
}
}
}
}
$html .= '</tr>';
}
$html .= '</tbody>';
// Finish the table and return it
$html .= '</table>';
return $html;
}
// Function to build the summary table for an overview of all sources e.g.'paper', 'binance' or 'bitfinex'
// $array is an array with the data, which needs to be properly set up first to match the headers
function build_table_summary($array,$fiat = "dollar",$fiatExchangeDataUSD = "1") {
// Start the table
$html = '<table>';
// Add the header row, predefined for prettier headers than array keys
$html .= '<tr class= "header green">';
$html .= '<th>' .'Type' . '</th>';
$html .= '<th>' .'Profit' . '</th>';
$html .= '<th>' .'Profit %' . '</th>';
$html .= '<th>' .'Exit Profit' . '</th>';
$html .= '<th>' .'Exit Profit %' . '</th>';
$html .= '</tr>';
// Add the content row of the table with a loop depending on the array's content
foreach( $array as $key=>$value){
$html .= '<tr class= "row">';
foreach($value as $key2=>$value2){
if ($key2 === array_key_first($array["$key"])) {
$html .= '<td class="name">' . "$value2" . '</td>';
}
else {
if(strpos($key2,"percent") !== false) {
$html .= '<td class="value">' . number_format($value2, 2, '.', ',') . ' %' . '</td>';
}
else {
if ($fiat == "euro") {
$html .= '<td class="value">' . '€ ' . number_format(($value2*$fiatExchangeDataUSD), 2, '.', ',') . '</td>';
}
else {
$html .= '<td class="value">' . '$ ' . number_format($value2, 2, '.', ',') . '</td>';
}
}
}
}
$html .= '</tr>';
}
// Finish the table and return it
$html .= '</table>';
return $html;
}
?>