fix: dont run get_assts if STOCK_EXCHANGE is NONE

This commit is contained in:
olli 2024-02-07 11:44:23 +01:00
parent 9d0e0b388c
commit ae99194986
3 changed files with 54 additions and 51 deletions

View File

@ -81,54 +81,57 @@ do
INTERVAL_MIN=$(echo "${INTERVAL}/60-1" | bc -l | sed -r 's/^(-?)\./\10./' | cut -d\. -f1) INTERVAL_MIN=$(echo "${INTERVAL}/60-1" | bc -l | sed -r 's/^(-?)\./\10./' | cut -d\. -f1)
[ -z "${INTERVAL_MIN}" ] && INTERVAL_MIN=1 [ -z "${INTERVAL_MIN}" ] && INTERVAL_MIN=1
# stock data ### get general market 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"'
elif [ "${STOCK_EXCHANGE}" = "BITPANDA" ]
then
TOKEN_INFO_CMD="bitpanda_get_token_info"
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
# Get coingecko data # Get coingecko data
get_coingecko_data get_coingecko_data
# watch some manual defined assets
watch_assets
# Get current assets
if [ "${STOCK_EXCHANGE}" != "NONE" ]
then
get_assets || continue
fi
# Get current MarketData # Get current MarketData
get_marketdata get_marketdata
##### Sell something? ####
check_for_sell
# Get current balances
get_balances || continue
# Check the situation on the market # Check the situation on the market
if ! market_performance if ! market_performance
then then
f_market_performance=$(cat MARKET_PERFORMANCE_LATEST) f_market_performance=$(cat MARKET_PERFORMANCE_LATEST)
fi fi
# stop here if no full loop
[ ${FULL_LOOP} == 0 ] && continue
##### Buy something? #### ## watch some manual defined assets
check_for_buy watch_assets
##### Update webpage
if jobs | egrep -q "Running.+webpage" ## if STOCK_EXCHANGE is present
if [ "${STOCK_EXCHANGE}" != "NONE" ]
then
# 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"'
elif [ "${STOCK_EXCHANGE}" = "BITPANDA" ]
then
TOKEN_INFO_CMD="bitpanda_get_token_info"
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
# Get current assets
get_assets || continue
# Sell something?
check_for_sell
# Get current balances
[ ${FULL_LOOP} = 1 ] && get_balances || continue
# Buy something?
[ ${FULL_LOOP} = 1 ] && check_for_buy
fi
## Update webpage
if jobs | egrep -q "Running.+webpage" && [ ${FULL_LOOP} = 1 ]
then then
g_echo_note "webpage already running" g_echo_note "webpage already running"
else else

View File

@ -1,22 +1,22 @@
function get_coingecko_data { function get_coingecko_data {
# get data from coingecko # get data from coingecko
local f_gecko_currencies="usd eur" local f_gecko_currencies="usd eur"
if find COINGECKO_GET_ASSETS_CMD_OUT -mmin +5 | grep -q COINGECKO_GET_ASSETS_CMD_OUT if find COINGECKO_GET_ASSETS_CMD_OUT -mmin +5 2>/dev/null | grep -q COINGECKO_GET_ASSETS_CMD_OUT
then then
for f_gecko_currency in ${f_gecko_currencies} for f_gecko_currency in ${f_gecko_currencies}
do do
echo "curl -s -X 'GET' \"https://api.coingecko.com/api/v3/coins/markets?vs_currency=${f_gecko_currency}&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_${f_gecko_currency}_CMD echo "curl -s -X 'GET' \"https://api.coingecko.com/api/v3/coins/markets?vs_currency=${f_gecko_currency}&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_${f_gecko_currency}_CMD
g_runcmd g_retrycmd sh COINGECKO_GET_ASSETS_${f_gecko_currency}_CMD >COINGECKO_GET_ASSETS_${f_gecko_currency}_CMD_OUT_TMP || return 1 g_runcmd g_retrycmd sh COINGECKO_GET_ASSETS_${f_gecko_currency}_CMD >COINGECKO_GET_ASSETS_${f_gecko_currency}_CMD_OUT_TMP || return 1
local f_test_query=$(jq -r ".[] |select(.symbol==\"btc\")|\"\\(.current_price)\"" COINGECKO_GET_ASSETS_${f_gecko_currency}_CMD_OUT_TMP) local f_test_query=$(jq -r ".[] |select(.symbol==\"btc\")|\"\\(.current_price)\"" COINGECKO_GET_ASSETS_${f_gecko_currency}_CMD_OUT_TMP)
if g_num_valid_number ${f_test_query} if g_num_valid_number ${f_test_query}
then then
mv COINGECKO_GET_ASSETS_${f_gecko_currency}_CMD_OUT_TMP COINGECKO_GET_ASSETS_${f_gecko_currency}_CMD_OUT mv COINGECKO_GET_ASSETS_${f_gecko_currency}_CMD_OUT_TMP COINGECKO_GET_ASSETS_${f_gecko_currency}_CMD_OUT
[[ ${f_gecko_currency} =~ ^usd ]] && cat COINGECKO_GET_ASSETS_${f_gecko_currency}_CMD_OUT >COINGECKO_GET_ASSETS_CMD_OUT [[ ${f_gecko_currency} =~ ^usd ]] && cat COINGECKO_GET_ASSETS_${f_gecko_currency}_CMD_OUT >COINGECKO_GET_ASSETS_CMD_OUT
else else
find COINGECKO_GET_ASSETS_${f_gecko_currency}_CMD_OUT -mmin +15 | grep -q COINGECKO_GET_ASSETS_${f_gecko_currency}_CMD_OUT && g_echo_warn "Coingecko data older then 15min: $(ls -l COINGECKO_GET_ASSETS_${f_gecko_currency}_CMD_OUT)" find COINGECKO_GET_ASSETS_${f_gecko_currency}_CMD_OUT -mmin +15 | grep -q COINGECKO_GET_ASSETS_${f_gecko_currency}_CMD_OUT && g_echo_warn "Coingecko data older then 15min: $(ls -l COINGECKO_GET_ASSETS_${f_gecko_currency}_CMD_OUT)"
return 1 return 1
fi fi
done done
fi fi
[ ${FULL_LOOP} == 0 ] && return 0 [ ${FULL_LOOP} == 0 ] && return 0

View File

@ -18,7 +18,7 @@ function get_marketdata {
get_marketdata_from_url https://www.investing.com/economic-calendar/cpi-733 US-CONSUMER-PRICE-INDEX get_marketdata_from_url https://www.investing.com/economic-calendar/cpi-733 US-CONSUMER-PRICE-INDEX
get_marketdata_from_url https://www.investing.com/indices/fed-funds-composite-interest-rate-opinion US-FED-FEDERAL-FUNDS-RATE-INVERTED-INDEX get_marketdata_from_url https://www.investing.com/indices/fed-funds-composite-interest-rate-opinion US-FED-FEDERAL-FUNDS-RATE-INVERTED-INDEX
# clear old stuff # clear old stuff
find asset-histories/*INDEX* -type f -mtime +6 -delet find asset-histories/*INDEX* -type f -mtime +6 -delete
} }
function get_marketdata_from_url { function get_marketdata_from_url {
@ -26,7 +26,7 @@ function get_marketdata_from_url {
local f_name="$2" local f_name="$2"
## get data for analysis ## get data for analysis
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} 2>/dev/null | 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}) f_get_marketdata_price=$(cat MARKET_DATA_CMD_OUT-${f_name})