Files
dabo/dabo/functions/get_assets.sh

117 lines
5.3 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_marketdata https://www.boerse.de/indizes/Dow-Jones/US2605661048 DOW-JONES-INDEX
get_marketdata https://www.boerse.de/indizes/SundP-500/US78378X1072 SP500-INDEX
get_marketdata https://www.boerse.de/indizes/Nasdaq-100/US6311011026 NASDAQ-INDEX
get_marketdata https://www.investing.com/indices/msci-eafe MSCI-EAFE-INDEX
get_marketdata https://www.investing.com/indices/10-year-treasury-yield 10-YEAR-TREASURY-YIELD-INDEX
get_marketdata https://www.boerse.de/rohstoffe/WTI-Rohoelpreis/XD0015948363 OIL-INVERTED-INDEX
#get_marketdata https://www.boerse.de/aktien/Nvidia-Aktie/US67066G1040 NVIDIA-INDEX
#get_marketdata https://www.boerse.de/aktien/Tesla-Aktie/US88160R1014 TESLA-INDEX
#get_marketdata https://www.boerse.de/aktien/Apple-Aktie/US0378331005 APPLE-INDEX
get_marketdata https://www.boerse.de/realtime-kurse/MSCI-World/XC0009692739 MSCI-WORLD-INDEX
get_marketdata https://www.boerse.de/indizes/DJ-AMER-OIL-und-GAS/XC0006886516 OIL-GAS-INVERTED-INDEX
get_marketdata https://www.boerse.de/fonds/SPDR-SundP-Regional-Banking-ETF/US78464A6982 KRE-BANKING-INDEX
get_marketdata https://www.boerse.de/indizes/Dax/DE0008469008 DAX-INDEX
get_marketdata https://www.investing.com/indices/usdollar DXY-INVERTED-INDEX
get_marketdata https://www.investing.com/economic-calendar/unemployment-rate-300/ US-UNEMPLOYMENT-INDEX
get_marketdata https://www.investing.com/economic-calendar/cpi-733 US-CONSUMER-PRICE-INDEX
}