Compare commits

..

No commits in common. "f34c5ddf89612dd17ca600a9b46ebdee6cea1786" and "e3602cc7b8d17626e1ced0b96b584d179745c052" have entirely different histories.

7 changed files with 59 additions and 157 deletions

7
.gitignore vendored
View File

@ -9,13 +9,10 @@
/dabo/.*-secrets /dabo/.*-secrets
/home/.ssh /home/.ssh
/home/.viminfo /home/.viminfo
.*history /home/.bash_history
.wget-hsts /home/.dabo-bot.sh.lock
/analyze-* /analyze-*
*.del *.del
*.tmp
*local*
test*.sh
/env /env
/genpw.sh /genpw.sh
/watch-assets.csv* /watch-assets.csv*

View File

@ -53,7 +53,7 @@ function get_orders {
echo $f_ccxt_result | tee "CCXT_ORDERS_${f_symbol_file}_RAW" | jq -r " echo $f_ccxt_result | tee "CCXT_ORDERS_${f_symbol_file}_RAW" | jq -r "
.[] | .[] |
select(.status==\"open\") | select(.status==\"open\") |
.symbol + \",\" + .type + \",\" + .side + \",\" + (.price|tostring) + \",\" + (.amount|tostring) + \",\" + .id + \",\" + (.stopLossPrice|tostring) + \",\" + (.takeProfitPrice|tostring) + \",\" + (.stopPrice|tostring) .symbol + \",\" + .type + \",\" + .side + \",\" + (.price|tostring) + \",\" + (.amount|tostring) + \",\" + .id + \",\" + (.stopLossPrice|tostring) + \",\" + (.takeProfitPrice|tostring)
" >"CCXT_ORDERS_${f_symbol_file}" " >"CCXT_ORDERS_${f_symbol_file}"
else else
rm -f "CCXT_ORDERS_${f_symbol_file}_RAW" "CCXT_ORDERS_${f_symbol_file}" rm -f "CCXT_ORDERS_${f_symbol_file}_RAW" "CCXT_ORDERS_${f_symbol_file}"
@ -117,9 +117,6 @@ function get_order_line_vars {
o[${f_asset}_takeprofitprice]=${f_order_array[7]} o[${f_asset}_takeprofitprice]=${f_order_array[7]}
f_order_takeprofitprice=${f_order_array[7]} f_order_takeprofitprice=${f_order_array[7]}
o[${f_asset}_stopprice]=${f_order_array[8]}
f_order_stopprice=${f_order_array[8]}
} }

View File

@ -22,7 +22,7 @@ function get_positions {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_symbol f_symbols f_asset f_stoploss f_takeprofit local f_symbol f_symbols
get_symbols_ticker get_symbols_ticker
@ -39,40 +39,13 @@ function get_positions {
[ -z "$f_symbols" ] && return 1 [ -z "$f_symbols" ] && return 1
f_ccxt "print($STOCK_EXCHANGE.fetchPositions(symbols=[${f_symbols}]))" && echo $f_ccxt_result >CCXT_POSITIONS_RAW f_ccxt "print($STOCK_EXCHANGE.fetchPositions(symbols=[${f_symbols}]))" && echo $f_ccxt_result >CCXT_POSITIONS_RAW
jq -r " jq -r "
.[] | .[] |
select(.entryPrice != 0) | select(.entryPrice != 0) |
.symbol + \",\" + (.collateral|tostring) + \",\" + (.entryPrice|tostring) + \",\" + .side + \",\" + (.leverage|tostring) + \",\" + (.liquidationPrice|tostring) + \",\" + (.stopLossPrice|tostring) + \",\" + (.takeProfitPrice|tostring) .symbol + \",\" + (.collateral|tostring) + \",\" + (.entryPrice|tostring) + \",\" + (.markPrice|tostring) + \",\" + .side + \",\" + (.leverage|tostring) + \",\" + (.liquidationPrice|tostring) + \",\" + (.stopLossPrice|tostring) + \",\" + (.takeProfitPrice|tostring)
" CCXT_POSITIONS_RAW >CCXT_POSITIONS " CCXT_POSITIONS_RAW >CCXT_POSITIONS
# check for takeprofit/stoploss orders if not in CCXT output (needed for phememx and maybe more exchanges)
get_position_array
for f_symbol in ${f_symbols_array_trade[@]}
do
f_asset=${f_symbol//:$CURRENCY/}
f_asset=${f_asset//\//}
# only continue if position for symbol exists and stoploss or takeprofit is empty
[ -z "${p[${f_asset}_entry_price]}" ] && continue
[ -n "${p[${f_asset}_stoploss_price]}" ] && continue
[ -n "${p[${f_asset}_takeprofit_price]}" ] && continue
# check for position side
[ "${p[${f_asset}_side]}" = "long" ] && f_action=sell
[ "${p[${f_asset}_side]}" = "short" ] && f_action=buy
if [[ ${p[${f_asset}_side]} =~ long|short ]]
then
# search fpr stoploss and takeprofit
f_stoploss=$(egrep "^$f_symbol,Stop,$f_action,null,0," CCXT_ORDERS | cut -d , -f9)
f_takeprofit=$(egrep "^$f_symbol,MarketIfTouched,$f_action,null,0," CCXT_ORDERS | cut -d , -f9)
# escape : and / for sed and edit CCXT_POSITIONS if stoploss or takeprofit order found
f_symbol=${f_symbol//\//\\\/}
f_symbol=${f_symbol//:/\\:}
[ -n "$f_stoploss" ] && sed -i "/^$f_symbol,.*,${p[${f_asset}_side]},/s/^\(\([^,]*,\)\{6\}\)[^,]*/\1$f_stoploss/" CCXT_POSITIONS
[ -n "$f_takeprofit" ] && sed -i "/^$f_symbol,.*,${p[${f_asset}_side]},/s/^\(\([^,]*,\)\{7\}\)[^,]*/\1$f_takeprofit/" CCXT_POSITIONS
fi
done
} }
function get_position_array { function get_position_array {
@ -81,7 +54,7 @@ function get_position_array {
# clear/create assoziative array p # clear/create assoziative array p
unset p unset p
declare -Ag p declare -Ag p
get_symbols_ticker
# build array from lines in CCXT_POSITIONS # build array from lines in CCXT_POSITIONS
g_array CCXT_POSITIONS f_get_positions_array g_array CCXT_POSITIONS f_get_positions_array
for f_position in ${f_get_positions_array[@]} for f_position in ${f_get_positions_array[@]}
@ -112,37 +85,36 @@ function get_position_line_vars {
f_position_entry_price=${f_position_array[2]} f_position_entry_price=${f_position_array[2]}
p[${f_asset}_entry_price]=$f_position_entry_price p[${f_asset}_entry_price]=$f_position_entry_price
# mark price seems not lates price in very case so take the ticker f_position_current_price=${f_position_array[3]}
p[${f_asset}_current_price]=${v[${f_asset}_price]} p[${f_asset}_current_price]=$f_position_current_price
f_position_current_price=${v[${f_asset}_price]}
f_position_side=${f_position_array[3]} f_position_side=${f_position_array[4]}
[ -z "$f_position_side" ] && f_position_side="long" [ -z "$f_position_side" ] && f_position_side="long"
p[${f_asset}_side]=$f_position_side p[${f_asset}_side]=$f_position_side
f_position_leverage=${f_position_array[4]} f_position_leverage=${f_position_array[5]}
[[ $f_position_leverage = null ]] && f_position_leverage="1" [[ $f_position_leverage = null ]] && f_position_leverage="1"
p[${f_asset}_leverage]=$f_position_leverage p[${f_asset}_leverage]=$f_position_leverage
p[${f_asset}_liquidation_price]=${f_position_array[5]} p[${f_asset}_liquidation_price]=${f_position_array[6]}
f_position_liquidation_price=${f_position_array[5]} f_position_liquidation_price=${f_position_array[6]}
if [[ ${f_position_array[6]} = null ]] if [[ ${f_position_array[7]} = null ]]
then then
unset p[${f_asset}_stoploss_price] unset p[${f_asset}_stoploss_price]
unset f_position_stoploss_price unset f_position_stoploss_price
else else
p[${f_asset}_stoploss_price]=${f_position_array[6]} p[${f_asset}_stoploss_price]=${f_position_array[7]}
f_position_stoploss_price=${f_position_array[6]} f_position_stoploss_price=${f_position_array[7]}
fi fi
if [[ ${f_position_array[7]} = null ]] if [[ ${f_position_array[8]} = null ]]
then then
unset p[${f_asset}_takeprofit_price] unset p[${f_asset}_takeprofit_price]
unset f_position_takeprofit_price unset f_position_takeprofit_price
else else
p[${f_asset}_takeprofit_price]=${f_position_array[7]} p[${f_asset}_takeprofit_price]=${f_position_array[8]}
f_position_takeprofit_price=${f_position_array[7]} f_position_takeprofit_price=${f_position_array[8]}
fi fi
# calc pnl percentage # calc pnl percentage

View File

@ -39,7 +39,9 @@ function webpage {
<h1>State of Dabo-Bot! on ${STOCK_EXCHANGE} - ${URL} (ReadOnly)</h1> <h1>State of Dabo-Bot! on ${STOCK_EXCHANGE} - ${URL} (ReadOnly)</h1>
<h1>Last update $(date '+%F %T')</h1>" >../index.html.tmp <h1>Last update $(date '+%F %T')</h1>" >../index.html.tmp
# balance # historic overview
echo '<a href=TRANSACTIONS_OVERVIEWS.html><h2>Historic Overview</h2></a>' >>../index.html.tmp
local f_USED_BALANCE=$(tail -n1 "asset-histories/BALANCEUSED${CURRENCY}.history.csv" | cut -d, -f2) local f_USED_BALANCE=$(tail -n1 "asset-histories/BALANCEUSED${CURRENCY}.history.csv" | cut -d, -f2)
local f_COMPLETE_BALANCE=$(tail -n1 "asset-histories/BALANCECOMPLETE${CURRENCY}.history.csv" | cut -d, -f2) local f_COMPLETE_BALANCE=$(tail -n1 "asset-histories/BALANCECOMPLETE${CURRENCY}.history.csv" | cut -d, -f2)
g_calc "$f_COMPLETE_BALANCE-$f_USED_BALANCE" g_calc "$f_COMPLETE_BALANCE-$f_USED_BALANCE"
@ -87,17 +89,7 @@ function webpage {
f_asset=${f_symbol//:$CURRENCY/} f_asset=${f_symbol//:$CURRENCY/}
f_asset=${f_asset//\//} f_asset=${f_asset//\//}
[ -z "${p[${f_asset}_entry_price]}" ] && continue [ -z "${p[${f_asset}_entry_price]}" ] && continue
echo "<tr> echo "<tr><td>$f_symbol</td><td>${p[${f_asset}_currency_amount]}</td><td>${p[${f_asset}_entry_price]}</td><td>${p[${f_asset}_current_price]}</td><td>${p[${f_asset}_pnl]} ( ${p[${f_asset}_pnl_percentage]}%)</td><td>${p[${f_asset}_liquidation_price]}</td><td>${p[${f_asset}_stoploss_price]}</td><td>${p[${f_asset}_takeprofit_price]}</td><td>${p[${f_asset}_side]} ${p[${f_asset}_leverage]}x</td></tr>" >>../index.html.tmp
<td><a href=\"charts.html?symbol=${f_asset}&time=4h&symbol2=BTCUSDT\" target=\"_blank\" rel=\"noopener noreferrer\">$f_symbol</a></td>
<td>${p[${f_asset}_currency_amount]}</td>
<td>${p[${f_asset}_entry_price]}</td>
<td>${p[${f_asset}_current_price]}</td>
<td>${p[${f_asset}_pnl]} ( ${p[${f_asset}_pnl_percentage]}%)</td>
<td>${p[${f_asset}_liquidation_price]}</td>
<td>${p[${f_asset}_stoploss_price]}</td>
<td>${p[${f_asset}_takeprofit_price]}</td>
<td>${p[${f_asset}_side]} ${p[${f_asset}_leverage]}x</td>
</tr>" >>../index.html.tmp
done done
echo "</table>" >>../index.html.tmp echo "</table>" >>../index.html.tmp
@ -110,37 +102,13 @@ function webpage {
f_asset=${f_symbol//:$CURRENCY/} f_asset=${f_symbol//:$CURRENCY/}
f_asset=${f_asset//\//} f_asset=${f_asset//\//}
[ -z "${o[${f_asset}_entry_price]}" ] && continue [ -z "${o[${f_asset}_entry_price]}" ] && continue
[ "${o[${f_asset}_entry_price]}" = "null" ] && continue echo "<tr><td>$f_symbol</td><td>${o[${f_asset}_amount]}</td><td>${o[${f_asset}_entry_price]}</td><td>${o[${f_asset}_stoplossprice]}</td><td>${o[${f_asset}_takeprofitprice]}</td><td>${o[${f_asset}_type]} ${p[${f_asset}_side]}</td></tr>" >>../index.html.tmp
echo "<tr>
<td><a href=\"charts.html?symbol=${f_asset}&time=4h&symbol2=BTCUSDT\" target=\"_blank\" rel=\"noopener noreferrer\">$f_symbol</a></td>
<td>${o[${f_asset}_amount]}</td>
<td>${o[${f_asset}_entry_price]}</td>
<td>${o[${f_asset}_stoplossprice]}</td>
<td>${o[${f_asset}_takeprofitprice]}</td>
<td>${o[${f_asset}_type]} ${p[${f_asset}_side]}</td>
</tr>" >>../index.html.tmp
done done
echo "</table>" >>../index.html.tmp echo "</table>" >>../index.html.tmp
## charts
echo '<h2>Charts with local data</h2><p>Click on time units to open chart</p>' >>../index.html.tmp
local eco_assets=$(echo " $ECO_ASSETS" | sed 's/ / ECONOMY-/g')
for f_symbol in ${f_symbols_array_trade[@]} $eco_assets
do
f_asset=${f_symbol//:$CURRENCY/}
f_asset=${f_asset//\//}
echo "$f_asset: " >>../index.html.tmp
for f_timeframe in 1w 1d 4h 1h 15m
do
echo "<td><a href=\"charts.html?symbol=${f_asset}&time=${f_timeframe}&symbol2=BTCUSDT\" target=\"_blank\" rel=\"noopener noreferrer\"}>${f_timeframe}</a>" >>../index.html.tmp
done
echo "<br>" >>../index.html.tmp
done
## Open Positions ## Open Positions
echo "<h2>Open Positions - from other Exchanges</h2> echo "<h2>Open Positions - From Trade Histories (daily refresh only)</h2>" >>../index.html.tmp
<p>Crypto-Only from Bitpanda and JustTrade - daily refresh</p>" >>../index.html.tmp
echo "<table width='100%'>" >>../index.html.tmp echo "<table width='100%'>" >>../index.html.tmp
echo "<tr class=\"headline\"><td>Date</td><td>Amount</td><td>Spent Amount</td><td>Sold Amount</td><td>Profit/Loss</td><td>Asset Amount</td><td>Exchange</td></tr>" >>../index.html.tmp echo "<tr class=\"headline\"><td>Date</td><td>Amount</td><td>Spent Amount</td><td>Sold Amount</td><td>Profit/Loss</td><td>Asset Amount</td><td>Exchange</td></tr>" >>../index.html.tmp
rm -f ../index.html.tmp.tmp rm -f ../index.html.tmp.tmp
@ -150,7 +118,9 @@ function webpage {
local f_sold_complete=0 local f_sold_complete=0
local f_result_percent_complete=0 local f_result_percent_complete=0
local f_asset f_exchange f_amount f_spent f_sold f_currency_amount f_result_percent local f_asset f_exchange f_amount f_spent f_sold f_currency_amount f_result_percent
for f_asset_per_exchange in $(cat ALL_TRANSACTIONS_OVERVIEW.csv 2>/dev/null | cut -d, -f2,4 | sort -u) if [ -s ALL_TRANSACTIONS_OVERVIEW.csv ]
then
for f_asset_per_exchange in $(cat ALL_TRANSACTIONS_OVERVIEW.csv | cut -d, -f2,4 | sort -u)
do do
mapfile -d, -t f_asset_per_exchange_array < <(echo $f_asset_per_exchange) mapfile -d, -t f_asset_per_exchange_array < <(echo $f_asset_per_exchange)
f_asset=${f_asset_per_exchange_array[1]%$'\n'} f_asset=${f_asset_per_exchange_array[1]%$'\n'}
@ -213,19 +183,7 @@ function webpage {
sort -n -k7 -t'>' -r ../index.html.tmp.tmp >>../index.html.tmp sort -n -k7 -t'>' -r ../index.html.tmp.tmp >>../index.html.tmp
rm ../index.html.tmp.tmp rm ../index.html.tmp.tmp
echo "</table>" >>../index.html.tmp echo "</table>" >>../index.html.tmp
fi
# Closed positions
echo "<h2>Closed Positions and (german) tax declaration notes</h2>" >>../index.html.tmp
ls ../TRANSACTIONS_OVERVIEW-* | while read f_html
do
f_html=$(basename $f_html)
f_name=$(echo $f_html | cut -d- -f2,3 | cut -d. -f1)
echo "<a href='${f_html}'>$f_name</a><br>" >>../index.html.tmp
done
echo "$(cat ALL_TRANSACTIONS_OVERVIEW_WARN.csv | cut -d, -f1,2,20)<br>" >>../index.html.tmp
# THE END
echo "</body></html>" >>../index.html.tmp
# color magic # color magic
cat ../index.html.tmp | perl -pe 's/ (\-[0-9]+\.[0-9]+\%)/<font color=red>$1<\/font>/g; s/ ([0-9]+\.[0-9]+\%)/<font color=green>$1<\/font>/g;' >../index.html cat ../index.html.tmp | perl -pe 's/ (\-[0-9]+\.[0-9]+\%)/<font color=red>$1<\/font>/g; s/ ([0-9]+\.[0-9]+\%)/<font color=green>$1<\/font>/g;' >../index.html

View File

@ -37,7 +37,7 @@ function webpage_transactions {
local f_tax_year local f_tax_year
cat ALL_TRANSACTIONS_OVERVIEW.csv | cut -d- -f1 | sort -u | while read f_tax_year cat ALL_TRANSACTIONS_OVERVIEW.csv | cut -d- -f1 | sort -u | while read f_tax_year
do do
#echo "========== Tax year $f_tax_year (German Tax Law) ==========" echo "========== Tax year $f_tax_year (German Tax Law) =========="
local f_exchange_tax_type local f_exchange_tax_type
cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^$f_tax_year-" | cut -d, -f 2,13 | sort -u | egrep -v ',$' | grep -v "Note: " | while read f_exchange_tax_type cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^$f_tax_year-" | cut -d, -f 2,13 | sort -u | egrep -v ',$' | grep -v "Note: " | while read f_exchange_tax_type
do do
@ -45,9 +45,9 @@ function webpage_transactions {
local f_tax_type=$(echo $f_exchange_tax_type | cut -d, -f2) local f_tax_type=$(echo $f_exchange_tax_type | cut -d, -f2)
local f_tax=$(cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^$f_tax_year-" | cut -d, -f 2,13,14 | egrep -v ',,0$' | grep "$f_exchange_tax_type" | cut -d, -f3 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }") local f_tax=$(cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^$f_tax_year-" | cut -d, -f 2,13,14 | egrep -v ',,0$' | grep "$f_exchange_tax_type" | cut -d, -f3 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }")
#echo "$f_exchange_tax_type: $f_tax" echo "$f_exchange_tax_type: $f_tax"
#echo "$f_tax_type: $f_tax EUR<br>" >>${g_tmp}/tax_summary_$f_exchange-$f_tax_year echo "$f_tax_type: $f_tax EUR<br>" >>${g_tmp}/tax_summary_$f_exchange-$f_tax_year
echo "<html> echo "<html>
<head> <head>
@ -88,5 +88,31 @@ $(cat ${g_tmp}/tax_summary_$f_exchange-$f_tax_year)
echo "" echo ""
done done
## Overview over Overviews
echo "<html>
<head>
<meta charset='UTF-8'>
<meta http-equiv='refresh' content='${INTERVAL}'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' type='text/css' href='/browser.css'>
<link rel='stylesheet' type='text/css' href='/charts.min.css'>
<title>Trading Overview</title>
</head>
<body>
<h1>Transaction Overviews</h1>" >../TRANSACTIONS_OVERVIEWS.html
local f_html f_name
ls ../TRANSACTIONS_OVERVIEW-* | while read f_html
do
f_html=$(basename $f_html)
f_name=$(echo $f_html | cut -d- -f2,3 | cut -d. -f1)
echo "<a href='${f_html}'>$f_name</a><br>" >>../TRANSACTIONS_OVERVIEWS.html
done
echo "$(cat ALL_TRANSACTIONS_OVERVIEW_WARN.csv | cut -d, -f1,2,20)<br>" >>../TRANSACTIONS_OVERVIEWS.html
echo "</body></html>" >>../TRANSACTIONS_OVERVIEWS.html
} }

View File

@ -1,48 +0,0 @@
# Example strategy
g_echo_note "EXAMPLE Strategy"
return 0
for f_symbol in ${f_symbols_array_trade[@]}
do
echo "=== $f_symbol"
f_asset=${f_symbol//:$CURRENCY/}
f_asset=${f_asset//\//}
echo "asset:${f_asset}"
for check_var in price levels_1w_next_up levels_1w_next_down
do
echo "$check_var:${v[${f_asset}_$check_var]}"
if [ -z "${v[${f_asset}_$check_var]}" ]
then
g_echo_warn "var \${v[${f_asset}_$check_var]} does not exist!!!"
continue 2
fi
done
echo "level_1w_next_up:${v[${f_asset}_levels_1w_next_up]}"
#position_close "$f_symbol"
#f_ccxt "print(${STOCK_EXCHANGE}.cancelAllOrders('$f_symbol'))"
# stoploss 2% under ${v[${f_asset}_levels_1w_next_down]}
g_calc "${v[${f_asset}_levels_1w_next_down]}-(${v[${f_asset}_levels_1w_next_down]}/100*2)"
stoploss=$g_calc_result
# takeprofit 2% under ${v[${f_asset}_levels_1w_next_up]} or +0.5%
#g_calc "${v[${f_asset}_levels_1w_next_up]}-(${v[${f_asset}_levels_1w_next_up]}/100*2)"
#echo "g_num_is_lower_equal $g_calc_result ${v[${f_asset}_price]} && g_calc \"${v[${f_asset}_price]}/100*100.5\""
g_calc "${v[${f_asset}_price]}/100*100.5"
takeprofit=$g_calc_result
grep -q "^$f_symbol" CCXT_POSITIONS CCXT_ORDERS || order "$f_symbol" 100 long "${v[${f_asset}_levels_1w_next_down]}" "$stoploss" "$takeprofit"
done
# example scoring
#g_num_is_higher $v_ECONOMY_SP500_1d_rsi14 55 && score -2 "SP500 RSI14 $f_rsi14"
#g_num_is_lower $v_ECONOMY_SP500_1d_rsi14 45 && score 2 "SP500 RSI14 $f_rsi14"