mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 18:23:55 +00:00
33 lines
867 B
Python
33 lines
867 B
Python
import logging
|
|
from copy import deepcopy
|
|
|
|
from freqtrade.strategy.interface import IStrategy
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def import_strategy(strategy: IStrategy) -> IStrategy:
|
|
"""
|
|
Imports given Strategy instance to global scope
|
|
of freqtrade.strategy and returns an instance of it
|
|
"""
|
|
# Copy all attributes from base class and class
|
|
attr = deepcopy({**strategy.__class__.__dict__, **strategy.__dict__})
|
|
# Adjust module name
|
|
attr['__module__'] = 'freqtrade.strategy'
|
|
|
|
name = strategy.__class__.__name__
|
|
clazz = type(name, (IStrategy,), attr)
|
|
|
|
logger.debug(
|
|
'Imported strategy %s.%s as %s.%s',
|
|
strategy.__module__, strategy.__class__.__name__,
|
|
clazz.__module__, strategy.__class__.__name__,
|
|
)
|
|
|
|
# Modify global scope to declare class
|
|
globals()[name] = clazz
|
|
|
|
return clazz()
|