Files
dabo/dabo/functions/get_values.sh
2024-09-02 14:51:46 +02:00

106 lines
3.4 KiB
Bash

#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_values {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_assets="$@"
f_assets=${f_assets//:$CURRENCY/}
f_assets=${f_assets//\//}
local f_eco_asset f_eco_assets f_asset f_time f_prefix f_histfile f_columns f_return f_levelsfile f_tmp_levels f_first
for f_eco_asset in $ECO_ASSETS
do
if [ -z "$f_eco_assets" ]
then
f_eco_assets="ECONOMY-${f_eco_asset}"
else
f_eco_assets="$f_eco_assets ECONOMY-${f_eco_asset}"
fi
done
# get current prices from exchange
get_symbols_ticker
# get values from csv files
f_first=true
for f_asset in $f_assets BTC${CURRENCY} $f_eco_assets
do
# read latest ohlcv data and indicators per timeframe to vars
for f_time in 5m 15m 1h 4h 1d 1w
do
f_prefix="${f_asset}_${f_time}_"
[ "$f_first" = "true" ] && f_prefix="${f_time}_"
f_prefix=${f_prefix//-/_}
f_histfile="asset-histories/${f_asset}.history.${f_time}.csv"
if ! [ -s "$f_histfile" ]
then
g_echo_note "file $f_histfile emty or does not exist"
f_return=1
continue
fi
f_columns="${f_prefix}date,${f_prefix}open,${f_prefix}high,${f_prefix}low,${f_prefix}close,${f_prefix}volume,${f_prefix}change,${f_prefix}ath,${f_prefix}ema12,${f_prefix}ema26,${f_prefix}ema50,${f_prefix}ema100,${f_prefix}ema200,${f_prefix}ema400,${f_prefix}ema800,${f_prefix}rsi5,${f_prefix}rsi14,${f_prefix}rsi21,${f_prefix}macd,${f_prefix}macd_ema9_signal,${f_prefix}macd_histogram,${f_prefix}macd_histogram_signal,${f_prefix}macd_histogram_max,${f_prefix}macd_histogram_strength"
g_read_csv "${f_histfile}" 2 "$f_columns"
done
# read current levels
#v[${f_asset}_price]=${f_tickers_array[$f_asset]}
for f_time in 1w 1d
do
f_levelsfile="asset-histories/${f_asset}.history.${f_time}.csv.levels"
if [ -s "$f_levelsfile" ]
then
# get levels
read -r -a f_levels <"$f_levelsfile"
v[${f_asset}_levels_$f_time]="${f_levels[*]}"
# add current price and sort
f_levels+=("${v[${f_asset}_price]}")
oldIFS="$IFS"
IFS=$'\n' f_levels_sorted=($(sort -n <<<"${f_levels[*]}"))
IFS="$oldIFS"
# find current price and +- one for upper lower price
for ((i=0; i<${#f_levels_sorted[@]}; i++)); do
if [ "${f_levels_sorted[$i]}" = "${v[${f_asset}_price]}" ]
then
v[${f_asset}_levels_${f_time}_next_up]=${f_levels_sorted[i+1]}
v[${f_asset}_levels_${f_time}_next_down]=${f_levels_sorted[i-1]}
break
fi
done
fi
done
unset f_first
done
for i in "${!v[@]}"
do
echo "\${v[$i]} = ${v[$i]}"
done | sort >values.new
mv values.new values
return $f_return
}