Skip to content

Instantly share code, notes, and snippets.

@ifthenelse
Last active January 29, 2024 07:55
Show Gist options
  • Save ifthenelse/def05b24f4a2175b26469daf20337d80 to your computer and use it in GitHub Desktop.
Save ifthenelse/def05b24f4a2175b26469daf20337d80 to your computer and use it in GitHub Desktop.
freqtrade docker bots strategy update cronjob
#!/bin/zsh
# Force pairlist/blacklists and strategies update?
FORCEUPDATE=0
# Add git commits
ADDGITCOMMITS=0
# Default root path
ROOT_PATH="${HOME}"
# Get function params
while [[ "$#" -gt 0 ]]
do case $1 in
-f|--force-update) FORCEUPDATE=1
shift;;
-r|--root-path) ROOT_PATH="$2"
shift;;
-g|--git) ADDGITCOMMITS=1
shift;;
*) echo "Unknown parameter passed: $1"
exit 1;;
esac
# shift
done
# --- Configuration start ---
# enable update on bots
FTLIVE00_UPDATE=true
FTDRY00_UPDATE=false
# FTLIVE00 strategy local source
FTLIVE00_STRATEGY_SRC_PATH="${ROOT_PATH}/nfi"
FTLIVE00_STRATEGY_PATH="${FTLIVE00_STRATEGY_SRC_PATH}/NostalgiaForInfinityX4.py"
FTLIVE00_PAIRLIST_PATH="${FTLIVE00_STRATEGY_SRC_PATH}/configs/pairlist-volume-binance-usdt.json"
FTLIVE00_BLACKLIST_PATH="${FTLIVE00_STRATEGY_SRC_PATH}/configs/blacklist-binance.json"
# FTDRY00 strategy local source
FTDRY00_STRATEGY_SRC_PATH="${ROOT_PATH}/BB_RPB_TSL"
FTDRY00_STRATEGY_PATH="${FTDRY00_STRATEGY_SRC_PATH}/BB_RPB_TSL_BI.py"
FTDRY00_PAIRLIST_PATH="${FTDRY00_STRATEGY_SRC_PATH}/config_dynamic.json"
FTDRY00_BLACKLIST_PATH="${FTLIVE00_BLACKLIST_PATH}" # Use ftLive00 blacklist for ftDry00
# Local Freqtrade instance and repository
FT_USERDATA_PATH="${ROOT_PATH}/ft/user_data"
# FTLIVE00 bot configs
FT_FTLIVE00_STRATEGY_PATH="${FT_USERDATA_PATH}/strategies/NostalgiaForInfinityX4.py"
FT_FTLIVE00_PAIRLIST_PATH="${FT_USERDATA_PATH}/config.pairlist.ftLive00.json"
FT_FTLIVE00_BLACKLIST_PATH="${FT_USERDATA_PATH}/config.blacklist.ftLive00.json"
# FTDRY00 bot configs
FT_FTDRY00_STRATEGY_PATH="${FT_USERDATA_PATH}/strategies/BB_RPB_TSL_BI.py"
FT_FTDRY00_PAIRLIST_PATH="${FT_USERDATA_PATH}/config.pairlist.ftDry00.json"
FT_FTDRY00_BLACKLIST_PATH="${FT_USERDATA_PATH}/config.blacklist.ftDry00.json"
# Telegram Bot Live 00 token
TG_FT_LIVE_00_TOKEN="sometoken_live_00"
# Telegram Bot Dry 00 token
TG_FT_DRY_00_TOKEN="sometoken_dry_00"
# Telegram Chat ID (unique)
# get it from https://api.telegram.org/bot<BOT_TOKEN>/getUpdates and look for the "chat" field in the output JSON
TG_CHAT_ID="telegram_chat_id"
# --- Configuration end ---
# --- Strategies source code update start ---
# pull ftLive00 strategy source code
cd "$FTLIVE00_STRATEGY_SRC_PATH"
git checkout main
git fetch origin
# check pairlist updates for ftLive00
HAS_FTLIVE00_PAIRLIST_UPDATES=`git diff --name-only origin/main main | grep 'configs/pairlist-volume-binance-usdt.json'`
FTLIVE00_PAIRLIST_REF_COMMIT_HASH=`git log -1 --oneline HEAD..origin/main -- 'configs/pairlist-volume-binance-usdt.json'`
# check blacklist updates for ftLive00
HAS_FTLIVE00_BLACKLIST_UPDATES=`git diff --name-only origin/main main | grep 'configs/blacklist-binance.json'`
FTLIVE00_BLACKLIST_REF_COMMIT_HASH=`git log -1 --oneline HEAD..origin/main -- 'configs/blacklist-binance.json'`
# check for ftLive00 strategy updates
HAS_FTLIVE00_STRATEGY_UPDATES=`git diff --name-only origin/main main | grep 'NostalgiaForInfinityX4.py'`
FTLIVE00_STRATEGY_REF_COMMIT_HASH=`git log -1 --oneline HEAD..origin/main -- 'NostalgiaForInfinityX4.py'`
# pull ftDry00 strategy source code
cd "$FTDRY00_STRATEGY_SRC_PATH"
git checkout main
git fetch origin
# check pairlist updates for ftDry00 (uses same from ftLive00)
HAS_FTDRY00_PAIRLIST_UPDATES=`git diff --name-only origin/main main | grep 'configs/pairlist-volume-kucoin-usdt.json'`
FTDRY00_PAIRLIST_REF_COMMIT_HASH=`git log -1 --oneline HEAD..origin/main -- 'configs/pairlist-volume-kucoin-usdt.json'`
# check blacklist updates for ftDry00 (uses same from ftLive00)
HAS_FTDRY00_BLACKLIST_UPDATES=`git diff --name-only origin/main main | grep 'config_dynamic.json'`
FTDRY00_BLACKLIST_REF_COMMIT_HASH=`git log -1 --oneline HEAD..origin/main -- 'config_dynamic.json'`
# check for ftDry00 strategy updates
HAS_FTDRY00_STRATEGY_UPDATES=`git diff --name-only origin/main main | grep 'BB_RPB_TSL_BI.py'`
FTDRY00_STRATEGY_REF_COMMIT_HASH=`git log -1 --oneline HEAD..origin/main -- 'BB_RPB_TSL_BI.py'`
# if nothing to update, don't go any further
if [[ $FORCEUPDATE -eq 0 && -z $HAS_FTLIVE00_PAIRLIST_UPDATES && -z $HAS_FTLIVE00_BLACKLIST_UPDATES && -z $HAS_FTDRY00_PAIRLIST_UPDATES && -z $HAS_FTDRY00_BLACKLIST_UPDATES && -z $HAS_FTLIVE00_STRATEGY_UPDATES && -z $HAS_FTDRY00_STRATEGY_UPDATES ]]; then
echo "no update"
exit 1
fi
# update step 1 - ftLive00 pairlist and blacklist
# send update message to ftLive00 if pairlist and/or blacklist have been updated
if [[ $FTLIVE00_UPDATE = "true" ]]; then
# pull repo of ftLive00 strategy
cd "$FTLIVE00_STRATEGY_SRC_PATH"
git pull
# move to FT directory
cd "$FT_USERDATA_PATH"
cd ..
if [[ $FORCEUPDATE -eq 1 || $HAS_FTLIVE00_PAIRLIST_UPDATES || $HAS_FTLIVE00_BLACKLIST_UPDATES ]]; then
cp "$FTLIVE00_PAIRLIST_PATH" "$FT_FTLIVE00_PAIRLIST_PATH"
cp "$FTLIVE00_BLACKLIST_PATH" "$FT_FTLIVE00_BLACKLIST_PATH"
curl -s --data "text="$'\U1F4DD'" Updated pairlist and blacklist.%0APairlist ref commit hash:%0A %60$FTLIVE00_PAIRLIST_REF_COMMIT_HASH%60%0A%0ABlacklist commit hash:%0A%60$FTLIVE00_BLACKLIST_REF_COMMIT_HASH%60" \
--data "parse_mode=markdown" \
--data "chat_id=$TG_CHAT_ID" \
"https://api.telegram.org/bot$TG_FT_LIVE_00_TOKEN/sendMessage"
if [[ $ADDGITCOMMITS -eq 1 ]]; then
git add "$FT_FTLIVE00_PAIRLIST_PATH"
git commit -m "Update ftLive00 pairslist - Ref commit $FTLIVE00_PAIRLIST_REF_COMMIT_HASH"
git add "$FT_FTLIVE00_BLACKLIST_PATH"
git commit -m "Update ftLive00 blacklist - Ref commit $FTLIVE00_BLACKLIST_REF_COMMIT_HASH"
fi
fi
# update step 2 - update ftLive00 strategy
# send update message to ftLive00 if strategy has been updated
# and restart ftLive00 docker compose service
if [[ $FORCEUPDATE -eq 1 || $HAS_FTLIVE00_STRATEGY_UPDATES ]]; then
cp "$FTLIVE00_STRATEGY_PATH" "$FT_FTLIVE00_STRATEGY_PATH"
FTLIVE00_STRATEGY_LATEST_TAG=$(cat $FT_FTLIVE00_STRATEGY_PATH | grep -o "v[0-9]*\.[0-9]*\.[0-9]*")
curl -s --data "text="$'\U1F504'" NostalgiaForInfinityX4 is being updated to version: *$FTLIVE00_STRATEGY_LATEST_TAG*.%0ARef commit hash: %60$FTLIVE00_STRATEGY_REF_COMMIT_HASH%60%0APlease wait for reload..." \
--data "parse_mode=markdown" \
--data "chat_id=$TG_CHAT_ID" \
"https://api.telegram.org/bot$TG_FT_LIVE_00_TOKEN/sendMessage"
if [[ $ADDGITCOMMITS -eq 1 ]]; then
git add "$FT_FTLIVE00_STRATEGY_PATH"
git commit -m "Update NostalgiaForInfinityX4 to version $FTLIVE00_STRATEGY_LATEST_TAG - Ref commit $FTLIVE00_STRATEGY_REF_COMMIT_HASH"
fi
fi
# if updated, restart the ftLive00 bot
if [[ $FORCEUPDATE -eq 1 || $HAS_FTLIVE00_PAIRLIST_UPDATES || $HAS_FTLIVE00_BLACKLIST_UPDATES || $HAS_FTLIVE00_STRATEGY_UPDATES ]]; then;
docker compose -f docker-compose.`hostname`.yml restart ftLive00
fi
fi
# update step 3 - ftDry00 pairlist and blacklist
# send update message to ftDry00 if pairlist and/or blacklist have been updated
if [[ $FTDRY00_UPDATE = "true" ]]; then
# pull repo of ftDry00 strategy and pairlist / blacklist
cd "$FTDRY00_STRATEGY_SRC_PATH"
git pull
# move to FT directory
cd "$FT_USERDATA_PATH"
cd ..
if [[ $FORCEUPDATE -eq 1 || $HAS_FTDRY00_PAIRLIST_UPDATES || $HAS_FTDRY00_BLACKLIST_UPDATES ]]; then
cp "$FTDRY00_PAIRLIST_PATH" "$FT_FTDRY00_PAIRLIST_PATH"
cp "$FTDRY00_BLACKLIST_PATH" "$FT_FTDRY00_BLACKLIST_PATH"
curl -s --data "text="$'\U1F4DD'" Updated pairlist and blacklist.%0APairlist ref commit hash:%0A %60$FTDRY00_PAIRLIST_REF_COMMIT_HASH%60%0A%0ABlacklist commit hash:%0A%60$FTDRY00_BLACKLIST_REF_COMMIT_HASH%60" \
--data "parse_mode=markdown" \
--data "chat_id=$TG_CHAT_ID" \
"https://api.telegram.org/bot$TG_FT_DRY_02_TOKEN/sendMessage"
if [[ $ADDGITCOMMITS -eq 1 ]]; then
git add "$FT_FTDRY00_PAIRLIST_PATH"
git commit -m "Update ftDry00 pairslist - Ref commit $FTDRY00_PAIRLIST_REF_COMMIT_HASH"
git add "$FT_FTDRY00_BLACKLIST_PATH"
git commit -m "Update ftDry00 blacklist - Ref commit $FTDRY00_BLACKLIST_REF_COMMIT_HASH"
fi
fi
# update step 4 - update ftDry00 strategy (no)
# send update message to ftDry00 if strategy has been updated
# and restart ftDry00 docker compose service
if [[ $FORCEUPDATE -eq 1 || $HAS_FTDRY00_STRATEGY_UPDATES ]]; then
cp "$FTDRY00_STRATEGY_PATH" "$FT_FTDRY00_STRATEGY_PATH"
FTDRY00_STRATEGY_LATEST_TAG=$(cat $FT_FTDRY00_STRATEGY_PATH | grep -o "v[0-9]*\.[0-9]*\.[0-9]*")
curl -s --data "text="$'\U1F504'" BB_RPB_TSL_BI is being updated to version: *$FTDRY00_STRATEGY_LATEST_TAG*.%0ARef commit hash: %60$FTDRY00_STRATEGY_REF_COMMIT_HASH%60%0APlease wait for reload..." \
--data "parse_mode=markdown" \
--data "chat_id=$TG_CHAT_ID" \
"https://api.telegram.org/bot$TG_FT_DRY_02_TOKEN/sendMessage"
if [[ $ADDGITCOMMITS -eq 1 ]]; then
git add "$FT_FTDRY00_STRATEGY_PATH"
git commit -m "Update BB_RPB_TSL_BI to version $FTDRY00_STRATEGY_LATEST_TAG - Ref commit $FTDRY00_STRATEGY_REF_COMMIT_HASH"
fi
fi
# if updated, restart the ftDry00 bot
if [[ $FORCEUPDATE -eq 1 || $HAS_FTDRY00_PAIRLIST_UPDATES || $HAS_FTDRY00_BLACKLIST_UPDATES || $HAS_FTDRY00_STRATEGY_UPDATES ]]; then;
docker compose -f docker-compose.`hostname`.yml restart ftDry00
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment