This commit is contained in:
olli 2024-07-29 20:09:41 +02:00
parent 4f45f1c98a
commit 39b10958d5
7 changed files with 53 additions and 24 deletions

View File

@ -3,11 +3,11 @@
BASEPATH=/dabo/htdocs BASEPATH=/dabo/htdocs
# load functions # load functions
. /etc/bash/gaboshlib.include
for bashfunc in $(find ${BASEPATH}/../functions -type f -name "*.sh") for bashfunc in $(find ${BASEPATH}/../functions -type f -name "*.sh")
do do
. "$bashfunc" . "$bashfunc"
done done
. /etc/bash/gaboshlib.include
# vars # vars
LANGUAGE="en_US" LANGUAGE="en_US"
@ -21,3 +21,6 @@ set +a
mkdir -p ${BASEPATH}/botdata/asset-histories mkdir -p ${BASEPATH}/botdata/asset-histories
cd ${BASEPATH}/botdata cd ${BASEPATH}/botdata
. ../../dabo-bot.conf
. ../../dabo-bot.override.conf

View File

@ -2,7 +2,7 @@
. /dabo/dabo-prep.sh . /dabo/dabo-prep.sh
#sleep 1800 sleep 1800
while true while true
do do
g_echo_note "Next loop" g_echo_note "Next loop"

View File

@ -13,7 +13,7 @@ function get_ohlcv-candles {
do do
for f_timeframe in $f_timeframes for f_timeframe in $f_timeframes
do do
echo "=== Fetching/Refreshing $f_eco_asset $f_timeframe ===" g_echo_note "Fetching/Refreshing $f_eco_asset $f_timeframe"
f_histfile="asset-histories/ECONOMY-${f_eco_asset}.history.${f_timeframe}.csv" f_histfile="asset-histories/ECONOMY-${f_eco_asset}.history.${f_timeframe}.csv"
# 4h timefrage does not exist on yahoo finance so calc from 1h # 4h timefrage does not exist on yahoo finance so calc from 1h

View File

@ -12,12 +12,13 @@ function get_symbols_ticker {
if [ "$f_fetch" = "refetchonly" ] if [ "$f_fetch" = "refetchonly" ]
then then
# fetch from exchange # fetch from exchange
f_ccxt "print(${STOCK_EXCHANGE}.fetch_tickers())" && echo $f_ccxt_result >CCXT_TICKERS_RAW-${STOCK_EXCHANGE} rm -f CCXT_TICKERS-${STOCK_EXCHANGE}.tmp
f_ccxt "print(${STOCK_EXCHANGE}.fetch_tickers())" && echo $f_ccxt_result >CCXT_TICKERS_RAW-${STOCK_EXCHANGE}
# parse relevant tokens # parse relevant tokens
local f_grep="${CURRENCY}," local f_grep="${CURRENCY},"
[ -n "$LEVERAGE" ] && f_grep="${CURRENCY}:${CURRENCY}," [ -n "$LEVERAGE" ] && f_grep="${CURRENCY}:${CURRENCY},"
[ -s CCXT_TICKERS_RAW-${STOCK_EXCHANGE} ] && jq -r '.[] | .symbol + "," + (.last|tostring)' CCXT_TICKERS_RAW-${STOCK_EXCHANGE} | grep "${f_grep}" >CCXT_TICKERS-${STOCK_EXCHANGE}.tmp [ -s CCXT_TICKERS_RAW-${STOCK_EXCHANGE} ] && jq -r '.[] | .symbol + "," + (.last|tostring)' CCXT_TICKERS_RAW-${STOCK_EXCHANGE} | grep "${f_grep}" | egrep ".+,[0-9]" >CCXT_TICKERS-${STOCK_EXCHANGE}.tmp
if [ -s CCXT_TICKERS-${STOCK_EXCHANGE}.tmp ] if [ -s CCXT_TICKERS-${STOCK_EXCHANGE}.tmp ]
then then
@ -31,15 +32,18 @@ function get_symbols_ticker {
| grep ",$(date +%Y)-" \ | grep ",$(date +%Y)-" \
| sort -r -n -t, -k7 \ | sort -r -n -t, -k7 \
| cut -d. -f2 \ | cut -d. -f2 \
>CCXT_SYMBOLS-$STOCK_EXCHANGE-by-volume >CCXT_SYMBOLS-$STOCK_EXCHANGE-by-volume.tmp
# add mising (not yet fetched) symbols # add mising (not yet fetched) symbols
awk 'NR==FNR{a[$0];next} !($0 in a)' CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume CCXT_SYMBOLS-$STOCK_EXCHANGE >>CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume awk 'NR==FNR{a[$0];next} !($0 in a)' CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume.tmp CCXT_SYMBOLS-$STOCK_EXCHANGE >>CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume.tmp
# remove (no more) existing symbols # remove (no more) existing symbols
awk 'NR==FNR{a[$0];next} !($0 in a)' CCXT_SYMBOLS-$STOCK_EXCHANGE CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume \ awk 'NR==FNR{a[$0];next} !($0 in a)' CCXT_SYMBOLS-$STOCK_EXCHANGE CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume.tmp \
| while read f_remove_symbol | while read f_remove_symbol
do do
sed -i "\#${f_remove_symbol}#d" CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume sed -i "\#${f_remove_symbol}#d" CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume.tmp
done done
# write filan volume file
[ -s CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume.tmp ] && mv CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume.tmp CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume
# write file with symbols that should be traded # write file with symbols that should be traded
rm -f CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume-trade.tmp rm -f CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume-trade.tmp
@ -66,22 +70,16 @@ function get_symbols_ticker {
do do
f_symbol=${f_ticker%%:*} f_symbol=${f_ticker%%:*}
f_symbol=${f_symbol//\/} f_symbol=${f_symbol//\/}
f_symbol=${f_symbol/ /} #f_symbol=${f_symbol/ /}
f_price=${f_ticker/*,/} f_price=${f_ticker/*,/}
g_num_exponential2normal $f_price && f_price=$g_num_exponential2normal_result g_num_exponential2normal $f_price && f_price=$g_num_exponential2normal_result
# remove from symbol-list if price is invalid
if ! g_num_valid_number $f_price 2>/dev/null
then
f_remove_symbol=${f_ticker/,*/}
sed -i "\#${f_remove_symbol}#d" CCXT_SYMBOLS-${STOCK_EXCHANGE} CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume
continue
fi
f_tickers_array[$f_symbol]=$f_price f_tickers_array[$f_symbol]=$f_price
done done
fi fi
# create array with ccxt symbols sorted by volume # create array with ccxt symbols sorted by volume
pwd
ls -l CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume
[ -s CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume ] && g_array CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume f_symbols_array_ref [ -s CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume ] && g_array CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume f_symbols_array_ref
f_symbols_array=("${f_symbols_array_ref[@]}") f_symbols_array=("${f_symbols_array_ref[@]}")
@ -89,7 +87,6 @@ function get_symbols_ticker {
[ -s CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume-trade ] && g_array CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume-trade f_symbols_array_trade_ref [ -s CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume-trade ] && g_array CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume-trade f_symbols_array_trade_ref
f_symbols_array_trade=("${f_symbols_array_ref[@]}") f_symbols_array_trade=("${f_symbols_array_ref[@]}")
# create f_symbols var # create f_symbols var
[ -s CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume ] && f_symbols=$(cat CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume) [ -s CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume ] && f_symbols=$(cat CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume)
f_symbols=${f_symbols//$'\n'/'+'} f_symbols=${f_symbols//$'\n'/'+'}
@ -102,8 +99,8 @@ function get_symbols_ticker {
return 1 return 1
fi fi
sleep 5 sleep 5
get_symbols_ticker retry || return 1
g_echo_note "Could not get symbols list - empty - retrying" g_echo_note "Could not get symbols list - empty - retrying"
get_symbols_ticker retry || return 1
fi fi
} }

View File

@ -4,6 +4,8 @@ function get_transactions {
local f_exchange f_symbol f_symbol_file f_asset f_currency f_leverage f_convert_end_month f_convert_end_year f_symbol_file_csv f_symbol_file_csv_tmp f_start_date f_end_date f_convert_file f_fiat f_fiats local f_exchange f_symbol f_symbol_file f_asset f_currency f_leverage f_convert_end_month f_convert_end_year f_symbol_file_csv f_symbol_file_csv_tmp f_start_date f_end_date f_convert_file f_fiat f_fiats
local DEFAULT_STOCK_EXCHANGE=$STOCK_EXCHANGE local DEFAULT_STOCK_EXCHANGE=$STOCK_EXCHANGE
local DEFAULT_LEVERAGE=$LEVERAGE
for f_exchange in /dabo/.*-secrets; for f_exchange in /dabo/.*-secrets;
do do
@ -21,7 +23,9 @@ function get_transactions {
# refetch symbols if not default exchange # refetch symbols if not default exchange
if ! [[ $DEFAULT_STOCK_EXCHANGE = $STOCK_EXCHANGE ]] if ! [[ $DEFAULT_STOCK_EXCHANGE = $STOCK_EXCHANGE ]]
then then
unset LEVERAGE
get_symbols_ticker refetchonly get_symbols_ticker refetchonly
LEVERAGE=$DEFAULT_LEVERAGE
fi fi
# load symbols to array # load symbols to array

View File

@ -14,7 +14,7 @@ function transactions_overview {
local f_exchange f_asset f_transactions_array f_transaction f_result f_asset_quantity f_asset_quantity_sold f_currency_quantity f_currency_quantity_sold f_currency_spent f_date f_type f_asset_amount f_currency f_currency_amount f_fee_currency f_fee_amount f_sell_result f_taxable f_tax_type f_one_year_ago f_currency_amount_eur f_currency_spent_eur f_currency_quantity_sold_eur f_note f_asset_quantity_remaining f_currency_remaining f_year f_currency_spent_eur_tax f_currency_quantity_sold_eur_tax f_sell_result_percentage f_sell_result_percentage_eur local f_exchange f_asset f_transactions_array f_transaction f_result f_asset_quantity f_asset_quantity_sold f_currency_quantity f_currency_quantity_sold f_currency_spent f_date f_type f_asset_amount f_currency f_currency_amount f_fee_currency f_fee_amount f_sell_result f_taxable f_tax_type f_one_year_ago f_currency_amount_eur f_currency_spent_eur f_currency_quantity_sold_eur f_note f_asset_quantity_remaining f_currency_remaining f_year f_currency_spent_eur_tax f_currency_quantity_sold_eur_tax f_sell_result_percentage f_sell_result_percentage_eur
f_assets_per_exchange=$(egrep -h -v '^DATE,TYPE,ASSET,ASSET_AMOUNT,CURRENCY,CURRENCY_AMOUNT,EXCHANGE|^#|^$|^ +$|^$' TRANSACTIONS-*.csv | cut -d, -f3,7 | sort -u) f_assets_per_exchange=$(egrep -h -v '^DATE,TYPE,ASSET,ASSET_AMOUNT,CURRENCY,CURRENCY_AMOUNT,EXCHANGE|^#|^$|^ +$' TRANSACTIONS-*.csv | cut -d, -f3,7 | sort -u)
for f_asset_per_exchange in ${f_assets_per_exchange} for f_asset_per_exchange in ${f_assets_per_exchange}
do do

View File

@ -247,6 +247,31 @@ services:
cpus: '0.5' cpus: '0.5'
memory: 512M memory: 512M
# dabo-test:
# build:
# context: .
# dockerfile: Dockerfile
# restart: no
# user: 10000:10000
# volumes:
# - ./dabo:/dabo:ro
# - ./strategies:/dabo/strategies:ro
# - ./dabo-bot.conf:/dabo/dabo-bot.override.conf
## - ./watch-assets.csv:/dabo/watch-assets.csv
# - ./data:/dabo/htdocs:rw
# - ./home:/dabo/home:rw
# - /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro
# - /usr/local/etc/notify.conf:/usr/local/etc/notify.conf:ro
# - /etc/localtime:/etc/localtime:ro
# entrypoint: /dabo/test.sh
# cpu_shares: 128
# deploy:
# resources:
# limits:
# cpus: '0.5'
# memory: 512M
dabo-webpage: dabo-webpage:
build: build:
context: . context: .