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.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)

View File

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

View File

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