values, run strategies, fixes
This commit is contained in:
parent
6cf5d8502f
commit
7e5a95aafc
@ -10,7 +10,7 @@ STOCK_EXCHANGE="NONE"
|
||||
FEE="0.5"
|
||||
|
||||
# Interval in seconds - Should not be lower then 300
|
||||
INTERVAL="900"
|
||||
INTERVAL="300"
|
||||
|
||||
## Currency used for trading
|
||||
CURRENCY="USDT"
|
||||
|
@ -17,8 +17,6 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
|
||||
. /dabo/dabo-prep.sh
|
||||
|
||||
### MAIN ###
|
||||
@ -31,12 +29,12 @@ export FULL_LOOP=1
|
||||
echo $0 | grep -q "dabo-bot\.sh" && BOT=1
|
||||
|
||||
# cleanup trashlines in asset-histories (possibly generated by kill further of this progress)
|
||||
find asset-histories -name "*.csv" -type f | while read csv_file
|
||||
do
|
||||
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}"
|
||||
touch -t ${csv_timestamp} "${csv_file}"
|
||||
done
|
||||
#find asset-histories -name "*.csv" -type f | while read csv_file
|
||||
#do
|
||||
# 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}"
|
||||
# touch -t ${csv_timestamp} "${csv_file}"
|
||||
#done
|
||||
|
||||
|
||||
# run endless loop
|
||||
@ -47,7 +45,7 @@ do
|
||||
then
|
||||
rm -f firstloop
|
||||
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_full_interval=$((${INTERVAL} - $(date +%s) % ${INTERVAL}))
|
||||
# Check for next general interval
|
||||
@ -73,24 +71,25 @@ do
|
||||
# Timestamp
|
||||
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 ############
|
||||
### get general market data
|
||||
# Get coingecko data
|
||||
get_coingecko_data
|
||||
|
||||
# Get current MarketData
|
||||
get_marketdata
|
||||
|
||||
# Check the situation on the market
|
||||
if ! market_performance
|
||||
then
|
||||
f_market_performance=$(cat MARKET_PERFORMANCE_LATEST)
|
||||
fi
|
||||
#
|
||||
# # get minute interval for find -mmin (used by get_marketdata market_performance
|
||||
# INTERVAL_MIN=$(echo "${INTERVAL}/60-1" | bc -l | sed -r 's/^(-?)\./\10./' | cut -d\. -f1)
|
||||
# [ -z "${INTERVAL_MIN}" ] && INTERVAL_MIN=1
|
||||
#
|
||||
# ### get general market data
|
||||
# # Get coingecko data
|
||||
# get_coingecko_data
|
||||
#
|
||||
# # Get current MarketData
|
||||
# get_marketdata
|
||||
#
|
||||
# # Check the situation on the market
|
||||
# if ! market_performance
|
||||
# then
|
||||
# f_market_performance=$(cat MARKET_PERFORMANCE_LATEST)
|
||||
# fi
|
||||
####### TODO -> Funktionen überarbeiten ENDE ###########
|
||||
|
||||
|
||||
@ -115,8 +114,8 @@ do
|
||||
# Get current positions
|
||||
[ ${FULL_LOOP} = 1 ] && get_positions || continue
|
||||
|
||||
## Buy something?
|
||||
#[ ${FULL_LOOP} = 1 ] && check_for_buy
|
||||
## Run strategies
|
||||
[ ${FULL_LOOP} = 1 ] && run_strategies
|
||||
|
||||
done
|
||||
|
||||
|
@ -31,12 +31,14 @@ do
|
||||
# Reload Config
|
||||
. ../../dabo-bot.conf
|
||||
. ../../dabo-bot.override.conf
|
||||
# notify failed yahoo downloads
|
||||
[ "$interval" = "1d" ] && cat *USD_* *ECONOMY* 2>/dev/null | notify.sh -s "Failed Yahoo downloads"
|
||||
# Timestamp
|
||||
export f_timestamp=$(g_date_print)
|
||||
# get candles and indicators
|
||||
get_ohlcv-candles $interval
|
||||
[ -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" = "1w" ] && sleeptime=$(($(TZ=UTC date +%s -d "next monday 0:00") - $(date +%s) +2 ))
|
||||
g_echo_note "Waiting $sleeptime seconds until next run"
|
||||
|
@ -136,7 +136,7 @@ function currency_converter {
|
||||
return $?
|
||||
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
|
||||
fi
|
||||
|
||||
|
@ -86,6 +86,7 @@ function get_symbols_ticker {
|
||||
g_array CCXT_TICKERS-$STOCK_EXCHANGE f_tickers_array_ref
|
||||
local f_ticker f_symbol f_price
|
||||
declare -Ag f_tickers_array
|
||||
declare -Ag v
|
||||
for f_ticker in "${f_tickers_array_ref[@]}"
|
||||
do
|
||||
f_symbol=${f_ticker%%:*}
|
||||
@ -94,6 +95,7 @@ function get_symbols_ticker {
|
||||
f_price=${f_ticker/*,/}
|
||||
g_num_exponential2normal $f_price && f_price=$g_num_exponential2normal_result
|
||||
f_tickers_array[$f_symbol]=$f_price
|
||||
v[${f_symbol}_price]=$f_price
|
||||
done
|
||||
fi
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
|
||||
function get_values {
|
||||
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
|
||||
|
||||
local f_assets="$@"
|
||||
f_assets=${f_assets//:$CURRENCY/}
|
||||
@ -36,7 +37,7 @@ function get_values {
|
||||
fi
|
||||
done
|
||||
|
||||
# get current prices
|
||||
# get current prices from exchange
|
||||
get_symbols_ticker
|
||||
# get values from csv files
|
||||
f_first=true
|
||||
@ -52,31 +53,50 @@ function get_values {
|
||||
f_histfile="asset-histories/${f_asset}.history.${f_time}.csv"
|
||||
if ! [ -s "$f_histfile" ]
|
||||
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
|
||||
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}" 1 "$f_columns"
|
||||
g_read_csv "${f_histfile}" 2 "$f_columns"
|
||||
done
|
||||
|
||||
# read current levels and price
|
||||
f_levelsfile="asset-histories/${f_asset}.history.csv.levels"
|
||||
if [ "$f_first" = "true" ]
|
||||
# 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
|
||||
[ -s "$f_levelsfile" ] && v_levels="$(cat "$f_levelsfile")"
|
||||
v_price=${f_tickers_array[$f_asset]}
|
||||
else
|
||||
[ -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]}"
|
||||
# get levels
|
||||
g_array "$f_levelsfile" f_levels " "
|
||||
v[${f_asset}_levels_$f_time]="${f_levels[*]}"
|
||||
|
||||
# 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
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
unset f_first
|
||||
|
||||
done
|
||||
|
||||
|
||||
set 2>&1 | grep ^v_ | grep -v ^v_csv_array_associative >values
|
||||
for i in "${!v[@]}"
|
||||
do
|
||||
echo "\${v[$i]}"
|
||||
done | sort >values.new
|
||||
mv values.new values
|
||||
|
||||
return $f_return
|
||||
}
|
||||
|
@ -18,26 +18,28 @@
|
||||
# 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_SYMBOLS
|
||||
|
||||
#find
|
||||
#. "${f_strategy}" || return 1
|
||||
|
||||
get_values
|
||||
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
|
||||
echo $f_symbol
|
||||
get_values $f_symbol
|
||||
if ! bash -n "${f_strategy}" >$g_tmp/strat_bash_error 2>&1
|
||||
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
|
||||
|
||||
|
||||
echo "Score: $s_score"
|
||||
echo $s_score_hist
|
||||
|
||||
}
|
||||
|
@ -293,3 +293,5 @@ services:
|
||||
cpus: '1'
|
||||
memory: 128M
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user