From d76ead271f1cc3e2055dd85566ecb20cb5d3d4df Mon Sep 17 00:00:00 2001 From: Gert Wohlgemuth Date: Fri, 11 May 2018 15:13:41 -0700 Subject: [PATCH] Added requested changes --- freqtrade/strategy/resolver.py | 28 +++++++++++++++++++--------- requirements.txt | 3 --- setup.py | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/freqtrade/strategy/resolver.py b/freqtrade/strategy/resolver.py index 928a36a43..6df763a67 100644 --- a/freqtrade/strategy/resolver.py +++ b/freqtrade/strategy/resolver.py @@ -11,11 +11,10 @@ from typing import Optional, Dict, Type from freqtrade import constants from freqtrade.strategy.interface import IStrategy -import validators import tempfile from urllib.parse import urlparse -from urllib.request import urlretrieve import os +import requests from pathlib import Path logger = logging.getLogger(__name__) @@ -82,13 +81,24 @@ class StrategyResolver(object): # Add extra strategy directory on top of search paths abs_paths.insert(0, extra_dir) - if validators.url(strategy_name): - temp = tempfile.mkdtemp("freq", "strategy") - abs_paths.insert(0, temp) - name = os.path.basename(urlparse(strategy_name).path) - urlretrieve(strategy_name, os.path.join(temp, name)) - Path(os.path.join(temp, "__init__.py")).touch() - strategy_name = os.path.splitext(name)[0] + try: + # check if given strategy matches an url + logger.debug("requesting remote strategy from {}".format(strategy_name)) + resp = requests.get(strategy_name, stream=True) + if resp.status_code == 200: + temp = Path(tempfile.mkdtemp("freq", "strategy")) + name = os.path.basename(urlparse(strategy_name).path) + + temp.joinpath(name).write_text(resp.text) + temp.joinpath("__init__.py").touch() + + strategy_name = os.path.splitext(name)[0] + + # register temp path with the bot + abs_paths.insert(0, temp.absolute()) + + except requests.RequestException: + logger.debug("received error trying to fetch strategy remotely, carry on!") for path in abs_paths: strategy = self._search_strategy(path, strategy_name) diff --git a/requirements.txt b/requirements.txt index 887624cb6..4aa22fcd1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,6 +23,3 @@ coinmarketcap==4.2.1 # Required for plotting data #plotly==2.3.0 - -# Required for dynamic strategy loading from urls -validators diff --git a/setup.py b/setup.py index 856a47181..62a75eba9 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,7 @@ setup(name='freqtrade', 'TA-Lib', 'tabulate', 'cachetools', - 'coinmarketcap', + 'coinmarketcap' ], include_package_data=True, zip_safe=False,