Added support to load strategy directly from a given url
This commit is contained in:
parent
1dbdb880e6
commit
9b68986a2d
@ -6,13 +6,17 @@ This module load custom strategies
|
|||||||
import importlib.util
|
import importlib.util
|
||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from typing import Optional, Dict, Type
|
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
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
from urllib.request import urlretrieve
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -78,6 +82,14 @@ 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):
|
||||||
|
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:
|
for path in abs_paths:
|
||||||
strategy = self._search_strategy(path, strategy_name)
|
strategy = self._search_strategy(path, strategy_name)
|
||||||
if strategy:
|
if strategy:
|
||||||
|
@ -26,6 +26,15 @@ def test_load_strategy(result):
|
|||||||
assert 'adx' in resolver.strategy.populate_indicators(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):
|
def test_load_strategy_custom_directory(result):
|
||||||
resolver = StrategyResolver()
|
resolver = StrategyResolver()
|
||||||
extra_dir = os.path.join('some', 'path')
|
extra_dir = os.path.join('some', 'path')
|
||||||
|
@ -23,3 +23,6 @@ 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