dabo/dabo/dabo-bot.sh

124 lines
3.9 KiB
Bash
Raw Normal View History

2023-05-02 10:53:48 +02:00
#!/bin/bash
2024-05-30 17:30:03 +02:00
. /dabo/dabo-prep.sh
2023-05-02 10:53:48 +02:00
### MAIN ###
2024-05-30 17:30:03 +02:00
g_echo_warn "STARTING DABO BOT $0"
2023-05-02 10:53:48 +02:00
touch firstloop
export FULL_LOOP=1
2023-05-02 10:53:48 +02:00
# am I the bot (important for functions used by analyze.sh
echo $0 | grep -q "dabo-bot\.sh" && BOT=1
2023-06-19 17:50:18 +02:00
# 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
2023-05-02 10:53:48 +02:00
# 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
2024-02-06 12:36:27 +01:00
LOOP_INTERVAL=30 # 60s max free coingecko API interval + 30s puffer
time_to_interval=$((${LOOP_INTERVAL} - $(date +%s) % ${LOOP_INTERVAL}))
2024-02-06 13:49:55 +01:00
time_to_full_interval=$((${INTERVAL} - $(date +%s) % ${INTERVAL}))
# Check for next general interval
2024-02-06 13:42:22 +01:00
g_echo_note "NEXT LOOP in ${time_to_interval} seconds (Interval=${LOOP_INTERVAL}s)"
g_echo_note "NEXT FULL LOOP in ${time_to_full_interval} seconds (Interval=${INTERVAL}s)"
if [ ${time_to_full_interval} -le ${time_to_interval} ]
then
FULL_LOOP=1
2024-02-07 09:03:58 +01:00
g_echo_note "FULL INTERVAL"
2024-02-06 13:42:22 +01:00
sleep ${time_to_full_interval}
else
FULL_LOOP=0
2024-02-07 09:03:58 +01:00
g_echo_note "SHORT INTERVAL"
2024-02-06 13:42:22 +01:00
sleep ${time_to_interval}
fi
2023-05-02 10:53:48 +02:00
fi
2023-10-09 14:03:14 +02:00
# reload config
g_tries_delay=$(shuf -i 5-15 -n 1)
2023-05-02 10:53:48 +02:00
. ../../dabo-bot.conf
2023-05-09 17:04:02 +02:00
. ../../dabo-bot.override.conf
2023-05-02 10:53:48 +02:00
# Headline
2023-10-31 09:10:48 +01:00
export csv_headline="Date and Time,Price,Change,EMA12,EMA26,MACD,EMA9 (Sig.),Histogram,MACD Sig.,RSI5,RSI14,RSI21,RSI720,RSI60,RSI120,RSI240,RSI420,Coingecko Change 24h,Coingecko Change 7d,Coingecko Change 14d,Coingecko Change 30d,Coingecko Change 1y,Coingecko MarketCap Change 24h,RANGE DATE,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,Coingecko Price"
# 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
### 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)
2023-05-02 10:53:48 +02:00
fi
## watch some manual defined assets
2024-05-26 10:01:30 +02:00
#watch_assets
# transactions overview
#[ ${FULL_LOOP} = 1 ] && transactions_overview
2024-01-09 11:47:53 +01:00
# 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"'
2024-04-09 09:23:44 +02:00
elif [ "${STOCK_EXCHANGE}" = "ONETRADING" ]
then
2024-04-09 09:23:44 +02:00
TOKEN_INFO_CMD="onetrading_get_token_info"
TRADE_CMD='onetrading-api-call POST public/v1/account/orders "--header \"Content-Type: application/json\" --data \"{\\\"instrument_code\\\":\\\"TOKEN\\\",\\\"side\\\":\\\"ACTION\\\",\\\"type\\\":\\\"MARKET\\\",\\\"amount\\\":\\\"QUANTITY\\\"}\""'
2024-03-25 21:11:35 +01:00
elif [ "${STOCK_EXCHANGE}" = "NONE" ]
then
## stop here if STOCK_EXCHANGE not present
continue
fi
# Get current assets
2024-03-26 14:09:06 +01:00
get_assets || continue
2024-02-07 09:46:44 +01:00
# Sell something?
2024-03-26 14:09:06 +01:00
check_for_sell
2023-05-02 10:53:48 +02:00
# Get current balances
2024-05-26 10:01:30 +02:00
[ ${FULL_LOOP} = 1 ] && get_ccxt_balances || continue
2024-03-26 14:09:06 +01:00
[ ${FULL_LOOP} = 1 ] && get_balances || continue
2024-02-07 09:46:44 +01:00
# Buy something?
2024-03-26 14:09:06 +01:00
[ ${FULL_LOOP} = 1 ] && check_for_buy
# Update webpage
if jobs | egrep -q "Running.+webpage" && [ ${FULL_LOOP} = 1 ]
then
g_echo_note "webpage already running"
else
webpage &
fi
2023-05-02 10:53:48 +02:00
done