From f68c15cf3e684f57fc4de6cced61c8366e86644c Mon Sep 17 00:00:00 2001 From: olli Date: Fri, 19 May 2023 08:03:48 +0200 Subject: [PATCH] example script for recalc history data --- dabo/recalc-histories-example.sh | 82 ++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 dabo/recalc-histories-example.sh diff --git a/dabo/recalc-histories-example.sh b/dabo/recalc-histories-example.sh new file mode 100644 index 0000000..f68d116 --- /dev/null +++ b/dabo/recalc-histories-example.sh @@ -0,0 +1,82 @@ +#!/bin/bash -e + +. /etc/bash/gaboshlib.include + +g_lockfile + +for bashfunc in $(find dabo/functions -type f -name "*.sh") +do + . "$bashfunc" +done + + +function get_asset { + + local f_ASSET_HIST_FILE=$1 + local rawhistfile=$2 + + echo "$rawhistfile - $f_ASSET_HIST_FILE" + + #cat "$rawhistfile" | egrep ":00:|:15:|:30:|:45:" | while read f_line + cat "$rawhistfile" | egrep " 14:00:" | while read f_line + do + + ######## FROM get_asset.sh ######## + + [ -s "${f_ASSET_HIST_FILE}" ] || echo "${csv_headline}" >"${f_ASSET_HIST_FILE}" + # date and price + echo -n "${f_line}" >>${f_ASSET_HIST_FILE} + + # calculate price change percentage + local f_last_price=$(tail -n2 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f2) + if echo $f_last_price | grep -q "^[0-9]" + then + local f_price=$(tail -n1 ${f_ASSET_HIST_FILE} | cut -d, -f2) + local f_price_change=$(g_percentage-diff ${f_last_price} ${f_price}) + else + local f_price_change="" + fi + echo -n ",${f_price_change}" >>"${f_ASSET_HIST_FILE}" + + # calculate macd and rsi + get_macd_indicator ${f_ASSET_HIST_FILE} + get_rsi_indicator ${f_ASSET_HIST_FILE} 5 + get_rsi_indicator ${f_ASSET_HIST_FILE} 14 + get_rsi_indicator ${f_ASSET_HIST_FILE} 21 + get_rsi_indicator ${f_ASSET_HIST_FILE} 720 + get_rsi_indicator ${f_ASSET_HIST_FILE} 60 + get_rsi_indicator ${f_ASSET_HIST_FILE} 120 + get_rsi_indicator ${f_ASSET_HIST_FILE} 240 + get_rsi_indicator ${f_ASSET_HIST_FILE} 480 + + # get coingecko price change + f_asset=$(echo ${f_ASSET} | sed "s/${CURRENCY}\$//" | tr '[:upper:]' '[:lower:]') + echo -n ,100 >>${f_ASSET_HIST_FILE} + echo -n ,100 >>${f_ASSET_HIST_FILE} + echo -n ,100 >>${f_ASSET_HIST_FILE} + echo -n ,100 >>${f_ASSET_HIST_FILE} + + # end with newline + echo "" >>${f_ASSET_HIST_FILE} + + done + +} + + + +export csv_headline="Date and Time,Price,Price Change,EMA12,EMA26,MACD,EMA9 MACD (Signal),MACD Histogram,MACD Signal,RSI5,RSI14,RSI21,RSI720,RSI60,RSI120,RSI240,RSI420,Price Change 24h,Price Change 7d,Price Change 14d,Price Change 30d" + +echo -n "parallel -j16 bash -c --" >/tmp/parallel + +find home/docker/dabo-binance.ds9.dedyn.io/data/botdata/asset-histories -name "*.history-raw.csv" | while read rawhistfile +do + + export f_ASSET_HIST_FILE=$(echo "$rawhistfile" | sed 's/history-raw.csv/history.csv/') + + echo -n " \"get_asset ${f_ASSET_HIST_FILE} ${rawhistfile}\" " >>/tmp/parallel + +done + +export -f get_asset +. /tmp/parallel