Added support to load strategy directly from a given url

This commit is contained in:
Gert Wohlgemuth 2018-05-09 23:15:24 -07:00
parent 1dbdb880e6
commit 9b68986a2d
3 changed files with 26 additions and 2 deletions

View File

@ -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:

View File

@ -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')

View File

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