├── README.md └── update.sh /README.md: -------------------------------------------------------------------------------- 1 | # NFI Tags Auto Updater 2 | 3 | Simple Bash script to check for [NostalgiaForInfinity](https://github.com/iterativv/NostalgiaForInfinity) newly added tags or commits and update it for usage with [Freqtrade](https://github.com/freqtrade/freqtrade) bot. 4 | 5 | # Assumptions 6 | 7 | - Both `freqtrade` and `NostalgiaForInfinity` folders are in the same path level (e.g. /home/ubuntu) 8 | 9 | ## Installation 10 | 11 | Clone the repo: 12 | ``` 13 | git clone https://github.com/krsh-off/nfi-tags-auto-update.git 14 | ``` 15 | 16 | Open `update.sh` file and tweak some variables: 17 | - `ROOT_PATH` - path to the directory where `NostalgiaForInfinityNext` and `freqtrade` directories are places 18 | - `TG_TOKEN` - Telegram token you've got for the bot 19 | - `TG_CHAT_ID` - Telegram chat ID with your bot 20 | - `TG_FT_BOT_ID` - Telegram ID of your Freqtrade bot, the one that ends in `bot` 21 | - `MODE` - check out tags (default) or latest commit in the repo 22 | - `AUTO_RELOAD` - keep it `true` if you want to fully automate the process 23 | 24 | Make the file executable: 25 | ``` 26 | chmod +x update.sh 27 | ``` 28 | 29 | Setup a Cron job to execute the script periodically. 30 | 31 | Log into your server and type `crontab -e`. Next you should be editing the cron file, add in the following line at the bottom of the file. 32 | 33 | ``` 34 | */30 * * * * /bin/bash -c "nfi-tags-auto-update/update.sh" 35 | ``` 36 | 37 | Once that is saved, the updater will check for new git updates every 30 mins and notify you via Telegram if there was anything new so you can restart it. 38 | -------------------------------------------------------------------------------- /update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -x 4 | 5 | MODE="tags" 6 | AUTO_RELOAD=true 7 | 8 | TG_TOKEN="" 9 | TG_CHAT_ID="" 10 | TG_FT_BOT_ID="" 11 | 12 | ROOT_PATH="/home/ubuntu" 13 | NFI_DIR="${ROOT_PATH}/NostalgiaForInfinity" 14 | FT_DIR="${ROOT_PATH}/freqtrade/" 15 | 16 | GIT_URL="https://github.com/iterativv/NostalgiaForInfinity" 17 | 18 | # Go to NFI directory 19 | cd $NFI_DIR 20 | 21 | if [ "$MODE" == "tags" ]; then 22 | # Fetch latest tags 23 | git fetch --tags 24 | 25 | # Get tags names 26 | latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`) 27 | current_tag=$(git describe --tags) 28 | 29 | # Create a new branch with the latest tag name and copy the new version of the strategy 30 | if [ "$latest_tag" != "$current_tag" ]; then 31 | 32 | # Checkout to latest tag and update the NFI in Freqtrade folder 33 | git checkout tags/$latest_tag -b $latest_tag || git checkout $latest_tag 34 | 35 | # Get tag to which the latest tag is pointing 36 | latest_tag_commit=$(git rev-list -n 1 tags/${latest_tag}) 37 | 38 | if $AUTO_RELOAD; then 39 | # Compose the main message send by the bot 40 | message="NFI is updated to tag: *${latest_tag}*" 41 | message+="%0A%0A" 42 | message+="Config has been re-loaded, no actions are required." 43 | 44 | # Do auto-reload 45 | python3 "${FT_DIR}/scripts/rest_client.py" --config "$FT_DIR/user_data/config.json" reload_config 46 | else 47 | # Compose the main message send by the bot 48 | message="NFI is updated to tag: *${latest_tag}*" 49 | message+="%0A%0A" 50 | message+="Please [/reload_config](https://t.me/${TG_FT_BOT_ID}) to get it loaded." 51 | fi 52 | 53 | # Compose buttons for showing git changes and backtesting results 54 | keyboard="{\"inline_keyboard\":[[{\"text\":\"Changes\", \"url\":\"${GIT_URL}/compare/${current_tag}...${latest_tag}\"},{\"text\":\"Backtesting\", \"url\":\"${GIT_URL}/commit/${latest_tag_commit}\"}]]}" 55 | 56 | # Send the message 57 | curl -s --data "text=${message}" \ 58 | --data "reply_markup=${keyboard}" \ 59 | --data "chat_id=$TG_CHAT_ID" \ 60 | --data "parse_mode=markdown" \ 61 | "https://api.telegram.org/bot${TG_TOKEN}/sendMessage" 62 | fi 63 | elif [ "$MODE" == "latest" ]; then 64 | # Get current commit 65 | current_commit=$(git rev-parse --short HEAD) 66 | 67 | # Pull latest changes 68 | git checkout main 69 | git pull origin main 70 | 71 | # Get latest commit 72 | latest_commit=$(git rev-parse --short HEAD) 73 | 74 | if [ "$latest_commit" != "$current_commit" ]; then 75 | if $AUTO_RELOAD; then 76 | # Compose the main message send by the bot 77 | message="NFI is updated to commit: *${latest_commit}*" 78 | message+="%0A%0A" 79 | message+="Config has been re-loaded, no actions are required." 80 | 81 | # Do auto-reload 82 | python3 "${FT_DIR}/scripts/rest_client.py" --config "$FT_DIR/user_data/config.json" reload_config 83 | else 84 | # Compose the main message send by the bot 85 | message="NFI is updated to commit: *${latest_commit}*" 86 | message+="%0A%0A" 87 | message+="Please [/reload_config](https://t.me/${TG_FT_BOT_ID}) to get it loaded." 88 | fi 89 | 90 | # Compose buttons for showing git changes and backtesting results 91 | keyboard="{\"inline_keyboard\":[[{\"text\":\"Changes\", \"url\":\"${GIT_URL}/commit/${latest_commit}\"}]]}" 92 | 93 | # Send the message 94 | curl -s --data "text=${message}" \ 95 | --data "reply_markup=${keyboard}" \ 96 | --data "chat_id=$TG_CHAT_ID" \ 97 | --data "parse_mode=markdown" \ 98 | "https://api.telegram.org/bot${TG_TOKEN}/sendMessage" 99 | fi 100 | 101 | else 102 | echo "Supported modes: tags/latest" 103 | fi --------------------------------------------------------------------------------