values, run strategies, fixes

This commit is contained in:
olli 2024-08-25 13:58:33 +02:00
parent 6cf5d8502f
commit 7e5a95aafc
8 changed files with 85 additions and 58 deletions

View File

@ -10,7 +10,7 @@ STOCK_EXCHANGE="NONE"
FEE="0.5" FEE="0.5"
# Interval in seconds - Should not be lower then 300 # Interval in seconds - Should not be lower then 300
INTERVAL="900" INTERVAL="300"
## Currency used for trading ## Currency used for trading
CURRENCY="USDT" CURRENCY="USDT"

View File

@ -17,8 +17,6 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>. # along with dabo. If not, see <http://www.gnu.org/licenses/>.
. /dabo/dabo-prep.sh . /dabo/dabo-prep.sh
### MAIN ### ### MAIN ###
@ -31,12 +29,12 @@ export FULL_LOOP=1
echo $0 | grep -q "dabo-bot\.sh" && BOT=1 echo $0 | grep -q "dabo-bot\.sh" && BOT=1
# cleanup trashlines in asset-histories (possibly generated by kill further of this progress) # cleanup trashlines in asset-histories (possibly generated by kill further of this progress)
find asset-histories -name "*.csv" -type f | while read csv_file #find asset-histories -name "*.csv" -type f | while read csv_file
do #do
csv_timestamp=$(ls --time-style='+%Y%m%d%H%M' -l "${csv_file}" | cut -d" " -f6) # csv_timestamp=$(ls --time-style='+%Y%m%d%H%M' -l "${csv_file}" | cut -d" " -f6)
sed -i "/[0-9]$(date +%Y)-/d" "${csv_file}" # sed -i "/[0-9]$(date +%Y)-/d" "${csv_file}"
touch -t ${csv_timestamp} "${csv_file}" # touch -t ${csv_timestamp} "${csv_file}"
done #done
# run endless loop # run endless loop
@ -47,7 +45,7 @@ do
then then
rm -f firstloop rm -f firstloop
else else
LOOP_INTERVAL=30 # 60s max free coingecko API interval + 30s puffer LOOP_INTERVAL=30
time_to_interval=$((${LOOP_INTERVAL} - $(date +%s) % ${LOOP_INTERVAL})) time_to_interval=$((${LOOP_INTERVAL} - $(date +%s) % ${LOOP_INTERVAL}))
time_to_full_interval=$((${INTERVAL} - $(date +%s) % ${INTERVAL})) time_to_full_interval=$((${INTERVAL} - $(date +%s) % ${INTERVAL}))
# Check for next general interval # Check for next general interval
@ -73,24 +71,25 @@ do
# Timestamp # Timestamp
export f_timestamp=$(g_date_print) export f_timestamp=$(g_date_print)
# get minute interval for find -mmin
INTERVAL_MIN=$(echo "${INTERVAL}/60-1" | bc -l | sed -r 's/^(-?)\./\10./' | cut -d\. -f1)
[ -z "${INTERVAL_MIN}" ] && INTERVAL_MIN=1
####### TODO -> Funktionen überarbeiten ############ ####### TODO -> Funktionen überarbeiten ############
### get general market data #
# Get coingecko data # # get minute interval for find -mmin (used by get_marketdata market_performance
get_coingecko_data # INTERVAL_MIN=$(echo "${INTERVAL}/60-1" | bc -l | sed -r 's/^(-?)\./\10./' | cut -d\. -f1)
# [ -z "${INTERVAL_MIN}" ] && INTERVAL_MIN=1
# Get current MarketData #
get_marketdata # ### get general market data
# # Get coingecko data
# Check the situation on the market # get_coingecko_data
if ! market_performance #
then # # Get current MarketData
f_market_performance=$(cat MARKET_PERFORMANCE_LATEST) # get_marketdata
fi #
# # Check the situation on the market
# if ! market_performance
# then
# f_market_performance=$(cat MARKET_PERFORMANCE_LATEST)
# fi
####### TODO -> Funktionen überarbeiten ENDE ########### ####### TODO -> Funktionen überarbeiten ENDE ###########
@ -115,8 +114,8 @@ do
# Get current positions # Get current positions
[ ${FULL_LOOP} = 1 ] && get_positions || continue [ ${FULL_LOOP} = 1 ] && get_positions || continue
## Buy something? ## Run strategies
#[ ${FULL_LOOP} = 1 ] && check_for_buy [ ${FULL_LOOP} = 1 ] && run_strategies
done done

View File

@ -31,12 +31,14 @@ do
# Reload Config # Reload Config
. ../../dabo-bot.conf . ../../dabo-bot.conf
. ../../dabo-bot.override.conf . ../../dabo-bot.override.conf
# notify failed yahoo downloads
[ "$interval" = "1d" ] && cat *USD_* *ECONOMY* 2>/dev/null | notify.sh -s "Failed Yahoo downloads"
# Timestamp # Timestamp
export f_timestamp=$(g_date_print) export f_timestamp=$(g_date_print)
# get candles and indicators # get candles and indicators
get_ohlcv-candles $interval get_ohlcv-candles $interval
[ -n "$seconds" ] && sleeptime=$(( ( ($seconds - $(TZ=UTC printf "%(%s)T") % $seconds) % $seconds + 2 ))) [ -n "$seconds" ] && sleeptime=$(( ( ($seconds - $(TZ=UTC printf "%(%s)T") % $seconds) % $seconds + 2 )))
#[[ $interval = 4h ]] && #[[ $interval = 4h ]] && sleeptime=??
[ "$interval" = "1d" ] && sleeptime=$(($(TZ=UTC date +%s -d "tomorrow 0:00") - $(date +%s) +2 )) [ "$interval" = "1d" ] && sleeptime=$(($(TZ=UTC date +%s -d "tomorrow 0:00") - $(date +%s) +2 ))
[ "$interval" = "1w" ] && sleeptime=$(($(TZ=UTC date +%s -d "next monday 0:00") - $(date +%s) +2 )) [ "$interval" = "1w" ] && sleeptime=$(($(TZ=UTC date +%s -d "next monday 0:00") - $(date +%s) +2 ))
g_echo_note "Waiting $sleeptime seconds until next run" g_echo_note "Waiting $sleeptime seconds until next run"

View File

@ -136,7 +136,7 @@ function currency_converter {
return $? return $?
fi fi
fi fi
g_echo_warn "didn't find rate for ${f_currency}-${f_currency_target} - '${FUNCNAME} $@'" g_echo_note "didn't find rate for ${f_currency}-${f_currency_target} - '${FUNCNAME} $@'"
return 1 return 1
fi fi

View File

@ -86,6 +86,7 @@ function get_symbols_ticker {
g_array CCXT_TICKERS-$STOCK_EXCHANGE f_tickers_array_ref g_array CCXT_TICKERS-$STOCK_EXCHANGE f_tickers_array_ref
local f_ticker f_symbol f_price local f_ticker f_symbol f_price
declare -Ag f_tickers_array declare -Ag f_tickers_array
declare -Ag v
for f_ticker in "${f_tickers_array_ref[@]}" for f_ticker in "${f_tickers_array_ref[@]}"
do do
f_symbol=${f_ticker%%:*} f_symbol=${f_ticker%%:*}
@ -94,6 +95,7 @@ function get_symbols_ticker {
f_price=${f_ticker/*,/} f_price=${f_ticker/*,/}
g_num_exponential2normal $f_price && f_price=$g_num_exponential2normal_result g_num_exponential2normal $f_price && f_price=$g_num_exponential2normal_result
f_tickers_array[$f_symbol]=$f_price f_tickers_array[$f_symbol]=$f_price
v[${f_symbol}_price]=$f_price
done done
fi fi

View File

@ -19,6 +19,7 @@
function get_values { function get_values {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_assets="$@" local f_assets="$@"
f_assets=${f_assets//:$CURRENCY/} f_assets=${f_assets//:$CURRENCY/}
@ -36,7 +37,7 @@ function get_values {
fi fi
done done
# get current prices # get current prices from exchange
get_symbols_ticker get_symbols_ticker
# get values from csv files # get values from csv files
f_first=true f_first=true
@ -52,31 +53,50 @@ function get_values {
f_histfile="asset-histories/${f_asset}.history.${f_time}.csv" f_histfile="asset-histories/${f_asset}.history.${f_time}.csv"
if ! [ -s "$f_histfile" ] if ! [ -s "$f_histfile" ]
then then
g_echo_warn "file $f_histfile emty or does not exist" g_echo_note "file $f_histfile emty or does not exist"
f_return=1 f_return=1
continue continue
fi 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" 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}" 1 "$f_columns" g_read_csv "${f_histfile}" 2 "$f_columns"
done done
# read current levels and price # read current levels
f_levelsfile="asset-histories/${f_asset}.history.csv.levels" #v[${f_asset}_price]=${f_tickers_array[$f_asset]}
if [ "$f_first" = "true" ] for f_time in 1w 1d
do
f_levelsfile="asset-histories/${f_asset}.history.${f_time}.csv.levels"
if [ -s "$f_levelsfile" ]
then then
[ -s "$f_levelsfile" ] && v_levels="$(cat "$f_levelsfile")" # get levels
v_price=${f_tickers_array[$f_asset]} g_array "$f_levelsfile" f_levels " "
else v[${f_asset}_levels_$f_time]="${f_levels[*]}"
[ -s "$f_levelsfile" ] && declare -g v_${f_asset}_levels="$(cat "$f_levelsfile")"
[[ $f_asset =~ ECONOMY ]] || declare -g v_${f_asset}_price="${f_tickers_array[$f_asset]}" # add current price and sort
f_levels+=("${v[${f_asset}_price]}")
IFS=$'\n' f_levels_sorted=($(sort -n <<<"${f_levels[*]}"))
# 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 fi
done
fi
done
unset f_first unset f_first
done done
for i in "${!v[@]}"
set 2>&1 | grep ^v_ | grep -v ^v_csv_array_associative >values do
echo "\${v[$i]}"
done | sort >values.new
mv values.new values
return $f_return return $f_return
} }

View File

@ -18,26 +18,28 @@
# along with dabo. If not, see <http://www.gnu.org/licenses/>. # along with dabo. If not, see <http://www.gnu.org/licenses/>.
function strategy { function run_strategies {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_strategy
unset s_score unset s_score
unset s_SYMBOLS unset s_SYMBOLS
#find
#. "${f_strategy}" || return 1
get_values
get_symbols_ticker get_symbols_ticker
get_values ${f_symbols_array_trade[*]}
for f_symbol in "${f_symbols_array_trade[@]}" for f_strategy in $(find /dabo/strategies -type f -name "*strategy*")
do do
echo $f_symbol if ! bash -n "${f_strategy}" >$g_tmp/strat_bash_error 2>&1
get_values $f_symbol then
g_echo_error "Error in ${f_strategy} $(cat $g_tmp/strat_bash_error)"
continue
fi
g_echo_note "Runnign strategy ${f_strategy}"
. "${f_strategy}" || g_echo_warn "Failed ${f_strategy}"
done done
echo "Score: $s_score"
echo $s_score_hist
} }

View File

@ -293,3 +293,5 @@ services:
cpus: '1' cpus: '1'
memory: 128M memory: 128M