J2897

Freqtrade Docker Cronjobs

Sep 6th, 2022 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!

Cronjobs

Run crontab -e to add...

33 3  * * *     /home/J2897/Code/Bash/update_strat.sh           >> /home/J2897/freqtrade/user_data/logs/strat_updates.log
33 15 * * 3     /home/J2897/Code/Bash/update_dc.sh              >> /home/J2897/freqtrade/user_data/logs/dc_updates.log

update_dc.sh

Pulls the latest Docker Container and restarts...

#! /usr/bin/bash
cd '/home/J2897/freqtrade/'
echo "$(date) - Pulling the most recent docker container... "
docker compose down && docker compose pull && docker compose up -d
echo "$(date) - Finished."

update_strat.sh

Updates the strategy file when it's released and restarts...

#! /usr/bin/bash
cd '/home/J2897/freqtrade/'
echo "$(date) - Checking for strategy updates... "

# Get file Modified date as a UTS.
FILE1='/home/J2897/freqtrade/user_data/strategies/NostalgiaForInfinityX.py'
FILE_UTS=$(stat --printf='%Y' $FILE1) # %Y is the time of last data modification in seconds since Epoch.

# Get the published date of the latest release.
get_release_date() {
  curl --fail --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release info from GitHub API.
    grep '"published_at":' |                                               # Get date line.
    sed -E 's/.*"([^"]+)".*/\1/'                                           # Pluck JSON value.
}
# get_release_date() {
    # curl --fail --silent "https://api.github.com/repos/$1/releases/latest" |
    # jq -r .published_at
# }

# Update if there's a newer version.
RAW_CODE_URL='https://raw.githubusercontent.com/iterativv/NostalgiaForInfinity/main/NostalgiaForInfinityX.py'
# CURRENT_UTS=$(date '+%s')
PUBLISHED_UTS=$(date -d "$(get_release_date 'iterativv/NostalgiaForInfinity')" '+%s')
if [ $PUBLISHED_UTS -ge $FILE_UTS ];
then
    echo 'A newer version is available. Downloading...'
    curl --fail --silent "$RAW_CODE_URL" -o "$FILE1"
    docker compose down && docker compose up -d
fi
echo "$(date) - Finished."

Aliases

_Add these to your .bash_aliases file..._

alias restart-dc='docker compose down && docker compose pull && docker compose up -d'
alias update-dc='/home/J2897/Code/Bash/update_dc.sh'
alias update-strat='/home/J2897/Code/Bash/update_strat.sh'
Add Comment
Please, Sign In to add comment