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