new watch_assets function

This commit is contained in:
olli 2024-01-09 11:53:54 +01:00
parent 5f4bbad8fb
commit 535dff8d0a

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
}