From c2ee85d7b644433f674008fad6b5432515af8bdc Mon Sep 17 00:00:00 2001 From: olli Date: Fri, 14 Jun 2024 19:56:43 +0200 Subject: [PATCH] fixes and switch to ccxt --- dabo/dabo-bot.sh | 21 +++++++++------------ dabo/functions/ccxt.sh | 21 ++++++++++----------- dabo/functions/currency_converter.sh | 3 +++ dabo/functions/get_assets.sh | 22 ++++++++++++++-------- dabo/functions/get_marketdata_historic.sh | 10 ++++++---- dabo/functions/get_positions.sh | 2 ++ dabo/functions/get_symbols.sh | 19 +++++-------------- 7 files changed, 49 insertions(+), 49 deletions(-) diff --git a/dabo/dabo-bot.sh b/dabo/dabo-bot.sh index 5b88e66..3ac258d 100755 --- a/dabo/dabo-bot.sh +++ b/dabo/dabo-bot.sh @@ -3,7 +3,7 @@ . /dabo/dabo-prep.sh ### MAIN ### -g_echo_warn "STARTING DABO BOT $0" +g_echo_note "STARTING DABO BOT $0" touch firstloop export FULL_LOOP=1 @@ -51,9 +51,6 @@ do . ../../dabo-bot.conf . ../../dabo-bot.override.conf - # Headline - export csv_headline="Date and Time,Price,Change,EMA12,EMA26,MACD,EMA9 (Sig.),Histogram,MACD Sig.,RSI5,RSI14,RSI21,RSI720,RSI60,RSI120,RSI240,RSI420,Coingecko Change 24h,Coingecko Change 7d,Coingecko Change 14d,Coingecko Change 30d,Coingecko Change 1y,Coingecko MarketCap Change 24h,RANGE DATE,LOWEST IN RANGE,HIGHEST IN RANGE,PIVOT POINT,SUPPORT1,RESIST1,GOLDEN POCKET SUPPORT,GOLDEN POCKET RESIST,GOLDEN POCKET 65 SUPPORT,GOLDEN POCKET 65 RESIST,SUPPORT3,RESIST3,EMA50,EMA100,EMA200,EMA800,Coingecko Price" - # Timestamp export f_timestamp=$(g_date_print) @@ -101,8 +98,8 @@ do # Get current symbols [ ${FULL_LOOP} = 1 ] && get_symbols - # Get current assets - get_assets || continue + ## Get current assets + #get_assets || continue # Sell something? #check_for_sell @@ -117,12 +114,12 @@ do [ ${FULL_LOOP} = 1 ] && check_for_buy # Update webpage - if jobs | egrep -q "Running.+webpage" && [ ${FULL_LOOP} = 1 ] - then - g_echo_note "webpage already running" - else - webpage & - fi + #if jobs | egrep -q "Running.+webpage" && [ ${FULL_LOOP} = 1 ] + #then + # g_echo_note "webpage already running" + #else + # webpage & + #fi done diff --git a/dabo/functions/ccxt.sh b/dabo/functions/ccxt.sh index 9725535..e912ab4 100644 --- a/dabo/functions/ccxt.sh +++ b/dabo/functions/ccxt.sh @@ -14,10 +14,8 @@ function f_ccxt { return 1 fi - #unset g_ccxt_jobs - #local g_ccxt_jobs - mapfile -t g_ccxt_jobs < <(jobs -r) # Initialize ccxt in python if not initialized + mapfile -t g_ccxt_jobs < <(jobs -r) [[ ${g_ccxt_jobs[*]} =~ *python-pipeexec.py* ]] || unset f_ccxt_initialized if [ -z "$f_ccxt_initialized" ] then @@ -44,14 +42,18 @@ function f_ccxt { # reference result to python-result declare -ng f_ccxt_result=g_python_result - # Check for json output + # Check for json output or empty json output f_ccxt_json_out="" - [[ $f_ccxt_result =~ ^\[ ]] && [[ $f_ccxt_result =~ \]$ ]] && f_ccxt_json_out=1 - [[ $f_ccxt_result =~ ^\{ ]] && [[ $f_ccxt_result =~ \}$ ]] && f_ccxt_json_out=1 + if ! [ "$f_ccxt_result" = '[]' ] + then + [[ $f_ccxt_result =~ ^\[ ]] && [[ $f_ccxt_result =~ \]$ ]] && f_ccxt_json_out=1 + [[ $f_ccxt_result =~ ^\{ ]] && [[ $f_ccxt_result =~ \}$ ]] && f_ccxt_json_out=1 + fi + + # make the output jq-conform if json poutput + # avoids errors like: "parse error: Invalid numeric literal at" if [ -n "$f_ccxt_json_out" ] then - # make the output jq-conform - # avoids errors like: "parse error: Invalid numeric literal at" f_ccxt_result=${f_ccxt_result//\'/\"} f_ccxt_result=${f_ccxt_result// None/ null} f_ccxt_result=${f_ccxt_result// True/ true} @@ -62,6 +64,3 @@ function f_ccxt { return 0 } - - - diff --git a/dabo/functions/currency_converter.sh b/dabo/functions/currency_converter.sh index 195614a..01fe361 100644 --- a/dabo/functions/currency_converter.sh +++ b/dabo/functions/currency_converter.sh @@ -87,6 +87,9 @@ function currency_converter { if [ -n "$f_rate" ] then [[ $f_histfile =~ ${f_currency}${f_currency_target} ]] && f_reverse=true + [ $f_currency_target = "USD" ] && f_reverse=true + [ $f_currency = "USD" ] && f_reverse=false + [ $f_currency_target = "EUR" ] && [ $f_currency = "USD" ] && f_reverse=true [[ $f_line =~ ^$f_currency_date_hour ]] && break fi fi diff --git a/dabo/functions/get_assets.sh b/dabo/functions/get_assets.sh index 8c7634e..af1371d 100644 --- a/dabo/functions/get_assets.sh +++ b/dabo/functions/get_assets.sh @@ -27,17 +27,23 @@ function get_assets { mv ASSETS.tmp ASSETS ## write histfiles parallel - local f_ASSET - local f_parallel_arg - echo -n "parallel -j3 bash -c --" >/tmp/parallel + #local f_ASSET + #local f_parallel_arg + #echo -n "parallel -j3 bash -c --" >/tmp/parallel + #for f_ASSET in $(cat ASSETS | egrep -v "${BLACKLIST}") + #do + # #get_asset "${f_ASSET}" + # echo -n " \"get_asset ${f_ASSET}\"" >>/tmp/parallel + #done + #export f_timestamp + #export csv_headline + #. /tmp/parallel + + ## alternatively single jobs (for debugging!?) for f_ASSET in $(cat ASSETS | egrep -v "${BLACKLIST}") do - #get_asset "${f_ASSET}" - echo -n " \"get_asset ${f_ASSET}\"" >>/tmp/parallel + get_asset "${f_ASSET}" done - export f_timestamp - export csv_headline - . /tmp/parallel } diff --git a/dabo/functions/get_marketdata_historic.sh b/dabo/functions/get_marketdata_historic.sh index 961f9ec..ea3253d 100644 --- a/dabo/functions/get_marketdata_historic.sh +++ b/dabo/functions/get_marketdata_historic.sh @@ -19,12 +19,13 @@ function get_marketdata_yahoo_historic { [[ $f_item = "BLAZE-USD" ]] && f_item="BLAZE30179-USD" [[ $f_item = "BEER-USD" ]] && f_item="BEER31337-USD" [[ $f_item = "TAI-USD" ]] && f_item="TAI20605-USD" + [[ $f_item = "DEFI-USD" ]] && f_item="DEFI29200-USD" # end if already failed the last hour - if [ -f FAILED_YAHOO_${f_name}_HISTORIC_DOWNLOAD ] + if [ -f FAILED_YAHOO/${f_name}_HISTORIC_DOWNLOAD ] then - find "FAILED_YAHOO_${f_name}_HISTORIC_DOWNLOAD" -mmin +60 -delete - if [ -f FAILED_YAHOO_${f_name}_HISTORIC_DOWNLOAD ] + find "FAILED_YAHOO/${f_name}_HISTORIC_DOWNLOAD" -mmin +60 -delete + if [ -f FAILED_YAHOO/${f_name}_HISTORIC_DOWNLOAD ] then #g_echo_note "${f_targetcsv} already failed to downloaded within last hour" return 1 @@ -65,7 +66,8 @@ function get_marketdata_yahoo_historic { #ERR: #$(cat "${f_targetcsvtmp}".err) #" - mv ${f_targetcsvtmp}.err FAILED_YAHOO_${f_name}_HISTORIC_DOWNLOAD + mkdir -p FAILED_YAHOO + mv ${f_targetcsvtmp}.err FAILED_YAHOO/${f_name}_HISTORIC_DOWNLOAD return 1 fi } diff --git a/dabo/functions/get_positions.sh b/dabo/functions/get_positions.sh index 30725ea..69652e7 100644 --- a/dabo/functions/get_positions.sh +++ b/dabo/functions/get_positions.sh @@ -23,7 +23,9 @@ function get_positions { select(.entryPrice != 0) | .symbol + \",\" + (.notional|tostring) + \",\" + (.entryPrice|tostring) + \",\" + (.markPrice|tostring) + \",\" + .side + \",\" + (.leverage|tostring) " CCXT_POSITIONS_RAW >POSITIONS + get_position_array + } function get_position_array { diff --git a/dabo/functions/get_symbols.sh b/dabo/functions/get_symbols.sh index 3dae78a..1630ba4 100644 --- a/dabo/functions/get_symbols.sh +++ b/dabo/functions/get_symbols.sh @@ -2,17 +2,9 @@ function get_symbols { g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" - f_ccxt "print($STOCK_EXCHANGE.symbols)" - if [ -z "$f_ccxt_json_out" ] - then - g_echo_warn "Could not get symbols list - no json output" - return 1 - fi - local f_symbols=${f_ccxt_result} - f_symbols=${f_symbols//\"} - f_symbols=${f_symbols//, /+} - f_symbols=${f_symbols//\[} - f_symbols=${f_symbols//\]} + local f_symbols="" + [ -s CCXT_TICKERS_RAW ] && f_symbols=$(jq -r '.[] | .symbol' CCXT_TICKERS_RAW) + f_symbols=${f_symbols//$'\n'/'+'} if [ -z "$f_symbols" ] then @@ -20,9 +12,8 @@ function get_symbols { return 1 fi - g_array "$f_symbols" f_symbols_array + + g_array "$f_symbols" f_symbols_array_ref + + f_symbols_array=("${g_array[@]}") printf '%s\n' "${f_symbols_array[@]}" >SYMBOLS-$STOCK_EXCHANGE - - }