Added requested changes
This commit is contained in:
parent
9b68986a2d
commit
d76ead271f
@ -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,13 +81,24 @@ 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))
|
||||||
name = os.path.basename(urlparse(strategy_name).path)
|
resp = requests.get(strategy_name, stream=True)
|
||||||
urlretrieve(strategy_name, os.path.join(temp, name))
|
if resp.status_code == 200:
|
||||||
Path(os.path.join(temp, "__init__.py")).touch()
|
temp = Path(tempfile.mkdtemp("freq", "strategy"))
|
||||||
strategy_name = os.path.splitext(name)[0]
|
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:
|
for path in abs_paths:
|
||||||
strategy = self._search_strategy(path, strategy_name)
|
strategy = self._search_strategy(path, strategy_name)
|
||||||
|
@ -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
|
|
||||||
|
Loading…
Reference in New Issue
Block a user