Compare commits

...

2 Commits

Author SHA1 Message Date
7e5a95aafc values, run strategies, fixes 2024-08-25 13:58:33 +02:00
6cf5d8502f doc update vars 2024-08-25 11:49:02 +02:00
9 changed files with 131 additions and 154 deletions

142
README.md
View File

@ -218,14 +218,22 @@ and add Key on your matrix-Server to the authorized_keys of the matrix-User
Create Secrets file for your API Key(s)
```
# for OneTrading.com (ex BitpandaPro)
echo 'local API_TOKEN=YOUR_VERY_LOOOOOOONNNNGGGG_API_TOKEN_FROM_BITPANDA' >dabo/.bitpanda-secrets
chmod 400 dabo/.bitpanda-secrets
# or for Binance
echo 'local API_SECRET="YOUR_LONG_API_SECRET_FROM_BINANCE"
local API_KEY="YOUR_LONG_API_KEY_FROM_BINANCE" '>dabo/.binance-secrets
- file: dabo/.CCXT-ID-secrets
CCXI-ID see: https://github.com/ccxt/ccxt
Examples:
```
# for Phemex
echo 'local API_SECRET="YOUR_API_SECRET_FROM_PHEMEX"
local API_KEY="YOUR_API_KEY_FROM_BINANCE"
chmod 400 dabo/.phemex-secrets
# for Binance
echo 'local API_SECRET="YOUR_API_SECRET_FROM_BINANCE"
local API_KEY="YOUR_API_KEY_FROM_BINANCE" '>dabo/.binance-secrets
chmod 400 dabo/.binance-secrets
```
@ -319,106 +327,48 @@ The access rights to this file should be set to the minimum necessary for securi
## Strategies
You can put your own code into the strateghies it will be sourced by the bot.
You can put your own code into the strategies it will be sourced by the bot.
You can use available variables to set and read things.
You can use available variables to read (and set) values.
### Variables to set
### Variables with current market values
You can simply use the following varaibles to define things:
#### Large associative arrays v and vr (reverse)
${v[SYMBOL_TIMEFRAME_ITEM_NUMBER]}
- SYMBOL: Crypto-Symbol for examle ETHUSDT or ECONOMY_DXY ECONOMY_DOWJONES ECONOMY_SP500 ECONOMY_NASDAQ ECONOMY_MSCIEAFE ECONOMY_10YRTREASURY ECONOMY_OIL ECONOMY_GOLD ECONOMY_MSCIWORLD ECONOMY_OILGAS ECONOMY_KRE ECONOMY_EUR-USD
- TIMEFRAME: 5m,15m,1h,4h,1d,1w
- ITEM: 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
- NUMBER: 0=latest; 1=second latest
Examples:
```
${v[ECONOMY_NASDAQ_1h_close_0]}
${v[ECONOMY_SP500_rsi14_0]}
${v[ETHUSDT_1w_ema200_0]}
${v[ETHUSDT_1w_macd_histogram_signal_1]}
${v[SOLUSDT_levels_1d]}
$v[$[SOLUSDT_levels_1d_next_up]}
$v[$[ETHUSDT_levels_1w_next_down]}
```
local GOOD_MARKET_PERFORMANCE_INDEX
local BUY_RSI5_SIGNAL_UNTIL
local BUY_RSI14_SIGNAL_UNTIL
local BUY_RSI21_SIGNAL_UNTIL
local BUY_RSI60_SIGNAL_UNTIL
local BUY_RSI120_SIGNAL_UNTIL
local BUY_RSI240_SIGNAL_UNTIL
local BUY_RSI420_SIGNAL_UNTIL
local BUY_RSI720_SIGNAL_UNTIL
local BUY_RSI5_SIGNAL_FROM
local BUY_RSI14_SIGNAL_FROM
local BUY_RSI21_SIGNAL_FROM
local BUY_RSI60_SIGNAL_FROM
local BUY_RSI120_SIGNAL_FROM
local BUY_RSI240_SIGNAL_FROM
local BUY_RSI420_SIGNAL_FROM
local BUY_RSI720_SIGNAL_FROM
local BUY_MACD_RELATION_FROM
local BUY_MACD_RELATION_TO
local BUY_MIN_PRICE_CHANGE_LAST_1_DAY
local BUY_MIN_PRICE_CHANGE_LAST_7_DAY
local BUY_MIN_PRICE_CHANGE_LAST_14_DAY
local BUY_MIN_PRICE_CHANGE_LAST_30_DAY
local BUY_MINGROWTH_PERIOD
local BUY_MINGROWTH
Show all available:
```
for x in "${!v[@]}"; do printf "[%q]=%q\n" "$x" "${v[$x]}" ; done
```
### Variables with current values from the CSV files
#### Current price from exchange
${f_tickers_array[SYMBOL]}
```
# date from current timeframe
${f_date}
# current price
${f_price}
# price change percentage from timeframe before
${f_price_change}
# EMA
${f_ema12}
${f_ema26}
${f_ema50}
${f_ema100}
${f_ema200}
${f_ema800}
# MACD with EMA 12/16/9
${f_macd_histogram}
${f_macd_signal_relation}
${f_macd_histogram_relation}
${f_macd_histogram_signal}
# RSI from last ?? timeframes
${f_rsi5}
${f_rsi14}
${f_rsi21}
${f_rsi720}
${f_rsi60}
${f_rsi120}
${f_rsi240}
${f_rsi420}
# Price change from coingecko.com
${f_price_change_1_day}
${f_price_change_7_day}
${f_price_change_14_day}
${f_price_change_30_day}
${f_price_change_1_year}
# Market Capitalization change from coingecko.com
${f_marketcap_change_1_day}
# Ranges, Pivpot Point and Fibonacci based support and resist levels support/resist2 aka as "Golden Pocket"
${f_range_periods}
${f_lowest_in_range}
${f_highest_in_range}
${f_pivot_point}
${f_support1}
${f_resist1}
${f_golden_pocket_support}
${f_golden_pocket_resist}
${f_golden_pocket65_support}
${f_golden_pocket65_resist}
${f_support3}
${f_resist3}
${f_tickers_array[SOLUSDT]}
${f_tickers_array[ETH${CURRENCY}]}
```
## Future ideas/featrues
- Crypto preferences (While/Blacklist for certain currencies)
- Overview trades/profits/losses for tax declaration

View File

@ -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"

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -19,6 +19,7 @@
function get_values {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_assets="$@"
f_assets=${f_assets//:$CURRENCY/}
@ -36,11 +37,11 @@ function get_values {
fi
done
# get current prices
# 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
for f_asset in $f_assets BTC${CURRENCY} $f_eco_assets
do
# read latest ohlcv data and indicators per timeframe to vars
@ -52,32 +53,51 @@ 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" ]
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]}"
fi
# 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
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
for i in "${!v[@]}"
do
echo "\${v[$i]}"
done | sort >values.new
mv values.new values
set 2>&1 | grep ^v_ | grep -v ^v_csv_array_associative >values
return $f_return
}

View File

@ -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
}

View File

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