Compare commits

...

5 Commits

Author SHA1 Message Date
e3602cc7b8 fix 2024-09-04 18:04:06 +02:00
0dcdc33e7b update 2024-09-04 18:03:53 +02:00
a1c60d1696 update 2024-09-04 18:03:45 +02:00
ff46ae8e8a assoziative array 2024-09-04 18:03:28 +02:00
61c805ebfd assoziative array 2024-09-04 18:03:20 +02:00
5 changed files with 150 additions and 138 deletions

View File

@ -163,7 +163,7 @@ function get_ohlcv-candle {
then
f_open=${f_data_unit_ref[1]}
fi
g_num_exponential2normal "$f_open" && f_open=$g_num_exponential2normal_resul
g_num_exponential2normal "$f_open" && f_open=$g_num_exponential2normal_result
f_high=${f_data_unit_ref[2]}
g_num_exponential2normal "$f_high" && f_high=$g_num_exponential2normal_result
f_low=${f_data_unit_ref[3]}

View File

@ -61,25 +61,62 @@ select(.status==\"open\") |
fi
done
cat CCXT_ORDERS_*${CURRENCY} >CCXT_ORDERS 2>/dev/null
return 0
get_orders_array
}
function get_orders_array {
g_array CCXT_ORDERS f_get_ordes_rarray
local f_order
# clear/create assoziative array o
unset o
declare -Ag o
# build array from lines in CCXT_ORDERS
g_array CCXT_ORDERS f_get_ordes_array
for f_order in ${f_get_ordes_array[@]}
do
get_order_line_vars "$f_order"
done
# write values to file
for i in "${!o[@]}"
do
echo "\${o[$i]}=${o[$i]}"
done | sort >values-orders.new
mv values-orders.new values-orders
}
function get_orders_line_vars {
function get_order_line_vars {
local f_order_line=$1
g_array $f_order_line f_order_array ,
f_order_symbol=${f_order_array[0]}
local f_asset=${f_order_symbol//:$CURRENCY/}
f_asset=${f_asset//\//}
o[${f_asset}_type]=${f_order_array[1]}
f_order_type=${f_order_array[1]}
o[${f_asset}_side]=${f_order_array[2]}
f_order_side=${f_order_array[2]}
o[${f_asset}_entry_price]=${f_order_array[3]}
f_order_entry_price=${f_order_array[3]}
o[${f_asset}_amount]=${f_order_array[4]}
f_order_amount=${f_order_array[4]}
o[${f_asset}_id]=${f_order_array[5]}
f_order_id=${f_order_array[5]}
o[${f_asset}_stoplossprice]=${f_order_array[6]}
f_order_stoplossprice=${f_order_array[6]}
o[${f_asset}_takeprofitprice]=${f_order_array[7]}
f_order_takeprofitprice=${f_order_array[7]}
}

View File

@ -43,46 +43,96 @@ function get_positions {
jq -r "
.[] |
select(.entryPrice != 0) |
.symbol + \",\" + (.notional|tostring) + \",\" + (.entryPrice|tostring) + \",\" + (.markPrice|tostring) + \",\" + .side + \",\" + (.leverage|tostring) + \",\" + (.contracts|tostring) + \",\" + (.contractSize|tostring) + \",\" + (.liquidationPrice|tostring) + \",\" + (.unrealizedPnl|tostring)
.symbol + \",\" + (.collateral|tostring) + \",\" + (.entryPrice|tostring) + \",\" + (.markPrice|tostring) + \",\" + .side + \",\" + (.leverage|tostring) + \",\" + (.liquidationPrice|tostring) + \",\" + (.stopLossPrice|tostring) + \",\" + (.takeProfitPrice|tostring)
" CCXT_POSITIONS_RAW >CCXT_POSITIONS
}
function get_position_array {
local f_position
# clear/create assoziative array p
unset p
declare -Ag p
# build array from lines in CCXT_POSITIONS
g_array CCXT_POSITIONS f_get_positions_array
for f_position in ${f_get_positions_array[@]}
do
get_position_line_vars "$f_position"
done
# write values to file
for i in "${!p[@]}"
do
echo "\${p[$i]}=${p[$i]}"
done | sort >values-positions.new
mv values-positions.new values-positions
}
function get_position_line_vars {
local f_pos_line=$1
g_array $f_pos_line f_position_array ,
f_position_symbol=${f_position_array[0]}
f_position_currency_amount=${f_position_array[1]}
local f_asset=${f_position_symbol//:$CURRENCY/}
f_asset=${f_asset//\//}
printf -v f_position_currency_amount %.2f ${f_position_array[1]}
p[${f_asset}_currency_amount]=$f_position_currency_amount
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
f_position_side=${f_position_array[4]}
[ -z "$f_position_side" ] && f_position_side="long"
p[${f_asset}_side]=$f_position_side
f_position_leverage=${f_position_array[5]}
[ -z "$f_position_leverage" ] && f_position_leverage="1"
f_position_contracts=${f_position_array[6]}
f_position_contract_size=${f_position_array[7]}
f_position_liquidation_price=${f_position_array[8]}
f_position_unrealized_pnl=${f_position_array[9]}
[[ $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]}
g_percentage-diff $f_position_entry_price $f_position_current_price
[ "$f_position_side" = short ] && g_percentage-diff $f_position_current_price $f_position_entry_price
f_position_pnl_percentage=$g_percentage_diff_result
if [ -n $f_position_leverage ]
if [[ ${f_position_array[7]} = null ]]
then
g_calc "$f_position_pnl_percentage*$f_position_leverage"
f_position_pnl_percentage=$g_calc_result
g_calc "$f_position_currency_amount/$f_position_leverage"
f_position_currency_amount=$g_calc_result
g_calc "$f_position_currency_amount/100*$f_position_pnl_percentage"
f_position_pnl=$g_calc_result
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]}
fi
if [[ ${f_position_array[8]} = 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]}
fi
# calc pnl percentage
if [[ $f_position_side = long ]]
then
g_percentage-diff $f_position_entry_price $f_position_current_price
else
g_percentage-diff $f_position_current_price $f_position_entry_price
fi
g_calc "$g_percentage_diff_result*$f_position_leverage"
f_position_pnl_percentage=$g_calc_result
p[${f_asset}_pnl_percentage]=$g_calc_result
# calc pnl
g_calc "$f_position_currency_amount/100*$f_position_pnl_percentage"
printf -v f_position_pnl %.2f $g_calc_result
p[${f_asset}_pnl]=$f_position_pnl
}

View File

@ -22,8 +22,8 @@ function webpage {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
charts
webpage_transactions
get_symbols_ticker
# create status webpage
echo "<html>
@ -63,7 +63,7 @@ function webpage {
</table>" >>../index.html.tmp
echo "<h2>Balance in- outflows</h2>" >>../index.html.tmp
echo "<table><tr><td><b>Time ago</b><td><b>Balance</b></td><td><b>in/out</b></td><td><b>Percentage</b></td></tr>" >> ../index.html.tmp
echo "<table><tr class=\"headline\"><td><b>Time ago</b><td><b>Balance</b></td><td><b>in/out</b></td><td><b>Percentage</b></td></tr>" >> ../index.html.tmp
for f_balance_date in Day Week Month 3Month Year
do
@ -82,23 +82,35 @@ function webpage {
echo '<h2>Open Positions</h2>' >>../index.html.tmp
echo "<table width='100%'><tr><td>Symbol</td><td>Amount</td><td>Entry Price</td><td>Current Price</td><td>Profit/Loss</td><td>Notes</td></tr>" >>../index.html.tmp
echo "<table width='100%'><tr class=\"headline\"><td>Symbol</td><td>Amount</td><td>Entry Price</td><td>Current Price</td><td>Profit/Loss</td><td>Liquidation Price</td><td>StopLoss</td><td>TakeProfit</td><td>Notes</td></tr>" >>../index.html.tmp
get_position_array
for f_position in "${f_get_positions_array[@]}"
for f_symbol in ${f_symbols_array_trade[@]}
do
get_position_line_vars "$f_position"
printf -v f_position_currency_amount %.2f $f_position_currency_amount
printf -v f_position_entry_price %.2f $f_position_entry_price
printf -v f_position_current_price %.2f $f_position_current_price
printf -v f_position_pnl %.2f $f_position_pnl
echo "<tr><td>$f_position_symbol</td><td>${CURRENCY} $f_position_currency_amount</td><td>${CURRENCY} $f_position_entry_price</td><td>${CURRENCY} $f_position_current_price</td><td>${CURRENCY} $f_position_pnl ( ${f_position_pnl_percentage}%)</td><td>$f_position_side ${f_position_leverage}x</td></tr>" >>../index.html.tmp
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
done
echo "</table>" >>../index.html.tmp
echo '<h2>Open Orders</h2>' >>../index.html.tmp
echo "<table width='100%'><tr class=\"headline\"><td>Symbol</td><td>Amount</td><td>Entry Price</td><td>StopLoss</td><td>TakeProfit</td><td>Notes</td></tr>" >>../index.html.tmp
get_orders_array
for f_symbol in ${f_symbols_array_trade[@]}
do
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
done
echo "</table>" >>../index.html.tmp
## Open Positions
echo "<h2>Open Positions - From Trade Histories (daily refresh only)</h2>" >>../index.html.tmp
echo "<table width='100%'>" >>../index.html.tmp
echo "<tr><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
local f_result_complete=0
local f_spent_complete=0
@ -114,6 +126,7 @@ function webpage {
f_asset=${f_asset_per_exchange_array[1]%$'\n'}
f_exchange=${f_asset_per_exchange_array[0]}
[[ "$f_exchange" =~ JustTrade|Bitpanda ]] || continue
f_date=$(egrep "$f_exchange,.+,$f_asset" ALL_TRANSACTIONS_OVERVIEW.csv | tail -n1 | cut -d, -f1)
f_amount=$(egrep "$f_exchange,.+,$f_asset" ALL_TRANSACTIONS_OVERVIEW.csv | tail -n1 | cut -d, -f18)
f_spent=$(egrep "$f_exchange,.+,$f_asset" ALL_TRANSACTIONS_OVERVIEW.csv | tail -n1 | cut -d, -f20)
f_sold=$(egrep "$f_exchange,.+,$f_asset" ALL_TRANSACTIONS_OVERVIEW.csv | tail -n1 | cut -d, -f22)
@ -156,61 +169,22 @@ function webpage {
#f_sold_complete=$g_calc_result
printf -v f_sold_complete %.2f $g_calc_result
echo "<tr><td>$f_currency_amount $TRANSFER_CURRENCY</td><td>$f_spent $TRANSFER_CURRENCY</td><td>$f_sold $TRANSFER_CURRENCY</td><td>$f_result $TRANSFER_CURRENCY ( ${f_result_percent}%)</td><td>$f_amount $f_asset</td><td>$f_exchange</td></tr>" >>../index.html.tmp.tmp
echo "<tr><td>$f_date</td><td>$f_currency_amount $TRANSFER_CURRENCY</td><td>$f_spent $TRANSFER_CURRENCY</td><td>$f_sold $TRANSFER_CURRENCY</td><td>$f_result $TRANSFER_CURRENCY ( ${f_result_percent}%)</td><td>$f_amount $f_asset</td><td>$f_exchange</td></tr>" >>../index.html.tmp.tmp
fi
done
g_percentage-diff $f_spent_complete $f_currency_amount_complete
f_result_percent_complete=$g_percentage_diff_result
# ALL Line
echo "<tr><td>-</td><td>$f_currency_amount_complete $TRANSFER_CURRENCY</td><td>$f_spent_complete $TRANSFER_CURRENCY</td><td>$f_sold_complete $TRANSFER_CURRENCY</td><td>$f_result_complete $TRANSFER_CURRENCY ( ${f_result_percent_complete}%)</td><td>ALL</td><td>ALL</td></tr>" >>../index.html.tmp
echo "<tr><td>$f_currency_amount_complete $TRANSFER_CURRENCY</td><td>$f_spent_complete $TRANSFER_CURRENCY</td><td>$f_sold_complete $TRANSFER_CURRENCY</td><td>$f_result_complete $TRANSFER_CURRENCY ( ${f_result_percent_complete}%)</td><td>ALL</td><td>ALL</td></tr>" >>../index.html.tmp
sort -n -k3 -t'>' -r ../index.html.tmp.tmp >>../index.html.tmp
# Sort by Spent Amount
sort -n -k7 -t'>' -r ../index.html.tmp.tmp >>../index.html.tmp
rm ../index.html.tmp.tmp
echo "</table>" >>../index.html.tmp
fi
echo "<h2>Market Performance ( $(cat MARKET_PERFORMANCE_LATEST)%)</h2>" >>../index.html.tmp
#echo "<table width='100%'><tr><td><details><summary>Charts</summary>" >>../index.html.tmp
echo "<details><summary>Charts</summary>" >>../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 "</details></td></tr></table>" >>../index.html.tmp
echo "</details>" >>../index.html.tmp
echo "<details><summary>Table</summary><table width='100%'>" >>../index.html.tmp
echo "<tr>" >>../index.html.tmp
head -n1 MARKET_PERFORMANCE.csv | perl -pe 's/,/\n/g' | tr [:lower:] [:upper:] | while read f_mperfcol
do
echo "<td><b>${f_mperfcol}</b></td>" >>../index.html.tmp
done
echo "</tr>" >>../index.html.tmp
egrep "^[0-9][0-9]" MARKET_PERFORMANCE.csv | tail -n10 | while read f_mperfline
do
f_mperfline="$(echo ${f_mperfline} | perl -pe 's/ /_/g; s/,/ /g')"
echo "<tr>" >>../index.html.tmp
#echo "${mperfline}" | perl -pe 's/,/\n/g' | while read f_mperfcol
for f_mperfcol in ${f_mperfline}
do
if echo "${f_mperfcol}" | grep -q ":"
then
f_mperfcol="$(echo ${f_mperfcol} | perl -pe 's/_/ /')"
echo "<td><b>${f_mperfcol}</b></td>" >>../index.html.tmp
else
echo "<td> ${f_mperfcol}%</td>" >>../index.html.tmp
fi
done
echo "</tr>" >>../index.html.tmp
done
echo "</table></details>" >>../index.html.tmp
echo "<a href=\"botdata/MARKET_PERFORMANCE.csv\">Complete list</a>" >>../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

@ -86,63 +86,6 @@ a[id^="btn"] { background-color:#111111; cursor:pointer; display:inline-block; f
a[id^="btn"]:last-child { margin-left:-4px; }
a[id^="btn"]::-moz-focus-inner { border:0; padding:0; }
/* Chrome / Android / Tablet
html[data-useragent*="Chrome"][data-useragent*="Android"] body { color:#373837; }
html[data-useragent*="Chrome"][data-useragent*="Android"] audio { margin-left:4px; width:689px; }
html[data-useragent*="Chrome"][data-useragent*="Android"] #audiowrap { background-color:#fafafa; }
html[data-useragent*="Chrome"][data-useragent*="Android"] a[id^="btn"] { background-color:#fafafa; color:#373837; }
html[data-useragent*="Chrome"][data-useragent*="Android"] a[id^="btn"]:hover { background-color:#eee; }
html[data-useragent*="Chrome"][data-useragent*="Android"] #plList li { background-color:#fafafa; }
html[data-useragent*="Chrome"][data-useragent*="Android"] #plList li:hover { background-color:#eee; }
html[data-useragent*="Chrome"][data-useragent*="Android"] .plSel,
html[data-useragent*="Chrome"][data-useragent*="Android"] .plSel:hover { background-color:#eee!important; }
*/
/* Audio Player Media Queries
================================================== */
/* Tablet Portrait
@media only screen and (min-width: 768px) and (max-width: 959px) {
audio { width:526px; }
html[data-useragent*="MSIE 9.0"] audio { width:536px; }
html[data-useragent*="MSIE 10.0"] audio { width:543px; }
html[data-useragent*="rv:11.0"] audio { width:551px; }
html[data-useragent*="OS 7"] audio { width:546px; }
html[data-useragent*="OS 8"] audio { width:550px; }
html[data-useragent*="OS 9"] audio { width:550px; }
html[data-useragent*="Chrome"] audio { width:533px; }
html[data-useragent*="Chrome"][data-useragent*="Android"] audio { margin-left:4px; width:545px; }
}
/* Mobile Landscape
@media only screen and (min-width: 480px) and (max-width: 767px) {
audio { width:390px; }
html[data-useragent*="MSIE 9.0"] audio { width:400px; }
html[data-useragent*="MSIE 10.0"] audio { width:407px; }
html[data-useragent*="rv:11.0"] audio { width:415px; }
html[data-useragent*="OS 7"] audio { width:410px; }
html[data-useragent*="OS 8"] audio { width:414px; }
html[data-useragent*="OS 9"] audio { width:414px; }
html[data-useragent*="Chrome"] audio { width:397px; }
html[data-useragent*="Chrome"][data-useragent*="Mobile"] audio { margin-left:4px; width:410px; }
#npTitle { width:245px; }
}
/* Mobile Portrait
@media only screen and (max-width: 479px) {
audio { width:270px; }
html[data-useragent*="MSIE 9.0"] audio { width:280px; }
html[data-useragent*="MSIE 10.0"] audio { width:287px; }
html[data-useragent*="rv:11.0"] audio { width:295px; }
html[data-useragent*="OS 7"] audio { width:290px; }
html[data-useragent*="OS 8"] audio { width:294px; }
html[data-useragent*="OS 9"] audio { width:294px; }
html[data-useragent*="Chrome"] audio { width:277px; }
html[data-useragent*="Chrome"][data-useragent*="Mobile"] audio { margin-left:4px; width:290px; }
#npTitle { width:167px; }
}
*/
audio { width:92%; }
/* for VPN Login */
@ -173,12 +116,20 @@ pre,#footer {
font:16px sans-serif;
}
.headline {
font-size:18px;
background-color: #808080;
font-weight: bold;
color: black;
}
.statusok {
font:18px sans-serif;
background-color: #00BF40;
color: black;
}
.statusnok {
font:18px sans-serif;
background-color: #E10020;