Skip to content

Commit 166b91e

Browse files
committed
Update commands
1 parent a32d946 commit 166b91e

File tree

4 files changed

+59
-68
lines changed

4 files changed

+59
-68
lines changed

investing_algorithm_framework/core/management/commands/createbot.py renamed to investing_algorithm_framework/core/management/commands/create_algorithm.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,43 @@
44

55
from investing_algorithm_framework.core.exceptions import ImproperlyConfigured
66
from investing_algorithm_framework.core.management.command import BaseCommand, CommandError
7-
from investing_algorithm_framework.core.configuration.setup import DefaultBotProjectCreator
7+
from investing_algorithm_framework.core.configuration.setup.default_template_creators import DefaultProjectCreator
88

99

10-
class CreateBotCommand(BaseCommand):
10+
class CreateAlgorithmCommand(BaseCommand):
1111
help = (
12-
"Creates a project directory structure for the given investing_algorithm_framework name in the current directory or optionally "
13-
"in the given directory."
12+
"Creates a project directory structure for the given investing_algorithm_framework instance in the current "
13+
"directory or optionally in the given directory."
1414
)
1515

16-
missing_args_message = "You must provide a investing_algorithm_framework name."
17-
success_message = "Bot created and initialized."
16+
missing_args_message = "You must provide a project name."
17+
success_message = "Algorithm created and initialized."
1818

1919
def add_arguments(self, parser):
20-
parser.add_argument('name', help='Name of the investing_algorithm_framework.')
20+
parser.add_argument('name', help='Name of the algorithm/project.')
2121
parser.add_argument('directory', nargs='?', help='Optional destination directory')
2222
parser.add_argument(
2323
'--template_creator',
2424
help='Optional template creator plugin, provided by third party libraries'
2525
)
2626

27-
def handle(self, **options) -> str:
27+
def handle(self, **options) -> None:
2828

2929
# Get all the default attributes
30-
bot_name = options.get('name', None)
30+
project_name = options.get('name', None)
3131
directory = options.get('directory', None)
3232
template_creator = options.get('template_creator', None)
3333

34-
self.validate_name(bot_name)
34+
self.validate_name(project_name)
3535

3636
# initialize the investing_algorithm_framework project directory
3737
if directory is None:
38-
directory = os.path.join(os.getcwd(), bot_name)
38+
directory = os.path.join(os.getcwd(), project_name)
3939

4040
if os.path.isdir(directory):
4141
raise ImproperlyConfigured(
42-
"Directory {} already exists. Please make sure that the investing_algorithm_framework project name does not correspond to "
43-
"an existing directory"
42+
"Directory {} already exists. Please make sure that the project "
43+
"name does not correspond to an existing directory".format(str(directory))
4444
)
4545

4646
os.mkdir(directory)
@@ -49,24 +49,26 @@ def handle(self, **options) -> str:
4949
directory = os.path.abspath(os.path.expanduser(directory))
5050

5151
if not os.path.exists(directory):
52-
raise CommandError("Destination directory {} does not exist, please create it first.".format(directory))
52+
raise CommandError(
53+
"Destination directory {} does not exist, please create it first.".format(str(directory))
54+
)
5355

5456
# Use default investing_algorithm_framework creator
5557
if not template_creator:
56-
bot_template_creator = DefaultBotProjectCreator(directory, bot_name)
58+
template_creator = DefaultProjectCreator(directory, project_name)
5759

5860
# Creates templates
59-
bot_template_creator.configure()
60-
bot_template_creator.create()
61+
template_creator.configure()
62+
template_creator.create()
6163

6264
@staticmethod
6365
def validate_name(name: str) -> None:
6466
"""
65-
Helper function to validate the name of a given investing_algorithm_framework
67+
Helper function to validate the name of a given project
6668
"""
6769

6870
if name is None:
69-
raise CommandError("you must provide a investing_algorithm_framework name")
71+
raise CommandError("you must provide a project name")
7072

7173
if not re.match("^[a-zA-Z]+\w*$", name):
7274
raise CommandError("{} is not allowed, value must begin with a letter and "
@@ -80,6 +82,6 @@ def validate_name(name: str) -> None:
8082
else:
8183
raise CommandError(
8284
"'{}' conflicts with the name of an existing Python "
83-
"module and cannot be used as a investing_algorithm_framework name. Please try "
85+
"module and cannot be used as a project name. Please try "
8486
"another name.".format(name)
8587
)

investing_algorithm_framework/core/management/commands/help.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def add_arguments(self, parser) -> None:
1717
def handle(self) -> Any:
1818
usage = [
1919
"",
20-
"This is the command line management for the investing investing_algorithm_framework framework. \n"
20+
"This is the command line management for the investing algorithm framework. \n"
2121
"Type help <sub_command>' for help on a specific sub command.",
2222
"",
2323
"Available sub commands:",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from typing import Any
2+
3+
from investing_algorithm_framework.core.management.command import BaseCommand, CommandError
4+
from investing_algorithm_framework.core.context import Context
5+
from investing_algorithm_framework.core.configuration.config_constants import SETTINGS_CONTEXT_CONFIGURATION
6+
from investing_algorithm_framework.core.configuration import settings
7+
8+
9+
class RunAlgorithmCommand(BaseCommand):
10+
help_message = (
11+
"Runs a instance of an algorithm created with the investing_algorithm_framework, by default it will run "
12+
"until stopped, if cycles is specified it will run the according to the amount of cycles"
13+
)
14+
15+
success_message = (
16+
"Algorithm is finished running"
17+
)
18+
19+
def add_arguments(self, parser) -> None:
20+
pass
21+
22+
def handle(self, *args, **options) -> Any:
23+
24+
# configure settings
25+
settings.configure()
26+
27+
# Load the context configuration
28+
__import__(settings[SETTINGS_CONTEXT_CONFIGURATION])
29+
30+
# Create an investing_algorithm_framework context of the investing_algorithm_framework and run it
31+
context = Context()
32+
context.start()
33+
34+
35+
36+

investing_algorithm_framework/core/management/commands/runbot.py

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

0 commit comments

Comments
 (0)