2023-05-02 10:53:48 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
. /etc/bash/gaboshlib.include
|
|
|
|
|
2023-05-07 13:17:06 +02:00
|
|
|
export LANGUAGE="en_US"
|
|
|
|
|
2023-05-02 10:53:48 +02:00
|
|
|
### CONFIG ###
|
|
|
|
|
|
|
|
BASEPATH=/dabo/htdocs
|
|
|
|
g_tries=3
|
|
|
|
g_tries_delay=5
|
|
|
|
|
|
|
|
### FUNCTIONS ###
|
|
|
|
for bashfunc in $(find ${BASEPATH}/../functions -type f -name "*.sh")
|
|
|
|
do
|
|
|
|
. "$bashfunc"
|
|
|
|
done
|
|
|
|
|
|
|
|
### MAIN ###
|
|
|
|
|
2023-05-07 13:17:06 +02:00
|
|
|
g_signal-notify "STARTING DABO BOT $0"
|
|
|
|
|
2023-05-02 10:53:48 +02:00
|
|
|
# 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
|
|
|
|
|
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
|
|
|
|
g_echo_note "NEXT LOOP - sleping until next full ${INTERVAL} seconds"
|
|
|
|
sleep $((${INTERVAL} - $(date +%s) % ${INTERVAL}))
|
|
|
|
fi
|
|
|
|
|
|
|
|
# reload config
|
|
|
|
. ../../dabo-bot.conf
|
2023-05-09 17:04:02 +02:00
|
|
|
. ../../dabo-bot.override.conf
|
2023-05-02 10:53:48 +02: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"eOrderQty=QUANTITY&side=ACTION&type=MARKET"'
|
2023-05-07 13:17:06 +02:00
|
|
|
elif [ ${STOCK_EXCHANGE} = "BITPANDA" ]
|
|
|
|
then
|
2023-05-09 10:30:03 +02:00
|
|
|
TOKEN_INFO_CMD="bitpanda_get_token_info"
|
2023-05-07 13:17:06 +02:00
|
|
|
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\\\"}\""'
|
2023-05-02 10:53:48 +02:00
|
|
|
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
|
|
|
|
webpage &
|
|
|
|
|
|
|
|
done
|
|
|
|
|