function watch_assets { local f_watch_assets_array local f_line local f_price local f_alert local f_alert_html="

Alerts when values are crossed

" local f_portfolio_html="

Portfolio

" local f_last_price local f_html="Dabo WATCH ASSETS - ${URL}

Dabo-Bot WATCH ASSETS - ${URL} (ReadOnly)

Last update $(date '+%F %T')

" .watch_assets.sh.swp return 0 mapfile -t f_watch_assets_array < <(egrep -v '^ASSET,ALERTS,BUYPRICE,BUYDATE,BUYQUANTITY,SELLPRICE,SELLDATE,SELLQUANTITY|^#|^$|^ +$' /dabo/watch-assets.csv) for f_line in "${f_watch_assets_array[@]}" do g_echo "$f_line" readarray -d "," -t f_line_array < <(echo -n "0,${f_line}") local f_asset=${f_line_array[1]} local f_alerts=${f_line_array[2]} local f_buyprice=${f_line_array[3]} local f_buydate=${f_line_array[4]} local f_buyquantity=${f_line_array[5]} local f_sellprice=${f_line_array[6]} local f_selldate=${f_line_array[7]} local f_sellquantity=${f_line_array[8]} local f_comment=${f_line_array[9]} local f_currency=${f_line_array[10]} [[ ${f_currency} =~ ^usd ]] && local f_currency_symbol="$" [[ ${f_currency} =~ ^eur ]] && local f_currency_symbol="€" # get current asset price and last price f_price="" if [[ ${f_asset} =~ ^https ]] || [[ ${f_asset} =~ " " ]] then # get asset price from get_marketdata_from_url get_marketdata_from_url ${f_asset} f_price=${f_get_marketdata_price} ### 2do USD->EUR Umrechnugn wenn f_currency=eur readarray -d " " -t f_asset_array < <(echo -n "${f_asset}") f_asset=${f_asset_array[1]} else # get token price from coingecko f_price=$(jq -r ".[] |select(.symbol==\"${f_asset}\")|\"\\(.current_price)\"" COINGECKO_GET_ASSETS_${f_currency}_CMD_OUT) fi [ -s WATCH_ASSETS_${f_asset}_${f_currency}_LAST_PRICE ] && read f_last_price < <(cat WATCH_ASSETS_${f_asset}_${f_currency}_LAST_PRICE) echo ${f_price} >WATCH_ASSETS_${f_asset}_${f_currency}_LAST_PRICE echo g_num_valid_number ${f_price} ${f_last_price} #|| continue # Notify on alert readarray -d "|" -t f_alerts_array < <(echo -n "${f_alerts}") for f_alert in "${f_alerts_array[@]}" do f_alert_html+="" if g_num_is_higher ${f_price} ${f_alert} && g_num_is_lower_equal ${f_last_price} ${f_alert} then g_signal-notify "${f_asset} Price ${f_price} switched over ${f_alert}! Comment: ${f_comment}" fi if g_num_is_lower ${f_price} ${f_alert} && g_num_is_higher_equal ${f_last_price} ${f_alert} then g_signal-notify "${f_asset} Price ${f_price} switched under ${f_alert}! Comment: ${f_comment}" fi done # List portfolio if [ -n "${f_buyprice}" ] then g_calc "${f_buyprice}*${f_buyquantity}" f_buyquantity_price=${g_calc_result} g_percentage-diff ${f_buyprice} ${f_price} local f_portfolio_html+="" fi done f_alert_html+="
${f_asset}${f_alert}
${f_asset} (${f_comment})${f_buyquantity_price}${f_currency_symbol} (${f_buyprice}${f_currency_symbol})${f_price}${f_currency_symbol} ${g_percentage_diff_result}%
" f_portfolio_html+="" echo ${f_html} ${f_portfolio_html} ${f_alert_html} | perl -pe 's/ (\-[0-9]+\.[0-9]+\%)/$1<\/font>/g; s/ ([0-9]+\.[0-9]+\%)/$1<\/font>/g;' >../watch.html }