| 1 | #!/usr/bin/env bash |
| 2 | #encoding=utf8 |
| 3 | |
| 4 | function check_installed_pip() { |
| 5 | ${PYTHON} -m pip > /dev/null |
| 6 | if [ $? -ne 0 ]; then |
| 7 | echo "pip not found (called as '${PYTHON} -m pip'). Please make sure that pip is available for ${PYTHON}." |
| 8 | exit 1 |
| 9 | fi |
| 10 | } |
| 11 | |
| 12 | # Check which python version is installed |
| 13 | function check_installed_python() { |
| 14 | if [ -n "${VIRTUAL_ENV}" ]; then |
| 15 | echo "Please deactivate your virtual environment before running setup.sh." |
| 16 | echo "You can do this by running 'deactivate'." |
| 17 | exit 2 |
| 18 | fi |
| 19 | |
| 20 | which python3.8 |
| 21 | if [ $? -eq 0 ]; then |
| 22 | echo "using Python 3.8" |
| 23 | PYTHON=python3.8 |
| 24 | check_installed_pip |
| 25 | return |
| 26 | fi |
| 27 | |
| 28 | which python3.9 |
| 29 | if [ $? -eq 0 ]; then |
| 30 | echo "using Python 3.9" |
| 31 | PYTHON=python3.9 |
| 32 | check_installed_pip |
| 33 | return |
| 34 | fi |
| 35 | |
| 36 | which python3.7 |
| 37 | if [ $? -eq 0 ]; then |
| 38 | echo "using Python 3.7" |
| 39 | PYTHON=python3.7 |
| 40 | check_installed_pip |
| 41 | return |
| 42 | fi |
| 43 | |
| 44 | |
| 45 | if [ -z ${PYTHON} ]; then |
| 46 | echo "No usable python found. Please make sure to have python3.7 or newer installed" |
| 47 | exit 1 |
| 48 | fi |
| 49 | } |
| 50 | |
| 51 | function updateenv() { |
| 52 | echo "-------------------------" |
| 53 | echo "Updating your virtual env" |
| 54 | echo "-------------------------" |
| 55 | if [ ! -f .env/bin/activate ]; then |
| 56 | echo "Something went wrong, no virtual environment found." |
| 57 | exit 1 |
| 58 | fi |
| 59 | source .env/bin/activate |
| 60 | SYS_ARCH=$(uname -m) |
| 61 | echo "pip install in-progress. Please wait..." |
| 62 | ${PYTHON} -m pip install --upgrade pip |
| 63 | read -p "Do you want to install dependencies for dev [y/N]? " |
| 64 | if [[ $REPLY =~ ^[Yy]$ ]] |
| 65 | then |
| 66 | REQUIREMENTS=requirements-dev.txt |
| 67 | else |
| 68 | REQUIREMENTS=requirements.txt |
| 69 | fi |
| 70 | REQUIREMENTS_HYPEROPT="" |
| 71 | REQUIREMENTS_PLOT="" |
| 72 | read -p "Do you want to install plotting dependencies (plotly) [y/N]? " |
| 73 | if [[ $REPLY =~ ^[Yy]$ ]] |
| 74 | then |
| 75 | REQUIREMENTS_PLOT="-r requirements-plot.txt" |
| 76 | fi |
| 77 | if [ "${SYS_ARCH}" == "armv7l" ]; then |
| 78 | echo "Detected Raspberry, installing cython, skipping hyperopt installation." |
| 79 | ${PYTHON} -m pip install --upgrade cython |
| 80 | else |
| 81 | # Is not Raspberry |
| 82 | read -p "Do you want to install hyperopt dependencies [y/N]? " |
| 83 | if [[ $REPLY =~ ^[Yy]$ ]] |
| 84 | then |
| 85 | REQUIREMENTS_HYPEROPT="-r requirements-hyperopt.txt" |
| 86 | fi |
| 87 | fi |
| 88 | |
| 89 | ${PYTHON} -m pip install --upgrade -r ${REQUIREMENTS} ${REQUIREMENTS_HYPEROPT} ${REQUIREMENTS_PLOT} |
| 90 | if [ $? -ne 0 ]; then |
| 91 | echo "Failed installing dependencies" |
| 92 | exit 1 |
| 93 | fi |
| 94 | ${PYTHON} -m pip install -e . |
| 95 | if [ $? -ne 0 ]; then |
| 96 | echo "Failed installing Freqtrade" |
| 97 | exit 1 |
| 98 | fi |
| 99 | echo "pip install completed" |
| 100 | echo |
| 101 | } |
| 102 | |
| 103 | # Install tab lib |
| 104 | function install_talib() { |
| 105 | if [ -f /usr/local/lib/libta_lib.a ]; then |
| 106 | echo "ta-lib already installed, skipping" |
| 107 | return |
| 108 | fi |
| 109 | |
| 110 | cd build_helpers |
| 111 | tar zxvf ta-lib-0.4.0-src.tar.gz |
| 112 | cd ta-lib |
| 113 | sed -i.bak "s|0.00000001|0.000000000000000001 |g" src/ta_func/ta_utility.h |
| 114 | ./configure --prefix=/usr/local |
| 115 | make |
| 116 | sudo make install |
| 117 | if [ -x "$(command -v apt-get)" ]; then |
| 118 | echo "Updating library path using ldconfig" |
| 119 | sudo ldconfig |
| 120 | fi |
| 121 | cd .. && rm -rf ./ta-lib/ |
| 122 | cd .. |
| 123 | } |
| 124 | |
| 125 | # Install bot MacOS |
| 126 | function install_macos() { |
| 127 | if [ ! -x "$(command -v brew)" ] |
| 128 | then |
| 129 | echo "-------------------------" |
| 130 | echo "Installing Brew" |
| 131 | echo "-------------------------" |
| 132 | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
| 133 | fi |
| 134 | install_talib |
| 135 | test_and_fix_python_on_mac |
| 136 | } |
| 137 | |
| 138 | # Install bot Debian_ubuntu |
| 139 | function install_debian() { |
| 140 | sudo apt-get update |
| 141 | sudo apt-get install -y build-essential autoconf libtool pkg-config make wget git |
| 142 | install_talib |
| 143 | } |
| 144 | |
| 145 | # Upgrade the bot |
| 146 | function update() { |
| 147 | git pull |
| 148 | updateenv |
| 149 | } |
| 150 | |
| 151 | # Reset Develop or Stable branch |
| 152 | function reset() { |
| 153 | echo "----------------------------" |
| 154 | echo "Reseting branch and virtual env" |
| 155 | echo "----------------------------" |
| 156 | |
| 157 | if [ "1" == $(git branch -vv |grep -cE "\* develop|\* stable") ] |
| 158 | then |
| 159 | |
| 160 | read -p "Reset git branch? (This will remove all changes you made!) [y/N]? " |
| 161 | if [[ $REPLY =~ ^[Yy]$ ]]; then |
| 162 | |
| 163 | git fetch -a |
| 164 | |
| 165 | if [ "1" == $(git branch -vv | grep -c "* develop") ] |
| 166 | then |
| 167 | echo "- Hard resetting of 'develop' branch." |
| 168 | git reset --hard origin/develop |
| 169 | elif [ "1" == $(git branch -vv | grep -c "* stable") ] |
| 170 | then |
| 171 | echo "- Hard resetting of 'stable' branch." |
| 172 | git reset --hard origin/stable |
| 173 | fi |
| 174 | fi |
| 175 | else |
| 176 | echo "Reset ignored because you are not on 'stable' or 'develop'." |
| 177 | fi |
| 178 | |
| 179 | if [ -d ".env" ]; then |
| 180 | echo "- Deleting your previous virtual env" |
| 181 | rm -rf .env |
| 182 | fi |
| 183 | echo |
| 184 | ${PYTHON} -m venv .env |
| 185 | if [ $? -ne 0 ]; then |
| 186 | echo "Could not create virtual environment. Leaving now" |
| 187 | exit 1 |
| 188 | fi |
| 189 | updateenv |
| 190 | } |
| 191 | |
| 192 | function test_and_fix_python_on_mac() { |
| 193 | |
| 194 | if ! [ -x "$(command -v python3.6)" ] |
| 195 | then |
| 196 | echo "-------------------------" |
| 197 | echo "Fixing Python" |
| 198 | echo "-------------------------" |
| 199 | echo "Python 3.6 is not linked in your system. Fixing it..." |
| 200 | brew link --overwrite python |
| 201 | echo |
| 202 | fi |
| 203 | } |
| 204 | |
| 205 | function config() { |
| 206 | |
| 207 | echo "-------------------------" |
| 208 | echo "Please use 'freqtrade new-config -c config.json' to generate a new configuration file." |
| 209 | echo "-------------------------" |
| 210 | } |
| 211 | |
| 212 | function install() { |
| 213 | echo "-------------------------" |
| 214 | echo "Installing mandatory dependencies" |
| 215 | echo "-------------------------" |
| 216 | |
| 217 | if [ "$(uname -s)" == "Darwin" ] |
| 218 | then |
| 219 | echo "macOS detected. Setup for this system in-progress" |
| 220 | install_macos |
| 221 | elif [ -x "$(command -v apt-get)" ] |
| 222 | then |
| 223 | echo "Debian/Ubuntu detected. Setup for this system in-progress" |
| 224 | install_debian |
| 225 | else |
| 226 | echo "This script does not support your OS." |
| 227 | echo "If you have Python3.6 or Python3.7, pip, virtualenv, ta-lib you can continue." |
| 228 | echo "Wait 10 seconds to continue the next install steps or use ctrl+c to interrupt this shell." |
| 229 | sleep 10 |
| 230 | fi |
| 231 | echo |
| 232 | reset |
| 233 | config |
| 234 | echo "-------------------------" |
| 235 | echo "Run the bot !" |
| 236 | echo "-------------------------" |
| 237 | echo "You can now use the bot by executing 'source .env/bin/activate; freqtrade <subcommand>'." |
| 238 | echo "You can see the list of available bot sub-commands by executing 'source .env/bin/activate; freqtrade --help'." |
| 239 | echo "You verify that freqtrade is installed successfully by running 'source .env/bin/activate; freqtrade --version'." |
| 240 | } |
| 241 | |
| 242 | function plot() { |
| 243 | echo " |
| 244 | ----------------------------------------- |
| 245 | Installing dependencies for Plotting scripts |
| 246 | ----------------------------------------- |
| 247 | " |
| 248 | ${PYTHON} -m pip install plotly --upgrade |
| 249 | } |
| 250 | |
| 251 | function help() { |
| 252 | echo "usage:" |
| 253 | echo " -i,--install Install freqtrade from scratch" |
| 254 | echo " -u,--update Command git pull to update." |
| 255 | echo " -r,--reset Hard reset your develop/stable branch." |
| 256 | echo " -c,--config Easy config generator (Will override your existing file)." |
| 257 | echo " -p,--plot Install dependencies for Plotting scripts." |
| 258 | } |
| 259 | |
| 260 | # Verify if 3.7 or 3.8 is installed |
| 261 | check_installed_python |
| 262 | |
| 263 | case $* in |
| 264 | --install|-i) |
| 265 | install |
| 266 | ;; |
| 267 | --config|-c) |
| 268 | config |
| 269 | ;; |
| 270 | --update|-u) |
| 271 | update |
| 272 | ;; |
| 273 | --reset|-r) |
| 274 | reset |
| 275 | ;; |
| 276 | --plot|-p) |
| 277 | plot |
| 278 | ;; |
| 279 | *) |
| 280 | help |
| 281 | ;; |
| 282 | esac |
| 283 | exit 0 |