Compare commits

..

6 Commits

6 changed files with 79 additions and 3 deletions

View File

@ -95,6 +95,9 @@ do
# Get coingecko data # Get coingecko data
get_coingecko_data get_coingecko_data
# watch some manual defined assets
watch_assets
# Get current assets # Get current assets
get_assets || continue get_assets || continue

View File

@ -14,7 +14,8 @@ function get_assets {
elif [ ${STOCK_EXCHANGE} = "BITPANDA" ] elif [ ${STOCK_EXCHANGE} = "BITPANDA" ]
then then
bitpanda-api-call GET "public/v1/market-ticker" || return 1 bitpanda-api-call GET "public/v1/market-ticker" || return 1
cat ${g_tmp}/API_CMD_OUT | jq -r '.[] | select(.state=="ACTIVE") | .instrument_code + "," + .last_price' | sed 's/_//' | grep "${CURRENCY}," | egrep -v "${TRANSFER_CURRENCY},|,0[\.][0]*$" >${f_filename}_OUT.tmp #cat ${g_tmp}/API_CMD_OUT | jq -r '.[] | select(.state=="ACTIVE") | .instrument_code + "," + .last_price' | sed 's/_//' | grep "${CURRENCY}," | egrep -v "${TRANSFER_CURRENCY},|,0[\.][0]*$" >${f_filename}_OUT.tmp
cat ${g_tmp}/API_CMD_OUT | jq -r '.[] | .instrument_code + "," + .last_price' | sed 's/_//' | grep "${CURRENCY}," | egrep -v "${TRANSFER_CURRENCY},|,0[\.][0]*$" >${f_filename}_OUT.tmp
fi fi
cp -p ${g_tmp}/API_CMD_OUT PRICETICKER cp -p ${g_tmp}/API_CMD_OUT PRICETICKER

View File

@ -1,7 +1,15 @@
function get_coingecko_data { function get_coingecko_data {
# get data from coingecko # 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 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 g_runcmd g_retrycmd sh COINGECKO_GET_ASSETS_CMD >COINGECKO_GET_ASSETS_CMD_OUT_TMP || return 1
local f_test_query=$(jq -r ".[] |select(.symbol==\"btc\")|\"\\(.current_price)\"" COINGECKO_GET_ASSETS_CMD_OUT_TMP)
if g_num_valid_number ${f_test_query}
then
mv COINGECKO_GET_ASSETS_CMD_OUT_TMP COINGECKO_GET_ASSETS_CMD_OUT
else
find COINGECKO_GET_ASSETS_CMD_OUT -mmin +${LOOP_INTERVAL} && g_echo_warn "Coingecko data older then ${LOOP_INTERVAL}s: $(ls -l COINGECKO_GET_ASSETS_CMD_OUT)"
return 1
fi
[ ${FULL_LOOP} == 0 ] && return 0 [ ${FULL_LOOP} == 0 ] && return 0
if [ -s COINGECKO_GET_ASSETS_CMD_OUT ] && grep -q "market_cap_rank" COINGECKO_GET_ASSETS_CMD_OUT if [ -s COINGECKO_GET_ASSETS_CMD_OUT ] && grep -q "market_cap_rank" COINGECKO_GET_ASSETS_CMD_OUT

View File

@ -6,6 +6,7 @@ function get_marketdata {
if find asset-histories/${f_name}.history.csv -mmin -${INTERVAL_MIN} | grep -q "asset-histories/${f_name}.history.csv" if find asset-histories/${f_name}.history.csv -mmin -${INTERVAL_MIN} | grep -q "asset-histories/${f_name}.history.csv"
then then
g_echo_note "asset-histories/${f_name}.history.csv already downloaded in the last ${INTERVAL_MIN} minutes" g_echo_note "asset-histories/${f_name}.history.csv already downloaded in the last ${INTERVAL_MIN} minutes"
f_get_marketdata_price=$(cat MARKET_DATA_CMD_OUT-${f_name})
return 0 return 0
fi fi
@ -50,6 +51,7 @@ $(tail -n 10 MARKET_DATA_CMD_OUT-${f_name}.tmp.err | cat -t)"
echo 0 >MARKET_DATA_CMD_OUT-${f_name} echo 0 >MARKET_DATA_CMD_OUT-${f_name}
fi fi
fi fi
echo "${f_timestamp},$(cat MARKET_DATA_CMD_OUT-${f_name})" >>asset-histories/${f_name}.history.csv f_get_marketdata_price=$(cat MARKET_DATA_CMD_OUT-${f_name})
echo "${f_timestamp},${f_get_marketdata_price}" >>asset-histories/${f_name}.history.csv
} }

View File

@ -0,0 +1,61 @@
function watch_assets {
local f_watch_assets_array
local f_line
local f_price
local f_alert
local f_last_price
mapfile -t f_watch_assets_array < <(grep -v ^ASSET,ALERTS,BUYPRICE,BUYDATE,BUYQUANTITY,SELLPRICE,SELLDATE,SELLQUANTITY /dabo/watch-assets.csv)
for f_line in "${f_watch_assets_array[@]}"
do
g_echo "$f_line"
readarray -d "," -t f_line_array < <(echo -n "0,${f_line}")
local f_asset=${f_line_array[1]}
local f_alerts=${f_line_array[2]}
local f_buyprice=${f_line_array[3]}
local f_buydate=${f_line_array[4]}
local f_buyquantity=${f_line_array[5]}
local f_sellprice=${f_line_array[6]}
local f_selldate=${f_line_array[7]}
local f_sellquantity=${f_line_array[8]}
local f_comment=${f_line_array[9]}
# get current asset price ild last price if not sold
if [ -z "${f_sellprice}" ]
then
if [[ ${f_asset} =~ ^https ]]
then
# get asset price from get_marketdata
get_marketdata ${f_asset}
f_price=${f_get_marketdata_price}
readarray -d " " -t f_asset_array < <(echo -n "${f_asset}")
f_asset=${f_asset_array[1]}
else
# get token price from coingecko
f_price=$(jq -r ".[] |select(.symbol==\"${f_asset}\")|\"\\(.current_price)\"" COINGECKO_GET_ASSETS_CMD_OUT)
fi
[ -s WATCH_ASSETS_${f_asset}_LAST_PRICE ] && read f_last_price < <(cat WATCH_ASSETS_${f_asset}_LAST_PRICE)
echo ${f_price} >WATCH_ASSETS_${f_asset}_LAST_PRICE
echo g_num_valid_number ${f_price} ${f_last_price} #|| continue
# Notify on alert
readarray -d "|" -t f_alerts_array < <(echo -n "${f_alerts}")
for f_alert in "${f_alerts_array[@]}"
do
if g_num_is_higher_equal ${f_price} ${f_alert} && g_num_is_lower_equal ${f_last_price} ${f_alert}
then
g_signal-notify "${f_asset} Price ${f_price} switched over alert ${f_alert}! Comment: ${f_comment}"
fi
if g_num_is_lower_equal ${f_price} ${f_alert} && g_num_is_higher_equal ${f_last_price} ${f_alert}
then
g_signal-notify "${f_asset} Price ${f_price} switched under alert ${f_alert}! Comment: ${f_comment}"
fi
done
fi
done
}

View File

@ -11,6 +11,7 @@ services:
- ./dabo:/dabo:ro - ./dabo:/dabo:ro
- ./strategies:/dabo/strategies:ro - ./strategies:/dabo/strategies:ro
- ./dabo-bot.conf:/dabo/dabo-bot.override.conf - ./dabo-bot.conf:/dabo/dabo-bot.override.conf
- ./watch-assets.csv:/dabo/watch-assets.csv
- ./data:/dabo/htdocs:rw - ./data:/dabo/htdocs:rw
- ./home:/dabo/home:rw - ./home:/dabo/home:rw
- /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro - /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro