Merge branch 'LoadStrategyByUrl' into aws
# Conflicts: # setup.py
This commit is contained in:
commit
b680429ea1
@ -6,13 +6,16 @@ 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 tempfile
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
import os
|
||||||
|
import requests
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -78,6 +81,25 @@ 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)
|
||||||
|
|
||||||
|
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:
|
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')
|
||||||
|
1
setup.py
1
setup.py
@ -8,6 +8,7 @@ if version_info.major == 3 and version_info.minor < 6 or \
|
|||||||
|
|
||||||
from freqtrade import __version__
|
from freqtrade import __version__
|
||||||
|
|
||||||
|
|
||||||
setup(name='freqtrade',
|
setup(name='freqtrade',
|
||||||
version=__version__,
|
version=__version__,
|
||||||
description='Simple High Frequency Trading Bot for crypto currencies',
|
description='Simple High Frequency Trading Bot for crypto currencies',
|
||||||
|
Loading…
Reference in New Issue
Block a user