-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
158 lines (135 loc) · 5.28 KB
/
index.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
//read config and function
if (!is_file('config.php')) {
die('fatal error: config.php not exist');
}
require_once 'config.php';
require_once 'function.php';
//connect to poloniex.com
require_once 'Libs/poloniex.php';
$poloniex = new Poloniex($key, $api_secret);
//loading deposits
//loading value
$ticker = $poloniex->get_ticker();
$btc = $ticker["USDT_BTC"]["last"];
$balanceAll = $poloniex->get_balances();
$balance = $balanceAll["BTC"];
if($czechCurrencyConversion) {
$czechCurrency = checkCurrency('USD');
}
//loading lendings
$lendingHistory = $poloniex->get_lending_history();
//echo '<pre>'; print_r($lendingHistory);
//echo('<pre>'); print_r($poloniex->get_balances());
//data processing
$lendingsSuma = 0;
$lendingsDay = array();
$lendingsMonth = array();
$lendingsYear = array();
foreach ($lendingHistory AS $oneLending) {
if ($oneLending["currency"] == "BTC") {
$day = date('Y-m-d', strtotime($oneLending["close"]));
$month = date('Y-m', strtotime($oneLending["close"]));
$year = date('Y', strtotime($oneLending["close"]));
if (isset($lendingsDay[$day])) {
$lendingsDay[$day] += convertBtcToSatoshi($oneLending["earned"]);
} else {
$lendingsDay[$day] = convertBtcToSatoshi($oneLending["earned"]);
}
if (isset($lendingsMonth[$month])) {
$lendingsMonth[$month] += convertBtcToSatoshi($oneLending["earned"]);
} else {
$lendingsMonth[$month] = convertBtcToSatoshi($oneLending["earned"]);
}
if (isset($lendingsYear[$year])) {
$lendingsYear[$year] += convertBtcToSatoshi($oneLending["earned"]);
} else {
$lendingsYear[$year] = convertBtcToSatoshi($oneLending["earned"]);
}
$lendingsSuma += convertBtcToSatoshi($oneLending["earned"]);
}
}
//email template
$template = '<html><head><title>Poloniex: lending report</title></head><body><div id="mail">';
$template .= 'Work in progress, sorry<hr />';
$template .= '<h1>Poloniex: lending report</h1>';
$template .= 'Balance: ' . printBTC(convertBtcToSatoshi($balance)) . ' BTC, ~' .printDolar($balance*$btc) .'$<br />';
$template .= templateStyle();
//day
$countDay = min($lastDay, count($lendingsDay));
if ($countDay > 0) {
$template .= '<h2>last ' . $countDay . ' day(s)</h2>';
$template .= '<table><tr>';
$template .= '<th class="date">date</th><th>BTC</th><th>USD (today\'s rate)</th>';
if($czechCurrency) {
$template .= '<th>CZK (today\'s rate)</th>';
}
$template .= '</tr>';
$i = 0;
foreach ($lendingsDay AS $date => $oneLending) {
$template .= '<tr>';
$template .= '
<td>' . date($formatDateDay, strtotime($date)) . '</td>
<td>' . printBTC($oneLending) . ' BTC</td>
<td>~' .printDolar(convertSatoshiToBtc($oneLending)*$btc) .'$</td>';
if($czechCurrency) {
$template .= '<td>' .printDolar(convertSatoshiToBtc($oneLending)*$btc*$czechCurrency) .',-</td>';
}
$template .= '</tr>';
$i++;
if ($i >= $countDay) break;
}
$template .= '</table>';
}
//month
if (count($lendingsMonth) > 0) {
$template .= '<h2>last ' . count($lendingsMonth) . ' month(s)</h2>';
$template .= '<table><tr><th class="date">date</th><th>BTC</th><th>USD (today\'s rate)</th>';
if($czechCurrency) {
$template .= '<th>CZK (today\'s rate)</th>';
}
$template .= '</tr>';
foreach ($lendingsMonth AS $date => $oneLending) {
$template .= '<tr><td>' . date($formatDateMonth, strtotime($date .'-01')) . '</td><td>' . printBTC($oneLending) . ' BTC</td><td>~' .printDolar(convertSatoshiToBtc($oneLending)*$btc) .'$</td>';
if($czechCurrency) {
$template .= '<td>' .printDolar(convertSatoshiToBtc($oneLending)*$btc*$czechCurrency) .',-</td>';
}
$template .= '</tr>';
}
$template .= '</table>';
}
//year
if (count($lendingsYear) > 0) {
$template .= '<h2>last ' . count($lendingsYear) . ' year(s)</h2>';
$template .= '<table><tr><th class="date">date</th><th>BTC</th><th>USD (today\'s rate)</th>';
if($czechCurrency) {
$template .= '<th>CZK (today\'s rate)</th>';
}
$template .= '</tr>';
foreach ($lendingsYear AS $date => $oneLending) {
$template .= '<tr><td>' . date("Y", strtotime($date .'-01-01')) . '</td><td>' . printBTC($oneLending) . ' BTC</td><td>~' .printDolar(convertSatoshiToBtc($oneLending)*$btc) .'$</td>';
if($czechCurrency) {
$template .= '<td>' .printDolar(convertSatoshiToBtc($oneLending)*$btc*$czechCurrency) .',-</td>';
}
$template .= '</tr>';
}
$template .= '</table>';
}
if (count($lendingsYear) > 1) {
$template .= '<h2>Lending sum</h2>';
$template .= '<table><tr><th class="date">date</th><th>BTC</th><th>USD (today\'s rate)</th>';
if($czechCurrency) {
$template .= '<th>CZK (today\'s rate)</th>';
}
$template .= '</tr>';
$template .= '<tr><td>sum</td><td>' . printBTC($lendingsSuma) . '</td><td>-</td>';
if($czechCurrency) {
$template .= '<td>' .printDolar(convertSatoshiToBtc($oneLending)*$btc*$czechCurrency) .',-</td>';
}
$template .= '</tr>';
$template .= '</table>';
}
$template .= '</div></body>';
//sending or printing
//WIP - only printing
echo $template;