This commit is contained in:
Gert Wohlgemuth 2018-05-13 16:49:13 +00:00 committed by GitHub
commit abd94b4521
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 3 deletions

View File

@ -6,13 +6,16 @@ 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 tempfile
from urllib.parse import urlparse
import os
import requests
from pathlib import Path
logger = logging.getLogger(__name__)
@ -78,6 +81,25 @@ class StrategyResolver(object):
# Add extra strategy directory on top of search paths
abs_paths.insert(0, extra_dir)
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)
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

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