diff --git a/dabo/functions/webpage.sh b/dabo/functions/webpage.sh index cc21ad4..306977c 100644 --- a/dabo/functions/webpage.sh +++ b/dabo/functions/webpage.sh @@ -1,24 +1,4 @@ -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} $@" @@ -27,17 +7,18 @@ function webpage { [ -e ../charts.min.css ] || wget -q https://raw.githubusercontent.com/ChartsCSS/charts.css/main/dist/charts.min.css -O ../charts.min.css # create status webpage - echo ' - - - - -' >../index.html.tmp - echo "Dabo! on ${STOCK_EXCHANGE} - ${URL} -" >>../index.html.tmp - echo "

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

-

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

" >>../index.html.tmp - + echo " + + + + + + + Dabo! on ${STOCK_EXCHANGE} - ${URL} + + +

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

+

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

" >../index.html.tmp local f_SPOT_BALANCE=$(tail -n1 "asset-histories/BALANCESPOT${CURRENCY}.history.csv" | cut -d, -f2) local f_COMPLETE_BALANCE=$(tail -n1 "asset-histories/BALANCECOMPLETE${CURRENCY}.history.csv" | cut -d, -f2) @@ -103,7 +84,7 @@ function webpage { echo '

Open Trades (Invested Assets)

' >>../index.html.tmp - echo "" >>../index.html.tmp + echo "
" >>../index.html.tmp local line cat EXCHANGE_GET_BALANCES_CMD_OUT | grep -v ${CURRENCY} | sort | while read line do @@ -117,7 +98,19 @@ function webpage { echo "
" >>../index.html.tmp echo "

Market Performance ( $(cat MARKET_PERFORMANCE_LATEST)%)

" >>../index.html.tmp - echo "" >>../index.html.tmp + #echo "
Charts" >>../index.html.tmp + echo "
Charts" >>../index.html.tmp + echo "Krypto" >>../index.html.tmp + genchart MARKET_PERFORMANCE.csv 50 2,3,4,5,6,7 red-or-green,gold,royalblue,lightyellow,MediumSlateBlue,Sienna >>../index.html.tmp + echo "Commodities" >>../index.html.tmp + genchart MARKET_PERFORMANCE.csv 50 2,12,10,13 red-or-green,gold,SandyBrown,Sienna >>../index.html.tmp + echo "World Economic data" >>../index.html.tmp + genchart MARKET_PERFORMANCE.csv 50 2,11,15 red-or-green,Yellow,Sienna >>../index.html.tmp + echo "US Economic data" >>../index.html.tmp + genchart MARKET_PERFORMANCE.csv 50 2,8,17,16,18,19,20,21,14,9 red-or-green,OliveDrab,Yellow,Orange,DeepSkyBlue,DarkMagenta,PeachPuff,PaleTurquoise,Pink,PapayaWhip >>../index.html.tmp + #echo "
" >>../index.html.tmp + echo "" >>../index.html.tmp + echo "
Table" >>../index.html.tmp echo "" >>../index.html.tmp head -n1 MARKET_PERFORMANCE.csv | perl -pe 's/,/\n/g' | tr [:lower:] [:upper:] | while read f_mperfcol do @@ -142,35 +135,20 @@ function webpage { echo "" >>../index.html.tmp done - echo "
" >>../index.html.tmp + echo "
" >>../index.html.tmp echo "Complete list" >>../index.html.tmp - - echo "

Top/Flop

" >>../index.html.tmp - ls -1 trade-histories/*.result | cut -d . -f3-6 | sort -u | while read f_asset_results - do - f_asset=$(echo ${f_asset_results} | cut -d\- -f1) - echo $(cat trade-histories/*${f_asset_results} | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM)}") >trade-histories/${f_asset}.complete_result - done - echo "

Top 10

" >>../index.html.tmp - grep [0-9] trade-histories/*.complete_result | sort -t: -k2 -rn | head -n 10 | cut -d/ -f2 | perl -pe 's/\.complete_result:/ /; s/$/%
/' >>../index.html.tmp - - echo "

Flop 10

" >>../index.html.tmp - grep [0-9] trade-histories/*.complete_result | sort -t: -k2 -n | head -n 10 | cut -d/ -f2 | perl -pe 's/\.complete_result:/ /; s/$/%
/' >>../index.html.tmp - - echo '

Latest trades

' >>../index.html.tmp echo '

Open

' >>../index.html.tmp - echo "" >>../index.html.tmp + echo "
" >>../index.html.tmp echo " - - " >>../index.html.tmp + " >>../index.html.tmp local f_trade_file for f_trade_file in $(ls -t trade-histories/trade-*-open.history.csv 2>/dev/null) @@ -185,24 +163,23 @@ function webpage { - " >>../index.html.tmp + echo " - " >>../index.html.tmp + echo "" >>../index.html.tmp done echo "
Date Asset Action ${CURRENCY} Quantity ${CURRENCY} Price CommissionCommentChart
Comment
$(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 +
Chart" >>../index.html.tmp genchart "$interimfile" >>../index.html.tmp - echo "
" >>../index.html.tmp echo '

Closed

' >>../index.html.tmp - echo "" >>../index.html.tmp + echo "
" >>../index.html.tmp echo " - - " >>../index.html.tmp + " >>../index.html.tmp for f_trade_file in $(ls -t trade-histories/trade-*-closed.history.csv 2>/dev/null | head -n 50) do @@ -211,10 +188,12 @@ function webpage { do local f_action=$(echo ${tradeline} | cut -d, -f2) local f_price=$(echo ${tradeline} | cut -d, -f5) - + local tradedate=$(echo ${tradeline} | cut -d, -f1 | perl -pe 's/_([0-9][0-9])-([0-9][0-9])-([0-9][0-9])/ $1:$2/') + if echo ${f_action} | grep -q buy then echo ${f_price} >${g_tmp}/buyprice + local tradedatebuy=${tradedate} fi if echo ${f_action} | grep -q sell @@ -231,30 +210,43 @@ function webpage { 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 " - - - " >>../index.html.tmp + ">>../index.html.tmp + if echo ${f_action} | grep -q sell + then + echo "" >>../index.html.tmp + else + echo "" >>../index.html.tmp + fi done done echo "
Date Asset Action ${CURRENCY} Quantity ${CURRENCY} Price (result) CommissionCommentChart
Comment
$(echo ${tradeline} | cut -d, -f1)${tradedate} ${asset} 🔗 ${f_action} $(echo ${tradeline} | cut -d, -f4) ${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 "
$(echo ${tradeline} | cut -d, -f7,8,9,10,11,12,13,14,15)
Charts" >>../index.html.tmp + local tradeintervals=$(cat ${interimfile} | wc -l) + head -n1 asset-histories/${asset}.history.csv >${g_tmp}/trade.csv + grep -A ${tradeintervals} "${tradedatebuy}:" asset-histories/${asset}.history.csv >>${g_tmp}/trade.csv + echo "Price, EMA, Levels" >>../index.html.tmp + genchart "${g_tmp}/trade.csv" ${tradeintervals} 2,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39 >>../index.html.tmp + echo "MACD" >>../index.html.tmp + genchart "${g_tmp}/trade.csv" ${tradeintervals} 8,6,7 >>../index.html.tmp + echo "RSIs" >>../index.html.tmp + genchart "${g_tmp}/trade.csv" ${tradeintervals} 10,11,12,14,15,16,17,13 >>../index.html.tmp + + echo "
" >>../index.html.tmp - echo "

Current config

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

Current config

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

Available Assets and histories

' >>../index.html.tmp - echo "" >>../index.html.tmp + echo "
" >>../index.html.tmp echo "" >>../index.html.tmp local asset cat ASSETS | egrep -v "${BLACKLIST}" | sort | while read asset @@ -263,15 +255,36 @@ function webpage { echo "" >>../index.html.tmp kcurrency=$(echo ${asset} | sed "s/${CURRENCY}//") #get_rate_percentage_min_before_and_now ${kcurrency} ${CURRENCY} 1440 - local asset=($(cat asset-histories/${asset}.history.csv | egrep -v "0.00000000$" | tail -n2 | head -n1 | sed 's/,/ /g')) - echo " - - + local assetin=($(cat asset-histories/${asset}.history.csv | egrep -v "0.00000000$" | tail -n2 | head -n1 | sed 's/,/ /g')) + echo " + - " >>../index.html.tmp + " >>../index.html.tmp + done echo "
AssetDatePrice ${CURRENCY}24h change (USD)
${asset} 🔗${asset[0]} ${asset[1]}${CURRENCY} ${asset[2]}${assetin[0]} ${assetin[1]}${CURRENCY} ${assetin[2]} $(grep "^$kcurrency," ASSET_PRICE_CHANGE_PERCENTAGE_24H | cut -d, -f2)%
" >>../index.html.tmp + echo "
${asset} Charts" >>../index.html.tmp + echo "Price, EMA, Levels" >>../index.html.tmp + genchart asset-histories/${asset}.history.csv 50 2,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39 >>../index.html.tmp + echo "MACD" >>../index.html.tmp + genchart asset-histories/${asset}.history.csv 50 8,6,7 >>../index.html.tmp + echo "RSIs" >>../index.html.tmp + genchart asset-histories/${asset}.history.csv 50 10,11,12,14,15,16,17,13 >>../index.html.tmp + echo "
" >>../index.html.tmp - + + echo "

Top/Flop

" >>../index.html.tmp + ls -1 trade-histories/*.result | cut -d . -f3-6 | sort -u | while read f_asset_results + do + f_asset=$(echo ${f_asset_results} | cut -d\- -f1) + echo $(cat trade-histories/*${f_asset_results} | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM)}") >trade-histories/${f_asset}.complete_result + done + echo "

Top 10

" >>../index.html.tmp + grep [0-9] trade-histories/*.complete_result | sort -t: -k2 -rn | head -n 10 | cut -d/ -f2 | perl -pe 's/\.complete_result:/ /; s/$/%
/' >>../index.html.tmp + + echo "

Flop 10

" >>../index.html.tmp + grep [0-9] trade-histories/*.complete_result | sort -t: -k2 -n | head -n 10 | cut -d/ -f2 | perl -pe 's/\.complete_result:/ /; s/$/%
/' >>../index.html.tmp + + echo '

Complete trading histories

' >>../index.html.tmp echo "" >>../index.html.tmp find trade-histories -type f -name *.history.csv | cut -d/ -f2 | cut -d. -f1 | sort | while read asset @@ -284,4 +297,8 @@ function webpage { # color magic cat ../index.html.tmp | perl -pe 's/ (\-[0-9]+\.[0-9]+\%)/$1<\/font>/g; s/ ([0-9]+\.[0-9]+\%)/$1<\/font>/g;' >../index.html #mv ../index.html.tmp ../index.html + + g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@ finished" + } +