Compare commits
No commits in common. "95ec066e853d98a87c687d6277f7bfa20e6c4b25" and "1d34619e7e1e2e8b179bfc7acaf7a06023fa4c8c" have entirely different histories.
95ec066e85
...
1d34619e7e
2 changed files with 57 additions and 133 deletions
53
portfolio.sh
53
portfolio.sh
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
# current dir
|
||||
dir="$(dirname "$(realpath "$0")")"
|
||||
dir="$(dirname $(realpath $0))"
|
||||
|
||||
# get files
|
||||
wallet="${dir}/wallet.json"
|
||||
|
@ -22,10 +22,7 @@ portfolio=$(jq -s '[ .[0] + .[1] | group_by(.token)[] | add ]' \
|
|||
<(echo "$(jq '.tokens' $wallet)") <(echo "$prices"))
|
||||
|
||||
# calculate value
|
||||
calc=$(jq '[.[]
|
||||
| .["value"] = .balance * .price
|
||||
| .["margin"] = .value - .investment
|
||||
| .["movement"] = .margin / .investment]' \
|
||||
calc=$(jq '[.[] | .["value"] = .balance * .price | .["margin"] = .value - .investment | .["movement"] = .margin / .investment]' \
|
||||
<(echo "$portfolio"))
|
||||
|
||||
# create rows
|
||||
|
@ -35,29 +32,13 @@ for t in "${tokens[@]}"; do
|
|||
tok=$(echo $t | jq '.token' | tr -d '"');
|
||||
bal=$(echo $t | jq '.balance|tonumber');
|
||||
prc=$(echo $t | jq '.price|tonumber');
|
||||
inv=$(echo $t | jq '.investment|tonumber');
|
||||
val=$(echo $t | jq '.value|tonumber');
|
||||
mar=$(echo $t | jq '.margin|tonumber');
|
||||
mov=$(echo $t | jq '.movement|tonumber');
|
||||
|
||||
if [[ -n "$prc" ]]; then
|
||||
inv=$(echo $t | jq '.investment|tonumber');
|
||||
val=$(echo $t | jq '.value|tonumber');
|
||||
mar=$(echo $t | jq '.margin|tonumber');
|
||||
mov=$(echo $t | jq '.movement|tonumber');
|
||||
else
|
||||
read -r inv val mar mov <<<$(echo 0 0 0 0);
|
||||
fi
|
||||
|
||||
row=$(
|
||||
echo "${row}<tr><td class=\"left\">${tok}</td><td>${bal}</td><td>" \
|
||||
$(printf "$%.2f\n" $prc)"</td><td>" \
|
||||
$(printf "$%.2f\n" $inv)"</td><td>" \
|
||||
$(printf "$%.2f\n" $val)"</td><td>" \
|
||||
$(printf "$%.2f\n" $mar)"</td><td>" \
|
||||
$(printf "%.3f\n" $mov)"</td></tr>" \
|
||||
);
|
||||
csv=$(
|
||||
echo "${csv}"\
|
||||
$(echo -n $(date +"['"%F"','"%T"','"%:::z"'")) \
|
||||
",'${tok}','${bal}','${prc}','${inv}','${val}','${mar}','${mov}']" \
|
||||
);
|
||||
row=$(echo "${row}<tr><td class=\"left\">${tok}</td><td>${bal}</td><td>"$(printf "$%.2f\n" $prc)"</td><td>"$(printf "$%.2f\n" $inv)"</td><td>"$(printf "$%.2f\n" $val)"</td><td>"$(printf "$%.2f\n" $mar)"</td><td>"$(printf "%.3f\n" $mov)"</td></tr>");
|
||||
csv=$(echo "${csv}"$(echo -n $(date +",['"%F"','"%T"','"%:::z"'"))",'${tok}','${bal}','${prc}','${inv}','${val}','${mar}','${mov}']");
|
||||
|
||||
# Sum up
|
||||
tot_inv=$(echo "${tot_inv:-0}+$inv" | bc);
|
||||
|
@ -67,31 +48,21 @@ for t in "${tokens[@]}"; do
|
|||
done
|
||||
|
||||
# format array
|
||||
csv=$(echo $csv | sed 's|\] \[|\],\[|g')
|
||||
csv=$(echo $csv | sed 's|^,||g')
|
||||
|
||||
# calculate movement
|
||||
tot_mov=$(echo "scale=3 ; $tot_mar / $tot_inv" | bc)
|
||||
|
||||
# fill template
|
||||
page=$(cat $template | \
|
||||
sed "s|%row%|$row|g" | \
|
||||
sed "s|%inv%|"$(printf "$%.2f\n" $tot_inv)"|g" | \
|
||||
sed "s|%val%|"$(printf "$%.2f\n" $tot_val)"|g" | \
|
||||
sed "s|%mar%|"$(printf "$%.2f\n" $tot_mar)"|g" | \
|
||||
sed "s|%mov%|"$(printf "%.4f\n" $tot_mov)"|g" | \
|
||||
sed "s|%dts%|$dts|g" | \
|
||||
sed "s|%csv_data%|$csv|g" | \
|
||||
sed "s|%dts_fln%|"$(echo -n $(date '+%F_%T%:::z'))"|g")
|
||||
page=$(cat $template | sed "s|%row%|$row|g;s|%inv%|"$(printf "$%.2f\n" $tot_inv)"|g;s|%val%|"$(printf "$%.2f\n" $tot_val)"|g;s|%mar%|"$(printf "$%.2f\n" $tot_mar)"|g;s|%mov%|"$(printf "%.4f\n" $tot_mov)"|g;s|%dts%|$dts|g;s|%csv_data%|$csv|g;s|%dts_fln%|"$(echo -n $(date '+%F_%T%:::z'))"|g")
|
||||
|
||||
# encode link
|
||||
itty=$(echo -n $page | lzma -9 | base64 -w0 | xargs -0 printf "https://itty.bitty.site/#Portfolio/%s\n")
|
||||
|
||||
# get ntfy
|
||||
# send signal
|
||||
ntfy=$(jq -r '.ntfy | "\(.server)/\(.topic)"' $wallet)
|
||||
|
||||
# send report
|
||||
curl \
|
||||
-H "title: Portfolio Update" \
|
||||
-H "tags: coin" \
|
||||
-H "click: ${itty}" \
|
||||
-H "tags: coin" -H "click: ${itty}" \
|
||||
-d "Click Here" $ntfy
|
||||
|
|
137
template.html
137
template.html
|
@ -1,107 +1,60 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Crypto Portfolio</title>
|
||||
<style>
|
||||
table.crypto {
|
||||
font-family: "Lucida Console", Monaco, monospace;
|
||||
border: 2px solid #4F7849;
|
||||
background-color: #EEEEEE;
|
||||
width: 100%;
|
||||
text-align: right;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
table.crypto td, table.crypto th {
|
||||
border: 1px solid #4F7849;
|
||||
padding: 2px 2px;
|
||||
}
|
||||
table.crypto tbody td {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
color: #4F7849;
|
||||
}
|
||||
table.crypto tr:nth-child(even) {
|
||||
background: #CEE0CC;
|
||||
}
|
||||
table.crypto thead {
|
||||
background: #4F7849;
|
||||
}
|
||||
table.crypto thead th {
|
||||
font-size: 18px;
|
||||
color: #FFFFFF;
|
||||
text-align: center;
|
||||
}
|
||||
table.crypto tfoot {
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
color: #FFFFFF;
|
||||
background: #4F7849;
|
||||
background: -moz-linear-gradient(top, #7b9a76 0%, #60855b 66%, #4F7849 100%);
|
||||
background: -webkit-linear-gradient(top, #7b9a76 0%, #60855b 66%, #4F7849 100%);
|
||||
background: linear-gradient(to bottom, #7b9a76 0%, #60855b 66%, #4F7849 100%);
|
||||
border-top: 4px solid #444444;
|
||||
}
|
||||
table.crypto tfoot td {
|
||||
font-size: 20px;
|
||||
}
|
||||
td.left {
|
||||
text-align: left;
|
||||
}
|
||||
</style>
|
||||
<title>Crypto Portfolio</title>
|
||||
<style>
|
||||
table {
|
||||
border-style: solid;
|
||||
border-width: 3px;
|
||||
}
|
||||
|
||||
td, th {
|
||||
border-style: solid;
|
||||
border-width: 2px;
|
||||
}
|
||||
td {
|
||||
text-align: right;
|
||||
}
|
||||
td.left {
|
||||
text-align: left;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table class="crypto">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Token</th>
|
||||
<th>Balance</th>
|
||||
<th>Price</th>
|
||||
<th>Investment</th>
|
||||
<th>Value</th>
|
||||
<th>Margin</th>
|
||||
<th>Movement</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
%row%
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td class="left">Total</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>%inv%</td>
|
||||
<td>%val%</td>
|
||||
<td>%mar%</td>
|
||||
<td>%mov%</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
<p><i>%dts%</i></p>
|
||||
<button onclick="download_csv_file()"> Download CSV </button>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Token</th><th>Balance</th><th>Price</th><th>Investment</th><th>Value</th><th>Margin</th><th>Movement</th>
|
||||
</tr>
|
||||
%row%
|
||||
<tr>
|
||||
<td class="left"><b>Total</b></td><td></td><td></td><td><b>%inv%</b></td><td><b>%val%</b></td><td><b>%mar%</b></td><td><b>%mov%</b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p><i>%dts%</i></p>
|
||||
<button onclick="download_csv_file()"> Download CSV </button>
|
||||
</body>
|
||||
<script>
|
||||
var csvFileData = [
|
||||
%csv_data%
|
||||
];
|
||||
var csvFileData = [
|
||||
%csv_data%
|
||||
];
|
||||
|
||||
function download_csv_file() {
|
||||
function download_csv_file() {
|
||||
|
||||
var csv = 'Date,Time,Zone,Token,Balance,Price,Investment,Value,Margin,Movement\n';
|
||||
var csv = 'Date,Time,Zone,Token,Balance,Price,Investment,Value,Margin,Movement\n';
|
||||
|
||||
csvFileData.forEach(function(row) {
|
||||
csv += row.join(',');
|
||||
csv += "\n";
|
||||
});
|
||||
csvFileData.forEach(function(row) {
|
||||
csv += row.join(',');
|
||||
csv += "\n";
|
||||
});
|
||||
|
||||
document.write(csv);
|
||||
document.write(csv);
|
||||
|
||||
var hiddenElement = document.createElement('a');
|
||||
hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(csv);
|
||||
hiddenElement.target = '_blank';
|
||||
var hiddenElement = document.createElement('a');
|
||||
hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(csv);
|
||||
hiddenElement.target = '_blank';
|
||||
|
||||
hiddenElement.download = 'CSV_Portfolio_%dts_fln%.csv';
|
||||
hiddenElement.click();
|
||||
}
|
||||
hiddenElement.download = 'CSV_Portfolio_%dts_fln%.csv';
|
||||
hiddenElement.click();
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue