diff --git a/freqtrade/strategy/resolver.py b/freqtrade/strategy/resolver.py index 8f4972919..928a36a43 100644 --- a/freqtrade/strategy/resolver.py +++ b/freqtrade/strategy/resolver.py @@ -6,13 +6,17 @@ This module load custom strategies import importlib.util import inspect import logging -import os from collections import OrderedDict 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 +from pathlib import Path logger = logging.getLogger(__name__) @@ -78,6 +82,14 @@ 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] + for path in abs_paths: strategy = self._search_strategy(path, strategy_name) if strategy: diff --git a/freqtrade/tests/strategy/test_strategy.py b/freqtrade/tests/strategy/test_strategy.py index 244910790..c46d27a49 100644 --- a/freqtrade/tests/strategy/test_strategy.py +++ b/freqtrade/tests/strategy/test_strategy.py @@ -26,6 +26,15 @@ def test_load_strategy(result): assert 'adx' in resolver.strategy.populate_indicators(result) +def test_load_strategy_from_url(result): + resolver = StrategyResolver() + resolver._load_strategy('https://raw.githubusercontent.com/berlinguyinca' + '/freqtrade-trading-strategies' + '/master/user_data/strategies/Simple.py') + assert hasattr(resolver.strategy, 'populate_indicators') + assert 'adx' in resolver.strategy.populate_indicators(result) + + def test_load_strategy_custom_directory(result): resolver = StrategyResolver() extra_dir = os.path.join('some', 'path') diff --git a/requirements.txt b/requirements.txt index 4aa22fcd1..887624cb6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,3 +23,6 @@ coinmarketcap==4.2.1 # Required for plotting data #plotly==2.3.0 + +# Required for dynamic strategy loading from urls +validators