150 lines
4.6 KiB
Bash
150 lines
4.6 KiB
Bash
function get_indicators_all {
|
|
|
|
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
|
|
|
|
local f_last_intervals="$1"
|
|
|
|
local f_histfile f_symbol
|
|
|
|
shopt -s nullglob
|
|
|
|
# find all hitory files
|
|
get_symbols_ticker
|
|
for f_symbol in "${f_symbols_array_trade[@]}"
|
|
do
|
|
f_symbol=${f_symbol%%:*}
|
|
f_symbol=${f_symbol//\/}
|
|
|
|
for f_histfile in "asset-histories/${f_symbol}.history."[0-5][5dhwm]*.csv
|
|
do
|
|
if [ -s "$f_histfile" ]
|
|
then
|
|
# check for already running jobs
|
|
if [ -s "${f_histfile}.fetching" ]
|
|
then
|
|
g_echo_note "Fetching active on ${f_histfile}"
|
|
continue
|
|
fi
|
|
if [ -s "${f_histfile}.indicators-calculating" ]
|
|
then
|
|
g_echo_note "Indicators-Calculating already active on ${f_histfile}"
|
|
continue
|
|
fi
|
|
|
|
printf '%(%Y-%m-%d %H:%M:%S)T' >"${f_histfile}.indicators-calculating"
|
|
get_indicators "${f_histfile}" ${f_last_intervals} && printf '%(%Y-%m-%d %H:%M:%S)T' >>"$f_histfile.indicators-calculated"
|
|
rm -f "${f_histfile}.indicators-calculating"
|
|
|
|
fi
|
|
done
|
|
done
|
|
|
|
}
|
|
|
|
|
|
function get_indicators {
|
|
|
|
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
|
|
local f_histfile="$1"
|
|
local f_last_intervals="$2"
|
|
local f_line
|
|
|
|
# history
|
|
local f_columns="date,open,high,low,close,volume,change,ath,ema12,ema26,ema50,ema100,ema200,ema400,ema800,rsi5,rsi14,rsi21,macd,macd_ema9_signal,macd_histogram,macd_histogram_signal,macd_histogram_max,macd_histogram_strength"
|
|
local f_emas="12 26 50 100 200 400 800"
|
|
local f_rsis="5 14 21"
|
|
local f_ema f_change f_changed f_line f_valid_data f_ath
|
|
local f_columns_space="${f_columns//,/ }"
|
|
g_read_csv "${f_histfile}" "${f_last_intervals}" "$f_columns"
|
|
for ((i=0; i<=${#g_csv_array[@]}-1; i++))
|
|
do
|
|
|
|
if [ -z "${v_csv_array_associative[date_${i}]}" ]
|
|
then
|
|
g_echo_note "No data $f_histfile:${v_csv_array_associative[date_${i}]}"
|
|
return 0
|
|
fi
|
|
#g_echo_note "=== $0 for $f_histfile:${v_csv_array_associative[date_${i}]},$f_histfile:${v_csv_array_associative[close_${i}]}"
|
|
|
|
# get previous position
|
|
p=$((i-1))
|
|
|
|
### check for unfilled fields
|
|
f_change=""
|
|
|
|
# check for missing percentage change
|
|
if [ -z "${v_csv_array_associative[change_${i}]}" ]
|
|
then
|
|
if ! [ $p -lt 0 ]
|
|
then
|
|
#echo "g_percentage-diff ${v_csv_array_associative[close_${p}]} ${v_csv_array_associative[close_${i}]}"
|
|
g_percentage-diff ${v_csv_array_associative[close_${p}]} ${v_csv_array_associative[close_${i}]} && f_change=1
|
|
v_csv_array_associative[change_${i}]=${g_percentage_diff_result}
|
|
fi
|
|
fi
|
|
|
|
# ath (all-time-high) of present data
|
|
if [ -z "${v_csv_array_associative[ath_${p}]}" ]
|
|
then
|
|
# define max for the first time
|
|
v_csv_array_associative[ath_${i}]=${v_csv_array_associative[high_${i}]}
|
|
else
|
|
#echo "g_num_is_higher ${v_csv_array_associative[high_${i}]} ${v_csv_array_associative[ath_${p}]}"
|
|
if g_num_is_higher ${v_csv_array_associative[high_${i}]} ${v_csv_array_associative[ath_${p}]}
|
|
then
|
|
v_csv_array_associative[ath_${i}]=${v_csv_array_associative[high_${i}]}
|
|
else
|
|
v_csv_array_associative[ath_${i}]=${v_csv_array_associative[ath_${p}]}
|
|
fi
|
|
fi
|
|
|
|
# check for missing EMAs
|
|
for f_ema_column in $f_emas
|
|
do
|
|
# check for enough values/lines to calculate EMA
|
|
[ $i -ge $f_ema_column ] || continue
|
|
# calculate EMA
|
|
[ -z "${v_csv_array_associative[ema${f_ema_column}_${i}]}" ] && calc_ema ${f_ema_column} close && f_change=1
|
|
done
|
|
|
|
# check for missing RSI
|
|
for f_rsi_column in $f_rsis
|
|
do
|
|
# check for enough values/lines to calculate RSI
|
|
[ $i -ge $f_rsi_column ] || continue
|
|
# calculate RSI
|
|
[ -z "${v_csv_array_associative[rsi${f_rsi_column}_${i}]}" ] && calc_rsi ${f_rsi_column} change && f_change=1
|
|
done
|
|
|
|
# check for missing macd
|
|
[ $i -ge 26 ] && [ -z "${v_csv_array_associative[macd_${i}]}" ] && calc_macd && f_change=1
|
|
|
|
# write to file if change is provided
|
|
if [ -n "$f_change" ]
|
|
then
|
|
# find line by date
|
|
f_line_date="${v_csv_array_associative[date_${i}]}"
|
|
oldIFS=$IFS
|
|
IFS=,
|
|
f_line=""
|
|
# build line
|
|
for f_column in $f_columns
|
|
do
|
|
if [ -z "$f_line" ]
|
|
then
|
|
f_line="${v_csv_array_associative[${f_column}_${i}]}"
|
|
else
|
|
f_line="$f_line,${v_csv_array_associative[${f_column}_${i}]}"
|
|
fi
|
|
done
|
|
g_echo_note "Changing values with date ${v_csv_array_associative[date_${i}]} in \"${f_histfile}\""
|
|
# replace line by date
|
|
sed -i "s/$f_line_date,.*/$f_line/" "$f_histfile"
|
|
IFS=$oldIFS
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|