Skip to content

Commit 3bddba0

Browse files
author
investing-algorithms
authored
Merge pull request #32 from investing-algorithms/feature_core
Rearrange core package
2 parents 81a057d + 62529cc commit 3bddba0

File tree

64 files changed

+210
-241
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+210
-241
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
from investing_algorithm_framework.core.management import execute_from_command_line
3+
from investing_algorithm_framework.management import execute_from_command_line
44

55
if __name__ == "__main__":
66
execute_from_command_line()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""
22
Invokes investing_algorithm_framework-admin when the investing_algorithm_framework framework module is run as a script.
3-
Example: python -m investing_algorithm_framework createalgorithm SampleAlgorithm
3+
Example: python -m investing_algorithm_framework create_standard_algo SampleAlgorithm
44
"""
55

6-
from investing_algorithm_framework.core.management import execute_from_command_line
6+
from investing_algorithm_framework.management import execute_from_command_line
77

88
if __name__ == "__main__":
99
execute_from_command_line()

investing_algorithm_framework/core/configuration/__init__.py renamed to investing_algorithm_framework/configuration/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
from enum import Enum
66

77
from investing_algorithm_framework.core.exceptions import ImproperlyConfigured, OperationalException
8-
from investing_algorithm_framework.core.configuration.template import Template
9-
from investing_algorithm_framework.core.configuration.config_constants import SETTINGS_MODULE_PATH_ENV_NAME, \
10-
SETTINGS_STRATEGY_REGISTERED_APPS, SETTINGS_DATA_PROVIDER_REGISTERED_APPS, BASE_DIR, SETTINGS_LOGGING_CONFIG
8+
from investing_algorithm_framework.configuration.config_constants import SETTINGS_MODULE_PATH_ENV_NAME, \
9+
SETTINGS_STRATEGY_REGISTERED_APPS, SETTINGS_DATA_PROVIDER_REGISTERED_APPS, SETTINGS_LOGGING_CONFIG
1110

1211

1312
class TimeUnit(Enum):
14-
1513
SECOND = 'SEC',
1614
MINUTE = 'MIN',
1715
HOUR = 'HR',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from investing_algorithm_framework.configuration.setup.default_template_creators import DefaultProjectCreator

investing_algorithm_framework/core/configuration/setup/default_template_creators.py renamed to investing_algorithm_framework/configuration/setup/default_template_creators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
import investing_algorithm_framework
55
from investing_algorithm_framework.core.exceptions import ImproperlyConfigured
6-
from investing_algorithm_framework.core.configuration.setup.template_creator import TemplateCreator
6+
from investing_algorithm_framework.configuration.setup.template_creator import TemplateCreator
77

88

99
class DefaultProjectCreator(TemplateCreator):
10-
TEMPLATE_ROOT_DIR = 'templates/algorithm_project_directory'
10+
TEMPLATE_ROOT_DIR = 'templates/projects/algorithm_project_directory'
1111
PROJECT_NAME_PLACEHOLDER = '{{ project_name }}'
1212
PROJECT_TEMPLATE_DIR_NAME = 'algorithm_project_template'
1313

investing_algorithm_framework/core/configuration/setup/template_creator.py renamed to investing_algorithm_framework/configuration/setup/template_creator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import stat
33
from abc import ABC, abstractmethod
44

5-
from investing_algorithm_framework.core.configuration import Template
5+
from investing_algorithm_framework.configuration.setup.template import Template
66

77

88
class TemplateCreator(Template, ABC):

investing_algorithm_framework/core/configuration/setup/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

investing_algorithm_framework/core/context/context.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from typing import Type
22

3-
from investing_algorithm_framework.core.configuration import settings
3+
from investing_algorithm_framework.configuration import settings
44
from investing_algorithm_framework.core.exceptions import OperationalException
55
from investing_algorithm_framework.core.utils import Singleton
6-
from investing_algorithm_framework.core.states import BotState
6+
from investing_algorithm_framework.core.state import State
77

88

99
class Context(metaclass=Singleton):
@@ -13,15 +13,15 @@ class Context(metaclass=Singleton):
1313
"""
1414

1515
# A reference to the current state of the context.
16-
_state: BotState = None
16+
_state: State = None
1717

1818
# Settings reference
1919
settings = settings
2020

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

24-
def transition_to(self, bot_state: Type[BotState]) -> None:
24+
def transition_to(self, bot_state: Type[State]) -> None:
2525
"""
2626
Function to change the running BotState at runtime.
2727
"""

investing_algorithm_framework/core/data_providers/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

investing_algorithm_framework/core/executors/executor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from investing_algorithm_framework.core.utils import StoppableThread
99
from investing_algorithm_framework.core.events.observer import Observer
1010
from investing_algorithm_framework.core.events.observable import Observable
11-
from investing_algorithm_framework.core.configuration.config_constants import DEFAULT_MAX_WORKERS
11+
from investing_algorithm_framework.configuration.config_constants import DEFAULT_MAX_WORKERS
1212

1313

1414
class Executor(Observable, Observer, ABC):

investing_algorithm_framework/core/management/__init__.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

investing_algorithm_framework/core/management/command_manager.py

Lines changed: 0 additions & 73 deletions
This file was deleted.

investing_algorithm_framework/core/order_executors/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
from investing_algorithm_framework.core.resolvers.class_collector import ClassCollector
21
from investing_algorithm_framework.core.resolvers.database_resolver import DatabaseResolver
2+
from investing_algorithm_framework.core.resolvers.class_resolver import ClassResolver
3+
34

investing_algorithm_framework/core/resolvers/class_collector.py renamed to investing_algorithm_framework/core/resolvers/class_resolver.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from importlib import import_module
55

66

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

investing_algorithm_framework/core/resolvers/database_resolver.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
from sqlalchemy.orm.exc import DetachedInstanceError
99
from sqlalchemy.exc import DatabaseError
1010

11-
12-
from investing_algorithm_framework.core.configuration import settings
13-
from investing_algorithm_framework.core.configuration.config_constants import BASE_DIR, DATABASE_NAME
11+
from investing_algorithm_framework.configuration import settings
12+
from investing_algorithm_framework.configuration.config_constants import BASE_DIR, DATABASE_NAME
1413
from investing_algorithm_framework.core.exceptions import DatabaseOperationalException
1514

1615

investing_algorithm_framework/core/resolvers/module_loaders/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

investing_algorithm_framework/core/resolvers/module_loaders/data_providers_loader.py

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from investing_algorithm_framework.core.state.state import State
2+

investing_algorithm_framework/core/states/bot_state.py renamed to investing_algorithm_framework/core/state/state.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from abc import ABC, abstractmethod
22
from typing import List
33

4-
from investing_algorithm_framework.core.context.state_validator import StateValidator
4+
from investing_algorithm_framework.core.validators import StateValidator
55

66

7-
class BotState(ABC):
7+
class State(ABC):
88
"""
9-
Represents a state of the Bot, these states are use by the BotContext. Each implemented state represents a work
9+
Represents a state of the Bot, these state are use by the BotContext. Each implemented state represents a work
1010
mode for the investing_algorithm_framework.
1111
"""
1212

investing_algorithm_framework/core/states/__init__.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

investing_algorithm_framework/core/strategies/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from investing_algorithm_framework.core.validators.state_validators import StateValidator
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from investing_algorithm_framework.management.command import BaseCommand
2+
from investing_algorithm_framework.management.command_manager import execute_from_command_line
3+

investing_algorithm_framework/core/management/command.py renamed to investing_algorithm_framework/management/command.py

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -77,37 +77,10 @@ def execute(self, *args, **options) -> Any:
7777
"""
7878
Try to execute this command.
7979
"""
80+
response = self.handle(*args, **options)
8081

81-
try:
82-
return self.handle_command_success(self.handle(*args, **options))
83-
except CommandError as e:
84-
return self.handle_command_error("Command error: " + e.__str__())
85-
except ImproperlyConfigured as e:
86-
return self.handle_command_error("Configuration error: " + e.__str__())
87-
88-
def handle_command_error(self, error_message: str = None) -> str:
89-
"""
90-
Handling of errors as output to the user
91-
"""
92-
93-
if error_message is None:
94-
return self.format_error_message("Command ended with error")
95-
96-
return self.format_error_message(error_message)
97-
98-
def handle_command_success(self, message: str = None) -> str:
99-
"""
100-
Handling of successful command execution as output to the user
101-
"""
102-
103-
if message is None:
104-
105-
if self.success_message is not None:
106-
return self.format_success_message(self.success_message)
107-
else:
108-
return self.format_success_message("Command finished")
109-
else:
110-
return self.format_success_message(message)
82+
if response is None and self.success_message is not None:
83+
return self.success_message
11184

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

131104
return self.execute(*args, **cmd_options)
132-
133-
@staticmethod
134-
def format_success_message(message: str) -> str:
135-
"""
136-
Utility function to format a success message
137-
"""
138-
139-
message = Fore.GREEN + message + '\n'
140-
return message
141-
142-
@staticmethod
143-
def format_error_message(message: str) -> str:
144-
"""
145-
Utility function to format an error message
146-
"""
147-
148-
message = Fore.RED + message + '\n'
149-
return message

0 commit comments

Comments
 (0)