Compare commits
No commits in common. "89659c64f7425051ca5df68cdde2e7dbee3bd7d2" and "530230cbb51e5ef26cae7b1f92b795ebfe9c3e0d" have entirely different histories.
89659c64f7
...
530230cbb5
@ -26,7 +26,6 @@ mkdir -p ${BASEPATH}/botdata/trade-histories
|
|||||||
cd ${BASEPATH}/botdata
|
cd ${BASEPATH}/botdata
|
||||||
|
|
||||||
touch firstloop
|
touch firstloop
|
||||||
export FULL_LOOP=1
|
|
||||||
|
|
||||||
# am I the bot (important for functions used by analyze.sh
|
# am I the bot (important for functions used by analyze.sh
|
||||||
echo $0 | grep -q "dabo-bot\.sh" && BOT=1
|
echo $0 | grep -q "dabo-bot\.sh" && BOT=1
|
||||||
@ -39,7 +38,6 @@ do
|
|||||||
touch -t ${csv_timestamp} "${csv_file}"
|
touch -t ${csv_timestamp} "${csv_file}"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
# run endless loop
|
# run endless loop
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
@ -48,20 +46,8 @@ do
|
|||||||
then
|
then
|
||||||
rm -f firstloop
|
rm -f firstloop
|
||||||
else
|
else
|
||||||
LOOP_INTERVAL=60 # 60s max free coinhecko API interval
|
g_echo_note "NEXT LOOP - sleping until next full ${INTERVAL} seconds"
|
||||||
time_to_interval=$((${LOOP_INTERVAL} - $(date +%s) % ${LOOP_INTERVAL}))
|
sleep $((${INTERVAL} - $(date +%s) % ${INTERVAL}))
|
||||||
g_echo_note "NEXT LOOP - sleeping ${time_to_interval} seconds until next full ${LOOP_INTERVAL} seconds"
|
|
||||||
sleep ${time_to_interval}
|
|
||||||
# Check for next general interval
|
|
||||||
time_to_full_interval=$((${INTERVAL} - $(date +%s) % ${INTERVAL}))
|
|
||||||
if [ ${time_to_full_interval} -le ${time_to_interval} ]
|
|
||||||
then
|
|
||||||
g_echo_note "NEXT FULL LOOP NOW - all ${INTERVAL} seconds"
|
|
||||||
FULL_LOOP=1
|
|
||||||
else
|
|
||||||
g_echo_note "NEXT FULL LOOP - ${INTERVAL} seconds in ${time_to_full_interval} seconds"
|
|
||||||
FULL_LOOP=0
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# reload config
|
# reload config
|
||||||
@ -92,15 +78,9 @@ do
|
|||||||
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\\\"}\""'
|
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
|
fi
|
||||||
|
|
||||||
# Get coingecko data
|
|
||||||
get_coingecko_data
|
|
||||||
|
|
||||||
# Get current assets
|
# Get current assets
|
||||||
get_assets || continue
|
get_assets || continue
|
||||||
|
|
||||||
# stop here if no full loop
|
|
||||||
[ ${FULL_LOOP} == 0 ] && continue
|
|
||||||
|
|
||||||
# Get current balances
|
# Get current balances
|
||||||
get_balances || continue
|
get_balances || continue
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ function check_sell_conditions {
|
|||||||
g_percentage-diff ${f_BUY_PRICE} ${f_price}
|
g_percentage-diff ${f_BUY_PRICE} ${f_price}
|
||||||
f_result=${g_percentage_diff_result}
|
f_result=${g_percentage_diff_result}
|
||||||
f_BUY_PRICE_LAST_RATE_DIFF=${f_result}
|
f_BUY_PRICE_LAST_RATE_DIFF=${f_result}
|
||||||
result=${f_result}
|
result=${f_BUY_PRICE_LAST_RATE_DIFF}
|
||||||
g_calc "${f_result}-${FEE}"
|
g_calc "${f_result}-${FEE}"
|
||||||
f_real_result=${g_calc_result}
|
f_real_result=${g_calc_result}
|
||||||
|
|
||||||
|
@ -40,8 +40,6 @@ function get_asset {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ ${FULL_LOOP} == 0 ] && return 0
|
|
||||||
|
|
||||||
f_ASSET_HIST_FILE="asset-histories/${f_ASSET}.history.csv"
|
f_ASSET_HIST_FILE="asset-histories/${f_ASSET}.history.csv"
|
||||||
#if [ ${f_linecount} -lt 30 ] && [ ${f_lines} -ge 50 ] && [ ${INTERVAL} -lt 300 ]
|
#if [ ${f_linecount} -lt 30 ] && [ ${f_lines} -ge 50 ] && [ ${INTERVAL} -lt 300 ]
|
||||||
#then
|
#then
|
||||||
|
@ -29,6 +29,39 @@ function get_assets {
|
|||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
## write assets list and filter by marketcap and sort by price
|
||||||
|
# get krypto symbol list sorted by marketcap
|
||||||
|
echo "curl -s -X 'GET' \"https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=250&page=1&sparkline=false&price_change_percentage=1h,24h,7d,14d,30d,1y\" -H 'accept: application/json'" >COINGECKO_GET_ASSETS_CMD
|
||||||
|
g_runcmd g_retrycmd sh COINGECKO_GET_ASSETS_CMD >COINGECKO_GET_ASSETS_CMD_OUT || return 1
|
||||||
|
#ASSET_MARKETCAP_OUT.tmp || return 1
|
||||||
|
if [ -s COINGECKO_GET_ASSETS_CMD_OUT ] && grep -q "market_cap_rank" COINGECKO_GET_ASSETS_CMD_OUT
|
||||||
|
then
|
||||||
|
|
||||||
|
# get marketcap sort
|
||||||
|
jq -r '.[].symbol' COINGECKO_GET_ASSETS_CMD_OUT | tr [:lower:] [:upper:] | head -n $LARGEST_MARKETCAP >ASSET_MARKETCAP_OUT.tmp-sort
|
||||||
|
if [ -s ASSET_MARKETCAP_OUT.tmp-sort ] && egrep -q "^[A-Z0-9]+$" ASSET_MARKETCAP_OUT.tmp-sort
|
||||||
|
then
|
||||||
|
mv ASSET_MARKETCAP_OUT.tmp-sort SORTMARKETCAP
|
||||||
|
else
|
||||||
|
g_echo_warn "ASSET_MARKETCAP_OUT.tmp-sort has wrong Syntax. - Not updating ASSET_MARKETCAP_OUT.tmp-sort $(tail -n 10 ASSET_MARKETCAP_OUT.tmp-sort)"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# write down 24h pricechange
|
||||||
|
cat COINGECKO_GET_ASSETS_CMD_OUT | jq -r '.[] | .symbol + "," + (.price_change_percentage_24h|tostring)' | tr [:lower:] [:upper:] >ASSET_PRICE_CHANGE_PERCENTAGE_24H
|
||||||
|
|
||||||
|
# store coingecko symbolids for coingecko info URLs
|
||||||
|
jq -r '.[] | .symbol + "," + .id' COINGECKO_GET_ASSETS_CMD_OUT >COINGECKO_IDS.tmp
|
||||||
|
if [ -s COINGECKO_IDS.tmp ]
|
||||||
|
then
|
||||||
|
mv COINGECKO_IDS.tmp COINGECKO_IDS
|
||||||
|
else
|
||||||
|
g_echo_warn "COINGECKO_IDS.tmp has wrong Syntax. - Not updating COINGECKO_IDS $(tail -n 10 COINGECKO_IDS.tmp)"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Write file with asset list and ignore marketcap under LARGEST_MARKETCAP
|
# Write file with asset list and ignore marketcap under LARGEST_MARKETCAP
|
||||||
cat EXCHANGE_GET_ASSETS_CMD_OUT | cut -d"," -f1 | while read f_ASSET
|
cat EXCHANGE_GET_ASSETS_CMD_OUT | cut -d"," -f1 | while read f_ASSET
|
||||||
do
|
do
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
function get_coingecko_data {
|
|
||||||
# get data from coingecko
|
|
||||||
echo "curl -s -X 'GET' \"https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=250&page=1&sparkline=false&price_change_percentage=1h,24h,7d,14d,30d,1y\" -H 'accept: application/json'" >COINGECKO_GET_ASSETS_CMD
|
|
||||||
g_runcmd g_retrycmd sh COINGECKO_GET_ASSETS_CMD >COINGECKO_GET_ASSETS_CMD_OUT || return 1
|
|
||||||
|
|
||||||
[ ${FULL_LOOP} == 0 ] && return 0
|
|
||||||
if [ -s COINGECKO_GET_ASSETS_CMD_OUT ] && grep -q "market_cap_rank" COINGECKO_GET_ASSETS_CMD_OUT
|
|
||||||
then
|
|
||||||
|
|
||||||
# get marketcap sort
|
|
||||||
jq -r '.[].symbol' COINGECKO_GET_ASSETS_CMD_OUT | tr [:lower:] [:upper:] | head -n $LARGEST_MARKETCAP >ASSET_MARKETCAP_OUT.tmp-sort
|
|
||||||
if [ -s ASSET_MARKETCAP_OUT.tmp-sort ] && egrep -q "^[A-Z0-9]+$" ASSET_MARKETCAP_OUT.tmp-sort
|
|
||||||
then
|
|
||||||
mv ASSET_MARKETCAP_OUT.tmp-sort SORTMARKETCAP
|
|
||||||
else
|
|
||||||
g_echo_warn "ASSET_MARKETCAP_OUT.tmp-sort has wrong Syntax. - Not updating ASSET_MARKETCAP_OUT.tmp-sort $(tail -n 10 ASSET_MARKETCAP_OUT.tmp-sort)"
|
|
||||||
return 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
# write down 24h pricechange
|
|
||||||
cat COINGECKO_GET_ASSETS_CMD_OUT | jq -r '.[] | .symbol + "," + (.price_change_percentage_24h|tostring)' | tr [:lower:] [:upper:] >ASSET_PRICE_CHANGE_PERCENTAGE_24H
|
|
||||||
|
|
||||||
# store coingecko symbolids for coingecko info URLs
|
|
||||||
jq -r '.[] | .symbol + "," + .id' COINGECKO_GET_ASSETS_CMD_OUT >COINGECKO_IDS.tmp
|
|
||||||
if [ -s COINGECKO_IDS.tmp ]
|
|
||||||
then
|
|
||||||
mv COINGECKO_IDS.tmp COINGECKO_IDS
|
|
||||||
else
|
|
||||||
g_echo_warn "COINGECKO_IDS.tmp has wrong Syntax. - Not updating COINGECKO_IDS $(tail -n 10 COINGECKO_IDS.tmp)"
|
|
||||||
return 2
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -39,15 +39,6 @@ function get_vars_from_csv {
|
|||||||
# basics
|
# basics
|
||||||
get_var_from_line date 1
|
get_var_from_line date 1
|
||||||
get_var_from_line price 2
|
get_var_from_line price 2
|
||||||
|
|
||||||
# get newest price from raw file if this is a non-full loop
|
|
||||||
# TODO: Nicer pure-bash code
|
|
||||||
if [ ${FULL_LOOP} == 0 ]
|
|
||||||
then
|
|
||||||
f_ASSET_HIST_FILE_RAW=$(echo ${f_ASSET_HIST_FILE} | sed 's/.csv$/-raw.csv/')
|
|
||||||
f_price=$(tail -n1 "${f_ASSET_HIST_FILE_RAW}" | cut -d, -f2)
|
|
||||||
fi
|
|
||||||
|
|
||||||
get_var_from_line price_change 3
|
get_var_from_line price_change 3
|
||||||
|
|
||||||
# Check for price trend last 4 iterations
|
# Check for price trend last 4 iterations
|
||||||
|
Loading…
Reference in New Issue
Block a user