integrated BASE64 encoded strategy loading

This commit is contained in:
Gert Wohlgemuth
2018-07-05 14:30:24 -07:00
parent 2bb63ba33d
commit 8bbee4038b
2 changed files with 29 additions and 2 deletions

View File

@@ -6,14 +6,16 @@ This module load custom strategies
import importlib.util
import inspect
import logging
import os
from base64 import urlsafe_b64decode
from collections import OrderedDict
from typing import Optional, Dict, Type
from freqtrade import constants
from freqtrade.strategy import import_strategy
from freqtrade.strategy.interface import IStrategy
import tempfile
import os
from pathlib import Path
logger = logging.getLogger(__name__)
@@ -80,6 +82,22 @@ class StrategyResolver(object):
# Add extra strategy directory on top of search paths
abs_paths.insert(0, extra_dir)
if ":" in strategy_name and "http" not in strategy_name:
print("loading none http based strategy: {}".format(strategy_name))
strat = strategy_name.split(":")
if len(strat) == 2:
temp = Path(tempfile.mkdtemp("freq", "strategy"))
name = strat[0] + ".py"
temp.joinpath(name).write_text(urlsafe_b64decode(strat[1]).decode('utf-8'))
temp.joinpath("__init__.py").touch()
strategy_name = os.path.splitext(name)[0]
# register temp path with the bot
abs_paths.insert(0, temp.absolute())
for path in abs_paths:
try:
strategy = self._search_strategy(path, strategy_name)