diff --git a/dabo/functions/webpage.sh b/dabo/functions/webpage.sh index 26e84b9..1249bc6 100644 --- a/dabo/functions/webpage.sh +++ b/dabo/functions/webpage.sh @@ -1,5 +1,25 @@ + +function genchart { + local lastmark=0 + local mark="" + local file="$1" + local highest=$(sort -n "${file}" | tail -n1 | sed s/^-//) + local lowest=$(sort -n "${file}" | head -n1 | sed s/^-//) + local divideby=$(echo "$highest+$lowest" | bc -l) + local color="green" + tail -n1 "${file}" | grep -q "^-" && color="red" + + echo "
+" + for mark in $(cat "${file}") + do + echo "" + lastmark=${mark} + done + echo "
$file
${mark} %
" +} + function webpage { - g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" # create status webpage @@ -7,7 +27,8 @@ function webpage { -' >../index.html.tmp + +' >../index.html.tmp echo "Dabo! on ${STOCK_EXCHANGE} - ${URL} " >>../index.html.tmp echo "

State of Dabo-Bot! on ${STOCK_EXCHANGE} - ${URL} (ReadOnly)

@@ -143,13 +164,15 @@ function webpage { ${CURRENCY} Quantity ${CURRENCY} Price Commission - Comment" >>../index.html.tmp + Comment + Chart" >>../index.html.tmp local f_trade_file for f_trade_file in $(ls -t trade-histories/trade-*-open.history.csv 2>/dev/null) do local tradeline=$(tail -n1 ${f_trade_file}) local asset=$(echo ${f_trade_file} | cut -d. -f3 | cut -d- -f1) + local interimfile=$(echo ${f_trade_file} | sed 's/open\.history\.csv/interim\.history\.csv/') echo "$(echo ${tradeline} | cut -d, -f1) ${asset} 🔗 $(echo ${tradeline} | cut -d, -f2) @@ -157,6 +180,9 @@ function webpage { $(echo ${tradeline} | cut -d, -f5) $(echo ${tradeline} | cut -d, -f6) $(echo ${tradeline} | cut -d, -f7,8,9,10,11,12,13,14,15) + " >>../index.html.tmp + genchart "$interimfile" >>../index.html.tmp + echo " " >>../index.html.tmp done echo "" >>../index.html.tmp @@ -170,7 +196,8 @@ function webpage { ${CURRENCY} Quantity ${CURRENCY} Price (result) Commission - Comment" >>../index.html.tmp + Comment + Chart" >>../index.html.tmp for f_trade_file in $(ls -t trade-histories/trade-*-closed.history.csv 2>/dev/null | head -n 50) do @@ -198,6 +225,7 @@ function webpage { fi fi local asset=$(echo ${f_trade_file} | cut -d. -f3 | cut -d- -f1) + interimfile=$(echo ${f_trade_file} | sed 's/closed\.history\.csv/interim\.history\.csv/') echo "$(echo ${tradeline} | cut -d, -f1) ${asset} 🔗 ${f_action} @@ -205,6 +233,9 @@ function webpage { ${f_price} $(echo ${tradeline} | cut -d, -f6) $(echo ${tradeline} | cut -d, -f7,8,9,10,11,12,13,14,15) + ">>../index.html.tmp + echo ${f_action} | grep -q sell && genchart "$interimfile" >>../index.html.tmp + echo " " >>../index.html.tmp done done @@ -212,48 +243,6 @@ function webpage { -# echo "" >>../index.html.tmp -# echo " -# -# -# -# -# -# " >>../index.html.tmp -# grep ^20 trade-histories/*history.csv | sed 's/\// /; s/\./ /; s/:/ /; s/,/ /g' | sort -r -k3 >${g_tmp}/trade-hist-complete -# local tradeline -# cat ${g_tmp}/trade-hist-complete | while read tradeline -# do -# # use array trade -# local trade=($tradeline) -# local f_trace_price=${trade[8]} -# if [ ${trade[4]} = "sell" ] -# then -# local f_trade_date=${trade[3]} -# local f_trade_currency=${trade[1]} -# local f_trade_sell_for=${trade[6]} -# local f_trade_buy_for=$(grep -B1 "^${f_trade_date},sell," "trade-histories/${f_trade_currency}.history.csv" | grep -i ",buy," | cut -d, -f4 | cut -d" " -f1) -# local f_result=$(echo "scale=2; ${f_trade_sell_for}-$f_trade_buy_for" | bc -l | sed 's/^\./0./; s/^-\./-0./' | xargs printf "%.2f") -# local f_result_percentage=$(g_percentage-diff $f_trade_buy_for ${f_trade_sell_for}) -# f_trace_price="$f_trace_price ($f_result( ${f_result_percentage}%))" -# #echo "${trade[1]} $f_trade_buy_for -- ${f_trade_sell_for} == $f_result(${f_result_percentage}%)" -# fi -# echo " -# -# -# -# -# -# -# " >>../index.html.tmp -# -# done -# echo "
DateAssetAction${CURRENCY} Quantity${CURRENCY} Price (profit/loss)CommissionComment
${trade[3]}${trade[1]} 🔗${trade[4]}${trade[6]}${f_trace_price}${trade[9]} ${trade[10]}${trade[@]:11:30}
" >>../index.html.tmp - - - - - echo "

Current config

" >>../index.html.tmp echo "
$(cat ../../dabo-bot.conf | perl -pe 's/\/>/g;')
" >>../index.html.tmp