function check_for_buy { g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_ok "Investmentbudget: $CURRENCY_BALANCE $CURRENCY" # check for emergency stop local f_COMPLETE_BALANCE=$(tail -n1 "asset-histories/BALANCECOMPLETE${CURRENCY}.history.csv" | cut -d, -f2) if [ $(echo "${f_COMPLETE_BALANCE} < ${EMERGENCY_STOP}" | bc -l) -ne 0 ] then g_echo_note "BUY ATTENTION! EMERGENCY STOP DUE TO POOR PERFORMANCE: BALANCE (${f_COMPLETE_BALANCE}) LOWER THEN EMERGENCY_STOP-VALUE (${EMERGENCY_STOP})" return 0 fi ## Generate grep regex for already invested assets #f_investedassets_regex=$(cat EXCHANGE_GET_BALANCES_CMD_OUT | cut -d, -f1 | perl -pe 's/^/\^/; s/\n/\|/' | perl -pe 's/\|$//') if ! [ -s ASSETS ] then g_echo_note "BUY file ASSETS empty $(ls -l ASSETS)" return 0 fi ## use BUY_CONDITION_RISK if market is bad if [ $(echo "${f_market_performance} > ${GOOD_MARKET_PERFORMANCE_INDEX}" | bc -l) -eq 0 ] then #g_echo_note "BUY market performance ${f_market_performance}% looks bad - Using BUY_CONDITION_RISK (${BUY_CONDITION_RISK}) as BUY_CONDITION" #BUY_CONDITION=${BUY_CONDITION_RISK} g_echo_note "BUY market performance ${f_market_performance}% looks bad - Dont buy anything" return 0 else g_echo_note "BUY market performance ${f_market_performance}% looks ok - going on buying with BUY_CONDITION (${BUY_CONDITION})" fi # go through highest assets local f_line for f_ASSET in $(cat ASSETS | egrep -v "${BLACKLIST}") do f_ASSET_HIST_FILE="asset-histories/${f_ASSET}.history.csv" if [ $(tail -n 6 "$f_ASSET_HIST_FILE" | egrep -v ",,|,$" | wc -l) -ge 5 ] then check_buy_conditions "$f_ASSET_HIST_FILE" else g_echo_note "BUY $f_ASSET_HIST_FILE not enough data - waiting for complete values" fi done }