Skip to content

Rearrange core package #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/investing-algorithm-framework-admin
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

from investing_algorithm_framework.core.management import execute_from_command_line
from investing_algorithm_framework.management import execute_from_command_line

if __name__ == "__main__":
execute_from_command_line()
4 changes: 2 additions & 2 deletions investing_algorithm_framework/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
Invokes investing_algorithm_framework-admin when the investing_algorithm_framework framework module is run as a script.
Example: python -m investing_algorithm_framework createalgorithm SampleAlgorithm
Example: python -m investing_algorithm_framework create_standard_algo SampleAlgorithm
"""

from investing_algorithm_framework.core.management import execute_from_command_line
from investing_algorithm_framework.management import execute_from_command_line

if __name__ == "__main__":
execute_from_command_line()
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
from enum import Enum

from investing_algorithm_framework.core.exceptions import ImproperlyConfigured, OperationalException
from investing_algorithm_framework.core.configuration.template import Template
from investing_algorithm_framework.core.configuration.config_constants import SETTINGS_MODULE_PATH_ENV_NAME, \
SETTINGS_STRATEGY_REGISTERED_APPS, SETTINGS_DATA_PROVIDER_REGISTERED_APPS, BASE_DIR, SETTINGS_LOGGING_CONFIG
from investing_algorithm_framework.configuration.config_constants import SETTINGS_MODULE_PATH_ENV_NAME, \
SETTINGS_STRATEGY_REGISTERED_APPS, SETTINGS_DATA_PROVIDER_REGISTERED_APPS, SETTINGS_LOGGING_CONFIG


class TimeUnit(Enum):

SECOND = 'SEC',
MINUTE = 'MIN',
HOUR = 'HR',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from investing_algorithm_framework.configuration.setup.default_template_creators import DefaultProjectCreator
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

import investing_algorithm_framework
from investing_algorithm_framework.core.exceptions import ImproperlyConfigured
from investing_algorithm_framework.core.configuration.setup.template_creator import TemplateCreator
from investing_algorithm_framework.configuration.setup.template_creator import TemplateCreator


class DefaultProjectCreator(TemplateCreator):
TEMPLATE_ROOT_DIR = 'templates/algorithm_project_directory'
TEMPLATE_ROOT_DIR = 'templates/projects/algorithm_project_directory'
PROJECT_NAME_PLACEHOLDER = '{{ project_name }}'
PROJECT_TEMPLATE_DIR_NAME = 'algorithm_project_template'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import stat
from abc import ABC, abstractmethod

from investing_algorithm_framework.core.configuration import Template
from investing_algorithm_framework.configuration.setup.template import Template


class TemplateCreator(Template, ABC):
Expand Down

This file was deleted.

12 changes: 6 additions & 6 deletions investing_algorithm_framework/core/context/context.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Type

from investing_algorithm_framework.core.configuration import settings
from investing_algorithm_framework.configuration import settings
from investing_algorithm_framework.core.exceptions import OperationalException
from investing_algorithm_framework.core.utils import Singleton
from investing_algorithm_framework.core.states import BotState
from investing_algorithm_framework.core.state import State


class Context(metaclass=Singleton):
Expand All @@ -13,15 +13,15 @@ class Context(metaclass=Singleton):
"""

# A reference to the current state of the context.
_state: BotState = None
_state: State = None

# Settings reference
settings = settings

def register_initial_state(self, bot_state: Type[BotState]) -> None:
self._state = bot_state(context=self)
def register_initial_state(self, state: Type[State]) -> None:
self._state = state(context=self)

def transition_to(self, bot_state: Type[BotState]) -> None:
def transition_to(self, bot_state: Type[State]) -> None:
"""
Function to change the running BotState at runtime.
"""
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion investing_algorithm_framework/core/executors/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from investing_algorithm_framework.core.utils import StoppableThread
from investing_algorithm_framework.core.events.observer import Observer
from investing_algorithm_framework.core.events.observable import Observable
from investing_algorithm_framework.core.configuration.config_constants import DEFAULT_MAX_WORKERS
from investing_algorithm_framework.configuration.config_constants import DEFAULT_MAX_WORKERS


class Executor(Observable, Observer, ABC):
Expand Down
2 changes: 0 additions & 2 deletions investing_algorithm_framework/core/management/__init__.py

This file was deleted.

73 changes: 0 additions & 73 deletions investing_algorithm_framework/core/management/command_manager.py

This file was deleted.

This file was deleted.

3 changes: 2 additions & 1 deletion investing_algorithm_framework/core/resolvers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from investing_algorithm_framework.core.resolvers.class_collector import ClassCollector
from investing_algorithm_framework.core.resolvers.database_resolver import DatabaseResolver
from investing_algorithm_framework.core.resolvers.class_resolver import ClassResolver


Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from importlib import import_module


class ClassCollector:
class ClassResolver:
"""
Class ClassCollector: This class will load all the classes of a specific type given the package_path.
You can specify a module name if you know where the class is located
Expand Down Expand Up @@ -55,4 +55,3 @@ def _find_classes(self, package_path: str, module_name: str = None) -> None:
@property
def instances(self) -> List[Any]:
return self._class_instances

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
from sqlalchemy.orm.exc import DetachedInstanceError
from sqlalchemy.exc import DatabaseError


from investing_algorithm_framework.core.configuration import settings
from investing_algorithm_framework.core.configuration.config_constants import BASE_DIR, DATABASE_NAME
from investing_algorithm_framework.configuration import settings
from investing_algorithm_framework.configuration.config_constants import BASE_DIR, DATABASE_NAME
from investing_algorithm_framework.core.exceptions import DatabaseOperationalException


Expand Down

This file was deleted.

This file was deleted.

2 changes: 2 additions & 0 deletions investing_algorithm_framework/core/state/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from investing_algorithm_framework.core.state.state import State

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from abc import ABC, abstractmethod
from typing import List

from investing_algorithm_framework.core.context.state_validator import StateValidator
from investing_algorithm_framework.core.validators import StateValidator


class BotState(ABC):
class State(ABC):
"""
Represents a state of the Bot, these states are use by the BotContext. Each implemented state represents a work
Represents a state of the Bot, these state are use by the BotContext. Each implemented state represents a work
mode for the investing_algorithm_framework.
"""

Expand Down
2 changes: 0 additions & 2 deletions investing_algorithm_framework/core/states/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion investing_algorithm_framework/core/strategies/__init__.py

This file was deleted.

1 change: 1 addition & 0 deletions investing_algorithm_framework/core/validators/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from investing_algorithm_framework.core.validators.state_validators import StateValidator
3 changes: 3 additions & 0 deletions investing_algorithm_framework/management/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from investing_algorithm_framework.management.command import BaseCommand
from investing_algorithm_framework.management.command_manager import execute_from_command_line

Original file line number Diff line number Diff line change
Expand Up @@ -77,37 +77,10 @@ def execute(self, *args, **options) -> Any:
"""
Try to execute this command.
"""
response = self.handle(*args, **options)

try:
return self.handle_command_success(self.handle(*args, **options))
except CommandError as e:
return self.handle_command_error("Command error: " + e.__str__())
except ImproperlyConfigured as e:
return self.handle_command_error("Configuration error: " + e.__str__())

def handle_command_error(self, error_message: str = None) -> str:
"""
Handling of errors as output to the user
"""

if error_message is None:
return self.format_error_message("Command ended with error")

return self.format_error_message(error_message)

def handle_command_success(self, message: str = None) -> str:
"""
Handling of successful command execution as output to the user
"""

if message is None:

if self.success_message is not None:
return self.format_success_message(self.success_message)
else:
return self.format_success_message("Command finished")
else:
return self.format_success_message(message)
if response is None and self.success_message is not None:
return self.success_message

@abstractmethod
def handle(self, *args, **options) -> Any:
Expand All @@ -129,21 +102,3 @@ def run_from_argv(self, argv) -> Any:
args = cmd_options.pop('args', ())

return self.execute(*args, **cmd_options)

@staticmethod
def format_success_message(message: str) -> str:
"""
Utility function to format a success message
"""

message = Fore.GREEN + message + '\n'
return message

@staticmethod
def format_error_message(message: str) -> str:
"""
Utility function to format an error message
"""

message = Fore.RED + message + '\n'
return message
Loading