Added requested changes

This commit is contained in:
Gert Wohlgemuth 2018-05-11 15:13:41 -07:00
parent 9b68986a2d
commit d76ead271f
3 changed files with 20 additions and 13 deletions

View File

@ -11,11 +11,10 @@ from typing import Optional, Dict, Type
from freqtrade import constants from freqtrade import constants
from freqtrade.strategy.interface import IStrategy from freqtrade.strategy.interface import IStrategy
import validators
import tempfile import tempfile
from urllib.parse import urlparse from urllib.parse import urlparse
from urllib.request import urlretrieve
import os import os
import requests
from pathlib import Path from pathlib import Path
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -82,14 +81,25 @@ class StrategyResolver(object):
# Add extra strategy directory on top of search paths # Add extra strategy directory on top of search paths
abs_paths.insert(0, extra_dir) abs_paths.insert(0, extra_dir)
if validators.url(strategy_name): try:
temp = tempfile.mkdtemp("freq", "strategy") # check if given strategy matches an url
abs_paths.insert(0, temp) 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) name = os.path.basename(urlparse(strategy_name).path)
urlretrieve(strategy_name, os.path.join(temp, name))
Path(os.path.join(temp, "__init__.py")).touch() temp.joinpath(name).write_text(resp.text)
temp.joinpath("__init__.py").touch()
strategy_name = os.path.splitext(name)[0] 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: for path in abs_paths:
strategy = self._search_strategy(path, strategy_name) strategy = self._search_strategy(path, strategy_name)
if strategy: if strategy:

View File

@ -23,6 +23,3 @@ coinmarketcap==4.2.1
# Required for plotting data # Required for plotting data
#plotly==2.3.0 #plotly==2.3.0
# Required for dynamic strategy loading from urls
validators

View File

@ -35,7 +35,7 @@ setup(name='freqtrade',
'TA-Lib', 'TA-Lib',
'tabulate', 'tabulate',
'cachetools', 'cachetools',
'coinmarketcap', 'coinmarketcap'
], ],
include_package_data=True, include_package_data=True,
zip_safe=False, zip_safe=False,