function get_asset { g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" local f_ASSET="$1" # write asset hist file with macd and rsi local f_ASSET_HIST_FILE="asset-histories/${f_ASSET}.history-raw.csv" [ -f "${f_ASSET_HIST_FILE}" ] || echo "Date and Time,Price" >"${f_ASSET_HIST_FILE}" if ! grep -q "^$(echo "${f_timestamp}" | cut -d: -f1,2)" "${f_ASSET_HIST_FILE}" then local f_line="${f_timestamp},$(egrep "^${f_ASSET}," EXCHANGE_GET_ASSETS_CMD_OUT | cut -d, -f2)" echo "${f_line}" >>${f_ASSET_HIST_FILE} local f_linecount=0 local f_last_price=0 local f_lines="$(tail -n 51 "${f_ASSET_HIST_FILE}" | wc -l)" for f_price in $(tail -n 50 "${f_ASSET_HIST_FILE}" | grep "^[0-9]" | cut -d, -f2) do if [ "$f_last_price" == "$f_price" ] then continue fi let "f_linecount+=1" f_last_price=$f_price done if [ ${f_linecount} -le 3 ] && [ ${f_lines} -ge 50 ] then g_echo_note "${f_ASSET_HIST_FILE}: price seems not to change - ignoring" return 0 fi f_ASSET_HIST_FILE="asset-histories/${f_ASSET}.history.csv" if [ ${f_linecount} -lt 30 ] && [ ${f_lines} -ge 50 ] then g_echo_note "${f_ASSET_HIST_FILE}: set price to 5 minute period" if ! echo "${f_timestamp}" | egrep -q ":[0-5]0:|:[0-5]5:" then return 0 fi fi # headline [ -s "${f_ASSET_HIST_FILE}" ] || echo 'Date and Time,Price,Price Change,EMA12,EMA26,MACD,EMA9 MACD (Signal),MACD Histogram,MACD Signal,RSI5,RSI14,RSI21,RSI720,RSI60,RSI120,RSI240,RSI420,Price Change 24h,Price Change 7d,Price Change 14d,Price Change 30d' >"${f_ASSET_HIST_FILE}" # date and price echo -n "${f_line}" >>${f_ASSET_HIST_FILE} # calculate price change percentage f_last_price=$(tail -n2 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f2) if echo $f_last_price | grep -q "^[0-9]" then f_price=$(tail -n1 ${f_ASSET_HIST_FILE} | cut -d, -f2) local f_price_change=$(g_percentage-diff ${f_last_price} ${f_price}) else local f_price_change="" fi echo -n ",${f_price_change}" >>"${f_ASSET_HIST_FILE}" # calculate macd and rsi get_macd_indicator ${f_ASSET_HIST_FILE} get_rsi_indicator ${f_ASSET_HIST_FILE} 5 get_rsi_indicator ${f_ASSET_HIST_FILE} 14 get_rsi_indicator ${f_ASSET_HIST_FILE} 21 get_rsi_indicator ${f_ASSET_HIST_FILE} 720 get_rsi_indicator ${f_ASSET_HIST_FILE} 60 get_rsi_indicator ${f_ASSET_HIST_FILE} 120 get_rsi_indicator ${f_ASSET_HIST_FILE} 240 get_rsi_indicator ${f_ASSET_HIST_FILE} 480 # get coingecko price change local f_asset=$(echo ${f_ASSET} | sed "s/${CURRENCY}\$//" | tr '[:upper:]' '[:lower:]') echo -n ,$(jq -r ".[] |select(.symbol==\"${f_asset}\")|\"\\(.price_change_percentage_24h_in_currency)\"" COINGECKO_GET_ASSETS_CMD_OUT) >>${f_ASSET_HIST_FILE} echo -n ,$(jq -r ".[] |select(.symbol==\"${f_asset}\")|\"\\(.price_change_percentage_7d_in_currency)\"" COINGECKO_GET_ASSETS_CMD_OUT) >>${f_ASSET_HIST_FILE} echo -n ,$(jq -r ".[] |select(.symbol==\"${f_asset}\")|\"\\(.price_change_percentage_14d_in_currency)\"" COINGECKO_GET_ASSETS_CMD_OUT) >>${f_ASSET_HIST_FILE} echo -n ,$(jq -r ".[] |select(.symbol==\"${f_asset}\")|\"\\(.price_change_percentage_30d_in_currency)\"" COINGECKO_GET_ASSETS_CMD_OUT) >>${f_ASSET_HIST_FILE} # end with newline echo "" >>${f_ASSET_HIST_FILE} fi }