Compare commits

...

5 Commits

Author SHA1 Message Date
f34c5ddf89 fixes 2024-09-05 18:02:25 +02:00
e991042eaa stoploss and takeprofit 2024-09-05 18:02:00 +02:00
d3714630b2 fixed and nicer output, added charts 2024-09-05 18:01:31 +02:00
170ad50652 fixed and nicer output, added charts 2024-09-05 18:01:25 +02:00
e15740900a examples 2024-09-05 14:55:59 +02:00
7 changed files with 157 additions and 59 deletions

7
.gitignore vendored
View File

@ -9,10 +9,13 @@
/dabo/.*-secrets
/home/.ssh
/home/.viminfo
/home/.bash_history
/home/.dabo-bot.sh.lock
.*history
.wget-hsts
/analyze-*
*.del
*.tmp
*local*
test*.sh
/env
/genpw.sh
/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 "
.[] |
select(.status==\"open\") |
.symbol + \",\" + .type + \",\" + .side + \",\" + (.price|tostring) + \",\" + (.amount|tostring) + \",\" + .id + \",\" + (.stopLossPrice|tostring) + \",\" + (.takeProfitPrice|tostring)
.symbol + \",\" + .type + \",\" + .side + \",\" + (.price|tostring) + \",\" + (.amount|tostring) + \",\" + .id + \",\" + (.stopLossPrice|tostring) + \",\" + (.takeProfitPrice|tostring) + \",\" + (.stopPrice|tostring)
" >"CCXT_ORDERS_${f_symbol_file}"
else
rm -f "CCXT_ORDERS_${f_symbol_file}_RAW" "CCXT_ORDERS_${f_symbol_file}"
@ -117,6 +117,9 @@ function get_order_line_vars {
o[${f_asset}_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} $@"
local f_symbol f_symbols
local f_symbol f_symbols f_asset f_stoploss f_takeprofit
get_symbols_ticker
@ -39,13 +39,40 @@ function get_positions {
[ -z "$f_symbols" ] && return 1
f_ccxt "print($STOCK_EXCHANGE.fetchPositions(symbols=[${f_symbols}]))" && echo $f_ccxt_result >CCXT_POSITIONS_RAW
jq -r "
.[] |
select(.entryPrice != 0) |
.symbol + \",\" + (.collateral|tostring) + \",\" + (.entryPrice|tostring) + \",\" + (.markPrice|tostring) + \",\" + .side + \",\" + (.leverage|tostring) + \",\" + (.liquidationPrice|tostring) + \",\" + (.stopLossPrice|tostring) + \",\" + (.takeProfitPrice|tostring)
.symbol + \",\" + (.collateral|tostring) + \",\" + (.entryPrice|tostring) + \",\" + .side + \",\" + (.leverage|tostring) + \",\" + (.liquidationPrice|tostring) + \",\" + (.stopLossPrice|tostring) + \",\" + (.takeProfitPrice|tostring)
" 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 {
@ -54,7 +81,7 @@ function get_position_array {
# clear/create assoziative array p
unset p
declare -Ag p
get_symbols_ticker
# build array from lines in CCXT_POSITIONS
g_array CCXT_POSITIONS f_get_positions_array
for f_position in ${f_get_positions_array[@]}
@ -85,36 +112,37 @@ function get_position_line_vars {
f_position_entry_price=${f_position_array[2]}
p[${f_asset}_entry_price]=$f_position_entry_price
f_position_current_price=${f_position_array[3]}
p[${f_asset}_current_price]=$f_position_current_price
# mark price seems not lates price in very case so take the ticker
p[${f_asset}_current_price]=${v[${f_asset}_price]}
f_position_current_price=${v[${f_asset}_price]}
f_position_side=${f_position_array[4]}
f_position_side=${f_position_array[3]}
[ -z "$f_position_side" ] && f_position_side="long"
p[${f_asset}_side]=$f_position_side
f_position_leverage=${f_position_array[5]}
f_position_leverage=${f_position_array[4]}
[[ $f_position_leverage = null ]] && f_position_leverage="1"
p[${f_asset}_leverage]=$f_position_leverage
p[${f_asset}_liquidation_price]=${f_position_array[6]}
f_position_liquidation_price=${f_position_array[6]}
p[${f_asset}_liquidation_price]=${f_position_array[5]}
f_position_liquidation_price=${f_position_array[5]}
if [[ ${f_position_array[7]} = null ]]
if [[ ${f_position_array[6]} = null ]]
then
unset p[${f_asset}_stoploss_price]
unset f_position_stoploss_price
else
p[${f_asset}_stoploss_price]=${f_position_array[7]}
f_position_stoploss_price=${f_position_array[7]}
p[${f_asset}_stoploss_price]=${f_position_array[6]}
f_position_stoploss_price=${f_position_array[6]}
fi
if [[ ${f_position_array[8]} = null ]]
if [[ ${f_position_array[7]} = null ]]
then
unset p[${f_asset}_takeprofit_price]
unset f_position_takeprofit_price
else
p[${f_asset}_takeprofit_price]=${f_position_array[8]}
f_position_takeprofit_price=${f_position_array[8]}
p[${f_asset}_takeprofit_price]=${f_position_array[7]}
f_position_takeprofit_price=${f_position_array[7]}
fi
# calc pnl percentage

View File

@ -39,9 +39,7 @@ function webpage {
<h1>State of Dabo-Bot! on ${STOCK_EXCHANGE} - ${URL} (ReadOnly)</h1>
<h1>Last update $(date '+%F %T')</h1>" >../index.html.tmp
# historic overview
echo '<a href=TRANSACTIONS_OVERVIEWS.html><h2>Historic Overview</h2></a>' >>../index.html.tmp
# balance
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)
g_calc "$f_COMPLETE_BALANCE-$f_USED_BALANCE"
@ -89,7 +87,17 @@ function webpage {
f_asset=${f_symbol//:$CURRENCY/}
f_asset=${f_asset//\//}
[ -z "${p[${f_asset}_entry_price]}" ] && continue
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
echo "<tr>
<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
echo "</table>" >>../index.html.tmp
@ -102,13 +110,37 @@ function webpage {
f_asset=${f_symbol//:$CURRENCY/}
f_asset=${f_asset//\//}
[ -z "${o[${f_asset}_entry_price]}" ] && 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
[ "${o[${f_asset}_entry_price]}" = "null" ] && continue
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
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
echo "<h2>Open Positions - From Trade Histories (daily refresh only)</h2>" >>../index.html.tmp
echo "<h2>Open Positions - from other Exchanges</h2>
<p>Crypto-Only from Bitpanda and JustTrade - daily refresh</p>" >>../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
rm -f ../index.html.tmp.tmp
@ -118,9 +150,7 @@ function webpage {
local f_sold_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
if [ -s ALL_TRANSACTIONS_OVERVIEW.csv ]
then
for f_asset_per_exchange in $(cat ALL_TRANSACTIONS_OVERVIEW.csv | cut -d, -f2,4 | sort -u)
for f_asset_per_exchange in $(cat ALL_TRANSACTIONS_OVERVIEW.csv 2>/dev/null | cut -d, -f2,4 | sort -u)
do
mapfile -d, -t f_asset_per_exchange_array < <(echo $f_asset_per_exchange)
f_asset=${f_asset_per_exchange_array[1]%$'\n'}
@ -183,7 +213,19 @@ function webpage {
sort -n -k7 -t'>' -r ../index.html.tmp.tmp >>../index.html.tmp
rm ../index.html.tmp.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
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
cat ALL_TRANSACTIONS_OVERVIEW.csv | cut -d- -f1 | sort -u | while read f_tax_year
do
echo "========== Tax year $f_tax_year (German Tax Law) =========="
#echo "========== Tax year $f_tax_year (German Tax Law) =========="
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
do
@ -45,9 +45,9 @@ function webpage_transactions {
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) }")
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>
<head>
@ -88,31 +88,5 @@ $(cat ${g_tmp}/tax_summary_$f_exchange-$f_tax_year)
echo ""
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

@ -82,7 +82,7 @@ const chart = LightweightCharts.createChart(document.getElementById('container')
type: 'solid',
color: '#222',
},
textColor: '#DDD',
textColor: '#DDD',
},
grid: {

View File

@ -0,0 +1,48 @@
# 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"