Skip to content
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
4 changes: 4 additions & 0 deletions investing_algorithm_framework/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from investing_algorithm_framework.utils.version import get_version

VERSION = (1, 0, 0, 'alpha', 0)

9 changes: 9 additions & 0 deletions investing_algorithm_framework/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +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 createbot SampleBot
"""

from investing_algorithm_framework.core.management import execute_from_command_line

if __name__ == "__main__":
execute_from_command_line()
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env python

from investing_algorithm_framework.core.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 @@ -4,9 +4,9 @@
from importlib import import_module
from enum import Enum

from investing_bot_framework.core.exceptions import ImproperlyConfigured, OperationalException
from investing_bot_framework.core.configuration.template import Template
from investing_bot_framework.core.configuration.config_constants import SETTINGS_MODULE_PATH_ENV_NAME, \
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


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Naming conventions
FRAMEWORK_NAME = 'investing investing_bot_framework framework'
FRAMEWORK_CORE_MODULE_NAME = 'investing_bot_framework.core'
FRAMEWORK_NAME = 'investing investing_algorithm_framework framework'
FRAMEWORK_CORE_MODULE_NAME = 'investing_algorithm_framework.core'

# Setting related constants
SETTINGS_BOT_PROJECT_NAME = 'BOT_PROJECT_NAME'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from investing_algorithm_framework.core.configuration.setup.default_template_creators import DefaultBotProjectCreator
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
from shutil import copyfile, copymode

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


class DefaultBotProjectCreator(TemplateCreator):
Expand All @@ -20,15 +20,15 @@ def configure(self) -> None:
def create(self) -> None:

# Find the default template directory
template_dir = os.path.join(investing_bot_framework.__path__[0], self.TEMPLATE_ROOT_DIR)
template_dir = os.path.join(investing_algorithm_framework.__path__[0], self.TEMPLATE_ROOT_DIR)

for root, dirs, files in os.walk(template_dir):

# Get the last part of the path
# This is used as the basis for the copying
path_rest = root[len(template_dir) + 1:]

# Replace template investing_bot_framework directory with given investing_bot_framework name
# Replace template investing_algorithm_framework directory with given investing_algorithm_framework name
path_rest = path_rest.replace(self.BOT_PROJECT_TEMPLATE_DIR_NAME, self._bot_name)

# Create the directories if they don't exist
Expand Down Expand Up @@ -83,7 +83,7 @@ def create(self) -> None:

file_data = file.read()

# Replace the placeholder with the investing_bot_framework name
# Replace the placeholder with the investing_algorithm_framework name
file_data = file_data.replace(self.BOT_PROJECT_NAME_PLACEHOLDER, self._bot_name)

# Write the file out again
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_bot_framework.core.configuration import Template
from investing_algorithm_framework.core.configuration import Template


class TemplateCreator(Template, ABC):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from abc import abstractmethod

from investing_bot_framework.core.exceptions import ImproperlyConfigured
from investing_algorithm_framework.core.exceptions import ImproperlyConfigured


class Template:
"""
A template class is responsible for creating a templates for the investing_bot_framework.
A template class is responsible for creating a templates for the investing_algorithm_framework.
"""

def __init__(self, bot_project_directory: str, bot_name: str) -> None:
"""
investing_bot_framework project directory is the root directory of the given investing_bot_framework. The bot_name will be the same as the root project
investing_algorithm_framework project directory is the root directory of the given investing_algorithm_framework. The bot_name will be the same as the root project
directory. For simplicity it is explicitly passed as a parameter
"""

Expand Down
1 change: 1 addition & 0 deletions investing_algorithm_framework/core/context/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from investing_algorithm_framework.core.context.bot_context import BotContext
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Type

from investing_bot_framework.core.configuration import settings
from investing_bot_framework.core.exceptions import OperationalException
from investing_bot_framework.core.utils import Singleton
from investing_bot_framework.core.states import BotState
from investing_algorithm_framework.core.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


class BotContext(metaclass=Singleton):
Expand Down Expand Up @@ -46,7 +46,7 @@ def _check_state(self, raise_exception: bool = False) -> bool:

def start(self) -> None:
"""
Run the current state of the investing_bot_framework
Run the current state of the investing_algorithm_framework
"""

self._check_state(raise_exception=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from investing_algorithm_framework.core.data_providers.data_provider import DataProvider
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Dict, Any
from abc import abstractmethod

from investing_bot_framework.core.workers import ScheduledWorker
from investing_algorithm_framework.core.workers import ScheduledWorker

logger = logging.getLogger(__name__)

Expand Down
2 changes: 2 additions & 0 deletions investing_algorithm_framework/core/events/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from investing_algorithm_framework.core.events.observable import Observable
from investing_algorithm_framework.core.events.observer import Observer
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List
from abc import ABC, abstractmethod
from investing_bot_framework.core.events.observer import Observer
from investing_algorithm_framework.core.events.observer import Observer


class Observable(ABC):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
class ImproperlyConfigured(Exception):
"""
Class ImproperlyConfigured: Exception class indicating a problem with the configuration of the investing_bot_framework
Class ImproperlyConfigured: Exception class indicating a problem with the configuration of the investing_algorithm_framework
"""
def __init__(self, message) -> None:
super(ImproperlyConfigured, self).__init__(message)


class OperationalException(Exception):
"""
Class OperationalException: Exception class indicating a problem occurred during running of the investing_bot_framework
Class OperationalException: Exception class indicating a problem occurred during running of the investing_algorithm_framework
"""
def __init__(self, message) -> None:
super(OperationalException, self).__init__(message)
Expand Down
2 changes: 2 additions & 0 deletions investing_algorithm_framework/core/executors/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from investing_algorithm_framework.core.executors.executor import Executor
from investing_algorithm_framework.core.executors.execution_scheduler import ExecutionScheduler
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from collections import namedtuple
from typing import Dict, List

from investing_bot_framework.core.utils import TimeUnit
from investing_bot_framework.core.exceptions import OperationalException
from investing_algorithm_framework.core.utils import TimeUnit
from investing_algorithm_framework.core.exceptions import OperationalException

ExecutionTask = namedtuple('ExecutionTask', 'time_unit interval last_run')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from wrapt import synchronized
from abc import abstractmethod, ABC

from investing_bot_framework.core.workers import Worker
from investing_bot_framework.core.exceptions import OperationalException
from investing_bot_framework.core.utils import StoppableThread
from investing_bot_framework.core.events.observer import Observer
from investing_bot_framework.core.events.observable import Observable
from investing_bot_framework.core.configuration.config_constants import DEFAULT_MAX_WORKERS
from investing_algorithm_framework.core.workers import Worker
from investing_algorithm_framework.core.exceptions import OperationalException
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


class Executor(Observable, Observer, ABC):
Expand Down
3 changes: 3 additions & 0 deletions investing_algorithm_framework/core/extensions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from investing_algorithm_framework.core.resolvers import DatabaseResolver

db = DatabaseResolver()
2 changes: 2 additions & 0 deletions investing_algorithm_framework/core/management/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from investing_algorithm_framework.core.management.command import BaseCommand
from investing_algorithm_framework.core.management.command_manager import execute_from_command_line
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from abc import abstractmethod, ABC
from colorama import Fore

from investing_bot_framework.core.exceptions import ImproperlyConfigured
from investing_algorithm_framework.core.exceptions import ImproperlyConfigured


class CommandError(Exception):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
import sys

from investing_bot_framework.core.management import BaseCommand
from investing_bot_framework.core.resolvers import ClassCollector
from investing_bot_framework.core.management.utils import get_commands
from investing_bot_framework.core.management.commands.help import HelpCommand
from investing_algorithm_framework.core.management import BaseCommand
from investing_algorithm_framework.core.resolvers import ClassCollector
from investing_algorithm_framework.core.management.utils import get_commands
from investing_algorithm_framework.core.management.commands.help import HelpCommand


class ManagementUtility:
Expand All @@ -17,7 +17,7 @@ def __init__(self, argv=None) -> None:
self.program_name = os.path.basename(self.argv[0])

if self.program_name == '__main__.py':
self.program_name = 'python -m investing-investing_bot_framework'
self.program_name = 'python -m investing-investing_algorithm_framework'
self.settings_exception = None

def execute(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
import re
from importlib import import_module

from investing_bot_framework.core.exceptions import ImproperlyConfigured
from investing_bot_framework.core.management.command import BaseCommand, CommandError
from investing_bot_framework.core.configuration.setup import DefaultBotProjectCreator
from investing_algorithm_framework.core.exceptions import ImproperlyConfigured
from investing_algorithm_framework.core.management.command import BaseCommand, CommandError
from investing_algorithm_framework.core.configuration.setup import DefaultBotProjectCreator


class CreateBotCommand(BaseCommand):
help = (
"Creates a project directory structure for the given investing_bot_framework name in the current directory or optionally "
"Creates a project directory structure for the given investing_algorithm_framework name in the current directory or optionally "
"in the given directory."
)

missing_args_message = "You must provide a investing_bot_framework name."
missing_args_message = "You must provide a investing_algorithm_framework name."
success_message = "Bot created and initialized."

def add_arguments(self, parser):
parser.add_argument('name', help='Name of the investing_bot_framework.')
parser.add_argument('name', help='Name of the investing_algorithm_framework.')
parser.add_argument('directory', nargs='?', help='Optional destination directory')
parser.add_argument(
'--template_creator',
Expand All @@ -33,13 +33,13 @@ def handle(self, **options) -> str:

self.validate_name(bot_name)

# initialize the investing_bot_framework project directory
# initialize the investing_algorithm_framework project directory
if directory is None:
directory = os.path.join(os.getcwd(), bot_name)

if os.path.isdir(directory):
raise ImproperlyConfigured(
"Directory {} already exists. Please make sure that the investing_bot_framework project name does not correspond to "
"Directory {} already exists. Please make sure that the investing_algorithm_framework project name does not correspond to "
"an existing directory"
)

Expand All @@ -51,7 +51,7 @@ def handle(self, **options) -> str:
if not os.path.exists(directory):
raise CommandError("Destination directory {} does not exist, please create it first.".format(directory))

# Use default investing_bot_framework creator
# Use default investing_algorithm_framework creator
if not template_creator:
bot_template_creator = DefaultBotProjectCreator(directory, bot_name)

Expand All @@ -62,11 +62,11 @@ def handle(self, **options) -> str:
@staticmethod
def validate_name(name: str) -> None:
"""
Helper function to validate the name of a given investing_bot_framework
Helper function to validate the name of a given investing_algorithm_framework
"""

if name is None:
raise CommandError("you must provide a investing_bot_framework name")
raise CommandError("you must provide a investing_algorithm_framework name")

if not re.match("^[a-zA-Z]+\w*$", name):
raise CommandError("{} is not allowed, value must begin with a letter and "
Expand All @@ -80,6 +80,6 @@ def validate_name(name: str) -> None:
else:
raise CommandError(
"'{}' conflicts with the name of an existing Python "
"module and cannot be used as a investing_bot_framework name. Please try "
"module and cannot be used as a investing_algorithm_framework name. Please try "
"another name.".format(name)
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Any
from collections import defaultdict

from investing_bot_framework.core.management import BaseCommand
from investing_bot_framework.core.management.utils import get_commands
from investing_bot_framework.core.configuration.config_constants import FRAMEWORK_CORE_MODULE_NAME, FRAMEWORK_NAME
from investing_algorithm_framework.core.management import BaseCommand
from investing_algorithm_framework.core.management.utils import get_commands
from investing_algorithm_framework.core.configuration.config_constants import FRAMEWORK_CORE_MODULE_NAME, FRAMEWORK_NAME


class HelpCommand(BaseCommand):
Expand All @@ -17,7 +17,7 @@ def add_arguments(self, parser) -> None:
def handle(self) -> Any:
usage = [
"",
"This is the command line management for the investing investing_bot_framework framework. \n"
"This is the command line management for the investing investing_algorithm_framework framework. \n"
"Type help <sub_command>' for help on a specific sub command.",
"",
"Available sub commands:",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from typing import Any

from investing_bot_framework.core.management.command import BaseCommand, CommandError
from investing_bot_framework.core.context import BotContext
from investing_bot_framework.core.configuration.config_constants import SETTINGS_BOT_CONTEXT_CONFIGURATION
from investing_bot_framework.core.configuration import settings
from investing_algorithm_framework.core.management.command import BaseCommand, CommandError
from investing_algorithm_framework.core.context import BotContext
from investing_algorithm_framework.core.configuration.config_constants import SETTINGS_BOT_CONTEXT_CONFIGURATION
from investing_algorithm_framework.core.configuration import settings


class RunBotCommand(BaseCommand):
help_message = (
"Runs a investing_bot_framework, by default it will run until stopped, if cycles is specified it will run "
"Runs a investing_algorithm_framework, by default it will run until stopped, if cycles is specified it will run "
"the according to the amount of cycles"
)

Expand All @@ -19,7 +19,7 @@ class RunBotCommand(BaseCommand):
def add_arguments(self, parser) -> None:
parser.add_argument(
'--cycles',
help='Optional number for the amount of cycles the investing_bot_framework runs'
help='Optional number for the amount of cycles the investing_algorithm_framework runs'
)

def handle(self, *args, **options) -> Any:
Expand All @@ -32,7 +32,7 @@ def handle(self, *args, **options) -> Any:

cycles = options.get('name', None)

# Create an investing_bot_framework context of the investing_bot_framework and run it
# Create an investing_algorithm_framework context of the investing_algorithm_framework and run it
context = BotContext()
context.start()

Expand Down
Loading