switch to CCXT
This commit is contained in:
32
dabo/functions/get_balance.sh
Normal file
32
dabo/functions/get_balance.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
function get_balance {
|
||||
|
||||
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
|
||||
|
||||
f_ccxt "print(${STOCK_EXCHANGE}.fetch_balance ({\"currency\": \"$CURRENCY\"}))" && [ -n "$f_ccxt_json_out" ] && echo $f_ccxt_result >CCXT_BALANCE
|
||||
|
||||
# get current investmentbalance
|
||||
f_CURRENCY_BALANCE=$(jq -r ".${CURRENCY}.free" CCXT_BALANCE)
|
||||
if g_num_valid_number "${f_CURRENCY_BALANCE}"
|
||||
then
|
||||
g_echo_note "=== Investmentbudget: $f_CURRENCY_BALANCE $CURRENCY"
|
||||
printf -v CURRENCY_BALANCE %.2f ${f_CURRENCY_BALANCE}
|
||||
else
|
||||
g_echo_warn "Could not determine CURRENCY_BALANCE (${f_CURRENCY_BALANCE} ${CURRENCY}) from file CCXT_BALANCE $(tail -n 10 CCXT_BALANCE)"
|
||||
return 3
|
||||
fi
|
||||
|
||||
f_USED_BALANCE=$(jq -r ".${CURRENCY}.used" CCXT_BALANCE)
|
||||
printf -v USED_BALANCE %.2f ${f_USED_BALANCE}
|
||||
f_COMPLETE_BALANCE=$(jq -r ".${CURRENCY}.total" CCXT_BALANCE)
|
||||
printf -v COMPLETE_BALANCE %.2f ${f_COMPLETE_BALANCE}
|
||||
|
||||
# write balance history
|
||||
g_echo_note "=== Total Balance: $f_COMPLETE_BALANCE $CURRENCY"
|
||||
g_echo_note "=== Free Balance: $f_CURRENCY_BALANCE $CURRENCY"
|
||||
g_echo_note "=== Used Balance: $f_USED_BALANCE $CURRENCY"
|
||||
echo "$f_timestamp,$COMPLETE_BALANCE" >>"asset-histories/BALANCECOMPLETE${CURRENCY}.history.csv"
|
||||
echo "$f_timestamp,$USED_BALANCE" >>"asset-histories/BALANCEUSED${CURRENCY}.history.csv"
|
||||
echo "$f_timestamp,$CURRENCY_BALANCE" >>"asset-histories/BALANCE${CURRENCY}.history.csv"
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user