#!/bin/bash # current dir dir="$(dirname $(realpath $0))" # get files wallet="${dir}/wallet.json" template="${dir}/template.html" # list tokens tokens=$(jq -r '.tokens | map(.token) | join(",")' $wallet) # fetch prices prices=$(curl "https://api.kucoin.com/api/v1/prices?base=USD¤cies=${tokens}" | \ jq '[.data | to_entries[] | {token: .key, price: .value} | .price |= tonumber]') # date stamp dts=$(echo -n "As of $(date '+%F %T %:::z')") # build portfolio 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]' \ <(echo "$portfolio")) # create rows readarray -t tokens < <(jq -c '.[]' <(echo $calc)) 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'); row=$(echo "${row}