118 lines
4.8 KiB
Bash
118 lines
4.8 KiB
Bash
function get_assets {
|
|
|
|
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
|
|
|
|
## determine assets with prices
|
|
local f_filename="EXCHANGE_GET_ASSETS_CMD"
|
|
# Try to collect assets
|
|
# get data from API
|
|
if [ ${STOCK_EXCHANGE} = "BINANCE" ]
|
|
then
|
|
binance-api-call GET /api/v3/ticker/price || return 1
|
|
# parse API output
|
|
cat ${g_tmp}/API_CMD_OUT | jq -r '.[] | .symbol + "," + .price' | grep "${CURRENCY}," | egrep -v "${TRANSFER_CURRENCY},|,0[\.][0]*$" >${f_filename}_OUT.tmp
|
|
elif [ ${STOCK_EXCHANGE} = "BITPANDA" ]
|
|
then
|
|
bitpanda-api-call GET "public/v1/market-ticker" || return 1
|
|
cat ${g_tmp}/API_CMD_OUT | jq -r '.[] | select(.state=="ACTIVE") | .instrument_code + "," + .last_price' | sed 's/_//' | grep "${CURRENCY}," | egrep -v "${TRANSFER_CURRENCY},|,0[\.][0]*$" >${f_filename}_OUT.tmp
|
|
fi
|
|
cp -p ${g_tmp}/API_CMD_OUT PRICETICKER
|
|
|
|
# timestamp for data
|
|
f_timestamp=$(g_date_print)
|
|
# check output
|
|
if [ -s ${f_filename}_OUT.tmp ] && egrep -q "^[A-Z]+${CURRENCY},[0-9]*\.[0-9]+$" ${f_filename}_OUT.tmp
|
|
then
|
|
mv ${f_filename}_OUT.tmp ${f_filename}_OUT
|
|
else
|
|
g_echo_warn "${f_filename}_OUT.tmp has wrong Syntax. - Not updating ${f_filename}_OUT $(tail -n 10 ${f_filename}_OUT.tmp)"
|
|
return 2
|
|
fi
|
|
|
|
## write assets list and filter by marketcap and sort by price
|
|
# get krypto symbol list sorted by marketcap
|
|
echo "curl -s -X 'GET' \"https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=250&page=1&sparkline=false&price_change_percentage=1h,24h,7d,14d,30d,1y\" -H 'accept: application/json'" >COINGECKO_GET_ASSETS_CMD
|
|
g_runcmd g_retrycmd sh COINGECKO_GET_ASSETS_CMD >COINGECKO_GET_ASSETS_CMD_OUT || return 1
|
|
#ASSET_MARKETCAP_OUT.tmp || return 1
|
|
if [ -s COINGECKO_GET_ASSETS_CMD_OUT ] && grep -q "market_cap_rank" COINGECKO_GET_ASSETS_CMD_OUT
|
|
then
|
|
|
|
# get marketcap sort
|
|
jq -r '.[].symbol' COINGECKO_GET_ASSETS_CMD_OUT | tr [:lower:] [:upper:] | head -n $LARGEST_MARKETCAP >ASSET_MARKETCAP_OUT.tmp-sort
|
|
if [ -s ASSET_MARKETCAP_OUT.tmp-sort ] && egrep -q "^[A-Z0-9]+$" ASSET_MARKETCAP_OUT.tmp-sort
|
|
then
|
|
mv ASSET_MARKETCAP_OUT.tmp-sort SORTMARKETCAP
|
|
else
|
|
g_echo_warn "ASSET_MARKETCAP_OUT.tmp-sort has wrong Syntax. - Not updating ASSET_MARKETCAP_OUT.tmp-sort $(tail -n 10 ASSET_MARKETCAP_OUT.tmp-sort)"
|
|
return 2
|
|
fi
|
|
|
|
# write down 24h pricechange
|
|
cat COINGECKO_GET_ASSETS_CMD_OUT | jq -r '.[] | .symbol + "," + (.price_change_percentage_24h|tostring)' | tr [:lower:] [:upper:] >ASSET_PRICE_CHANGE_PERCENTAGE_24H
|
|
|
|
# store coingecko symbolids for coingecko info URLs
|
|
jq -r '.[] | .symbol + "," + .id' COINGECKO_GET_ASSETS_CMD_OUT >COINGECKO_IDS.tmp
|
|
if [ -s COINGECKO_IDS.tmp ]
|
|
then
|
|
mv COINGECKO_IDS.tmp COINGECKO_IDS
|
|
else
|
|
g_echo_warn "COINGECKO_IDS.tmp has wrong Syntax. - Not updating COINGECKO_IDS $(tail -n 10 COINGECKO_IDS.tmp)"
|
|
return 2
|
|
fi
|
|
fi
|
|
|
|
|
|
# Write file with asset list and ignore marketcap under LARGEST_MARKETCAP
|
|
cat EXCHANGE_GET_ASSETS_CMD_OUT | cut -d"," -f1 | while read f_ASSET
|
|
do
|
|
# ignore marketcap under LARGEST_MARKETCAP
|
|
f_assetwocurrency=$(echo ${f_ASSET} | sed "s/$CURRENCY$//")
|
|
if ! egrep -q "^${f_assetwocurrency}$" SORTMARKETCAP
|
|
then
|
|
#g_echo_note "Ignoring $f_ASSET because of lower marketcap then Top ${LARGEST_MARKETCAP}"
|
|
continue
|
|
fi
|
|
echo ${f_ASSET} >>ASSETS.tmp
|
|
done
|
|
mv ASSETS.tmp ASSETS
|
|
|
|
|
|
## write histfiles by having a look on marketcap
|
|
#>ASSETS_HIGHEST.tmp
|
|
# get alread invested assets
|
|
#f_investedassets_regex=$(cat EXCHANGE_GET_BALANCES_CMD_OUT | cut -d, -f1 | perl -pe 's/^/\^/; s/\n/\|/' | perl -pe 's/\|$//')
|
|
local f_ASSET
|
|
|
|
local f_parallel_arg
|
|
echo -n "parallel -j3 bash -c --" >/tmp/parallel
|
|
for f_ASSET in $(cat ASSETS | egrep -v "${BLACKLIST}")
|
|
do
|
|
#get_asset "${f_ASSET}"
|
|
echo -n " \"get_asset ${f_ASSET}\"" >>/tmp/parallel
|
|
done
|
|
export -f get_asset
|
|
export f_timestamp
|
|
export csv_headline
|
|
. /tmp/parallel
|
|
|
|
# get MSCI World Index for analysis
|
|
echo "wget -q -O - https://www.boerse.de/realtime-kurse/MSCI-World/XC0009692739 | egrep 'itemprop=\"price\" content=\"[0-9]+\.[0-9]+\"' | cut -d\\\" -f6" >MSCI_WORLD_CMD
|
|
g_runcmd g_retrycmd sh MSCI_WORLD_CMD >MSCI_WORLD_CMD_OUT.tmp
|
|
# check output
|
|
if [ -s MSCI_WORLD_CMD_OUT.tmp ] && egrep -q "^[0-9]*\.[0-9]+$" MSCI_WORLD_CMD_OUT.tmp
|
|
then
|
|
if egrep -q "^0\.00$" MSCI_WORLD_CMD_OUT.tmp
|
|
then
|
|
g_echo_note "Ignoring MSCI World $(tail -n 10 MSCI_WORLD_CMD_OUT.tmp) - maybe out of business day"
|
|
else
|
|
mv MSCI_WORLD_CMD_OUT.tmp MSCI_WORLD_CMD_OUT
|
|
fi
|
|
else
|
|
g_echo_warn "MSCI_WORLD_CMD_OUT.tmp has wrong Syntax. - Not updating MSCI WORLD Index $(tail -n 10 MSCI_WORLD_CMD_OUT.tmp)"
|
|
fi
|
|
echo "${f_timestamp},$(cat MSCI_WORLD_CMD_OUT)" >>asset-histories/MSCI-WORLD-INDEX.history.csv
|
|
|
|
|
|
}
|
|
|