dabo/dabo/dabo-bot.sh
2023-10-24 21:13:59 +02:00

109 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
. /etc/bash/gaboshlib.include
export LANGUAGE="en_US"
### CONFIG ###
BASEPATH=/dabo/htdocs
g_tries=13
g_tries_delay=23
### FUNCTIONS ###
for bashfunc in $(find ${BASEPATH}/../functions -type f -name "*.sh")
do
. "$bashfunc"
done
### MAIN ###
g_signal-notify "STARTING DABO BOT $0"
# prepare directories
mkdir -p ${BASEPATH}/botdata/asset-histories
mkdir -p ${BASEPATH}/botdata/trade-histories
cd ${BASEPATH}/botdata
touch firstloop
# am I the bot (important for functions used by analyze.sh
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
# run endless loop
while true
do
# wait until next full minute in the beginning to be able to work with continue in this loop
if [ -f firstloop ]
then
rm -f firstloop
else
g_echo_note "NEXT LOOP - sleping until next full ${INTERVAL} seconds"
sleep $((${INTERVAL} - $(date +%s) % ${INTERVAL}))
fi
# reload config
g_tries_delay=$(shuf -i 5-15 -n 1)
. ../../dabo-bot.conf
. ../../dabo-bot.override.conf
# Headline
export csv_headline="Date and Time,Price,Change,EMA12,EMA26,MACD,EMA9 (Sig.),Histogram,MACD Sig.,RSI5,RSI14,RSI21,RSI720,RSI60,RSI120,RSI240,RSI420,Change 24h,Change 7d,Change 14d,Change 30d,Change 1y,MarketCap Change 24h,RANGE PERIODS,LOWEST IN RANGE,HIGHEST IN RANGE,PIVOT POINT,SUPPORT1,RESIST1,GOLDEN POCKET SUPPORT,GOLDEN POCKET RESIST,GOLDEN POCKET 65 SUPPORT,GOLDEN POCKET 65 RESIST,SUPPORT3,RESIST3,EMA50,EMA100,EMA200,EMA800"
# 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
# stock data
if [ ${STOCK_EXCHANGE} = "BINANCE" ]
then
# command for current token infos (function for setting var QUANTITY_LOT_CUT
TOKEN_INFO_CMD="binance_get_token_info"
# command for buying/selling a token
TRADE_CMD='binance-api-call POST /api/v3/order "&symbol=TOKEN&quoteOrderQty=QUANTITY&side=ACTION&type=MARKET"'
elif [ ${STOCK_EXCHANGE} = "BITPANDA" ]
then
TOKEN_INFO_CMD="bitpanda_get_token_info"
TRADE_CMD='bitpanda-api-call POST public/v1/account/orders "--header \"Content-Type: application/json\" --data \"{\\\"instrument_code\\\":\\\"TOKEN\\\",\\\"side\\\":\\\"ACTION\\\",\\\"type\\\":\\\"MARKET\\\",\\\"amount\\\":\\\"QUANTITY\\\"}\""'
fi
# Get current assets
get_assets || continue
# Get current balances
get_balances || continue
# Check the situation on the market
if ! market_performance
then
f_market_performance=$(cat MARKET_PERFORMANCE_LATEST)
fi
##### Sell something? ####
check_for_sell
##### Buy something? ####
check_for_buy
##### Update webpage
if jobs | egrep -q "Running.+webpage"
then
g_echo_note "webpage already running"
else
webpage &
fi
done