fix: lower intervals in raw files

This commit is contained in:
olli 2024-02-07 09:46:44 +01:00
parent 212cbd771b
commit e3670179ec
2 changed files with 110 additions and 112 deletions

View File

@ -103,8 +103,8 @@ do
# Get current assets # Get current assets
get_assets || continue get_assets || continue
# stop here if no full loop ##### Sell something? ####
[ ${FULL_LOOP} == 0 ] && continue check_for_sell
# Get current balances # Get current balances
get_balances || continue get_balances || continue
@ -115,8 +115,8 @@ do
f_market_performance=$(cat MARKET_PERFORMANCE_LATEST) f_market_performance=$(cat MARKET_PERFORMANCE_LATEST)
fi fi
##### Sell something? #### # stop here if no full loop
check_for_sell [ ${FULL_LOOP} == 0 ] && continue
##### Buy something? #### ##### Buy something? ####
check_for_buy check_for_buy

View File

@ -7,118 +7,116 @@ function get_asset {
local f_ASSET_HIST_FILE="asset-histories/${f_ASSET}.history-raw.csv" 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}" [ -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}"
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 then
local f_line="${f_timestamp},$(egrep "^${f_ASSET}," EXCHANGE_GET_ASSETS_CMD_OUT | cut -d, -f2)" g_echo_note "${f_ASSET_HIST_FILE}: price seems not to change - ignoring"
echo "${f_line}" >>${f_ASSET_HIST_FILE} return 0
fi
local f_linecount=0 [ ${FULL_LOOP} == 0 ] && return 0
local f_last_price=0 grep -q "^$(echo "${f_timestamp}" | cut -d: -f1,2)" "${f_ASSET_HIST_FILE}" || return 0
local f_lines="$(tail -n 51 "${f_ASSET_HIST_FILE}" | wc -l)" f_ASSET_HIST_FILE="asset-histories/${f_ASSET}.history.csv"
if find "${f_ASSET_HIST_FILE}" -mmin -${INTERVAL_MIN} | grep -q "${f_ASSET_HIST_FILE}"
then
g_echo_note "${f_ASSET_HIST_FILE} already downloaded in the last ${INTERVAL_MIN} minutes"
return 0
fi
for f_price in $(tail -n 50 "${f_ASSET_HIST_FILE}" | grep "^[0-9]" | cut -d, -f2) # headline
do #[ -s "${f_ASSET_HIST_FILE}" ] || echo "${csv_headline}" >"${f_ASSET_HIST_FILE}"
if [ "${f_last_price}" == "${f_price}" ] if [ -s "${f_ASSET_HIST_FILE}" ]
then then
continue sed -i -e 1c"$csv_headline" "${f_ASSET_HIST_FILE}"
fi else
let "f_linecount+=1" echo "$csv_headline" >"${f_ASSET_HIST_FILE}"
f_last_price=${f_price} fi
done
if [ ${f_linecount} -le 3 ] && [ ${f_lines} -ge 50 ] # date and price
then echo -n "${f_line}" >>${f_ASSET_HIST_FILE}
g_echo_note "${f_ASSET_HIST_FILE}: price seems not to change - ignoring"
return 0
fi
[ ${FULL_LOOP} == 0 ] && return 0 # 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)
g_percentage-diff ${f_last_price} ${f_price}
local f_price_change=${g_percentage_diff_result}
else
local f_price_change=""
fi
echo -n ",${f_price_change}" >>"${f_ASSET_HIST_FILE}"
f_ASSET_HIST_FILE="asset-histories/${f_ASSET}.history.csv" # calculate macd and rsi
if find "${f_ASSET_HIST_FILE}" -mmin -${INTERVAL_MIN} | grep -q "${f_ASSET_HIST_FILE}" get_macd_indicator ${f_ASSET_HIST_FILE}
then get_rsi_indicator ${f_ASSET_HIST_FILE} 5
g_echo_note "${f_ASSET_HIST_FILE} already downloaded in the last ${INTERVAL_MIN} minutes" get_rsi_indicator ${f_ASSET_HIST_FILE} 14
return 0 get_rsi_indicator ${f_ASSET_HIST_FILE} 21
fi 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
# headline # get coingecko price change
#[ -s "${f_ASSET_HIST_FILE}" ] || echo "${csv_headline}" >"${f_ASSET_HIST_FILE}" local f_asset=$(echo ${f_ASSET} | sed "s/${CURRENCY}\$//" | tr '[:upper:]' '[:lower:]')
if [ -s "${f_ASSET_HIST_FILE}" ] echo -n ,$(jq -r ".[] |select(.symbol==\"${f_asset}\")|\"\\(.price_change_percentage_24h_in_currency)\"" COINGECKO_GET_ASSETS_CMD_OUT) >>${f_ASSET_HIST_FILE}
then echo -n ,$(jq -r ".[] |select(.symbol==\"${f_asset}\")|\"\\(.price_change_percentage_7d_in_currency)\"" COINGECKO_GET_ASSETS_CMD_OUT) >>${f_ASSET_HIST_FILE}
sed -i -e 1c"$csv_headline" "${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}
else echo -n ,$(jq -r ".[] |select(.symbol==\"${f_asset}\")|\"\\(.price_change_percentage_30d_in_currency)\"" COINGECKO_GET_ASSETS_CMD_OUT) >>${f_ASSET_HIST_FILE}
echo "$csv_headline" >"${f_ASSET_HIST_FILE}" echo -n ,$(jq -r ".[] |select(.symbol==\"${f_asset}\")|\"\\(.price_change_percentage_1y_in_currency)\"" COINGECKO_GET_ASSETS_CMD_OUT) >>${f_ASSET_HIST_FILE}
fi echo -n ,$(jq -r ".[] |select(.symbol==\"${f_asset}\")|\"\\(.market_cap_change_percentage_24h)\"" COINGECKO_GET_ASSETS_CMD_OUT) >>${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)
g_percentage-diff ${f_last_price} ${f_price}
local f_price_change=${g_percentage_diff_result}
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}
echo -n ,$(jq -r ".[] |select(.symbol==\"${f_asset}\")|\"\\(.price_change_percentage_1y_in_currency)\"" COINGECKO_GET_ASSETS_CMD_OUT) >>${f_ASSET_HIST_FILE}
echo -n ,$(jq -r ".[] |select(.symbol==\"${f_asset}\")|\"\\(.market_cap_change_percentage_24h)\"" COINGECKO_GET_ASSETS_CMD_OUT) >>${f_ASSET_HIST_FILE}
# range and fibonacci # range and fibonacci
if ! get_range ${f_ASSET_HIST_FILE} if ! get_range ${f_ASSET_HIST_FILE}
then then
local f_oldrange=$(tail -n2 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f24,25,26,27,28,29,30,31,32,33,34,35) local f_oldrange=$(tail -n2 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f24,25,26,27,28,29,30,31,32,33,34,35)
#g_echo_note "Taking old range ${f_oldrange}" #g_echo_note "Taking old range ${f_oldrange}"
echo -n ",${f_oldrange}" >>$f_ASSET_HIST_FILE echo -n ",${f_oldrange}" >>$f_ASSET_HIST_FILE
fi
# Calculate EMA 50:36 100:37 200:38 800:39
local f_calcemanumcolumn
for f_calcemanumcolumn in 50:36 100:37 200:38 800:39
do
local f_calcema=$(echo ${f_calcemanumcolumn} | cut -d: -f1)
local f_caclemacolumn=$(echo ${f_calcemanumcolumn} | cut -d: -f2)
local f_last_ema="$(tail -n2 "${f_ASSET_HIST_FILE}" | head -n1 | grep "^[0-9]" | cut -d, -f${f_caclemacolumn})"
if [ -z "${f_last_ema}" ] || [ -z "${f_price}" ]
then
get_ema "${f_ASSET_HIST_FILE}" 2 ${f_calcema}
else
get_ema "${f_ASSET_HIST_FILE}" 2 ${f_calcema} "${f_last_ema}" "${f_price}"
fi
if [ -z "${f_ema}" ]
then
echo -n "," >>"${f_ASSET_HIST_FILE}"
else
echo -n ",${f_ema}" >>"${f_ASSET_HIST_FILE}"
fi
done
# get coingecko price
echo -n ,$(jq -r ".[] |select(.symbol==\"${f_asset}\")|\"\\(.current_price)\"" COINGECKO_GET_ASSETS_CMD_OUT) >>${f_ASSET_HIST_FILE}
# end with newline
echo "" >>${f_ASSET_HIST_FILE}
fi fi
# Calculate EMA 50:36 100:37 200:38 800:39
local f_calcemanumcolumn
for f_calcemanumcolumn in 50:36 100:37 200:38 800:39
do
local f_calcema=$(echo ${f_calcemanumcolumn} | cut -d: -f1)
local f_caclemacolumn=$(echo ${f_calcemanumcolumn} | cut -d: -f2)
local f_last_ema="$(tail -n2 "${f_ASSET_HIST_FILE}" | head -n1 | grep "^[0-9]" | cut -d, -f${f_caclemacolumn})"
if [ -z "${f_last_ema}" ] || [ -z "${f_price}" ]
then
get_ema "${f_ASSET_HIST_FILE}" 2 ${f_calcema}
else
get_ema "${f_ASSET_HIST_FILE}" 2 ${f_calcema} "${f_last_ema}" "${f_price}"
fi
if [ -z "${f_ema}" ]
then
echo -n "," >>"${f_ASSET_HIST_FILE}"
else
echo -n ",${f_ema}" >>"${f_ASSET_HIST_FILE}"
fi
done
# get coingecko price
echo -n ,$(jq -r ".[] |select(.symbol==\"${f_asset}\")|\"\\(.current_price)\"" COINGECKO_GET_ASSETS_CMD_OUT) >>${f_ASSET_HIST_FILE}
# end with newline
echo "" >>${f_ASSET_HIST_FILE}
} }