Skip to content

Commit de7ae32

Browse files
committed
Fix logging
1 parent 53be774 commit de7ae32

File tree

4 files changed

+70
-16
lines changed

4 files changed

+70
-16
lines changed

investing_algorithm_framework/templates/states/data_providing_state.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
from investing_algorithm_framework.core.workers import Worker
77
from investing_algorithm_framework.core.executors import Executor
88
from investing_algorithm_framework.configuration.config_constants \
9-
import DEFAULT_MAX_WORKERS, SETTINGS_MAX_WORKERS
9+
import SETTINGS_MAX_CONCURRENT_WORKERS, DEFAULT_MAX_WORKERS
10+
from investing_algorithm_framework.templates.data_providers.data_provider \
11+
import DataProviderInterface
1012

1113

1214
class DataProvidingState(State):
@@ -40,12 +42,25 @@ def run(self) -> None:
4042
# Execute all the data providers
4143
executor = Executor(
4244
workers=self.registered_data_providers,
43-
max_concurrent_workers=self.context.settings.get(
44-
SETTINGS_MAX_WORKERS, DEFAULT_MAX_WORKERS
45+
max_concurrent_workers=self.context.config.get(
46+
SETTINGS_MAX_CONCURRENT_WORKERS, DEFAULT_MAX_WORKERS
4547
)
4648
)
4749
executor.start()
4850

4951
@staticmethod
50-
def register_data_providers(data_providers: List[Worker]) -> None:
52+
def register_data_providers(data_providers: List) -> None:
53+
54+
for data_provider in data_providers:
55+
56+
assert isinstance(data_provider, Worker), (
57+
'Data provider {} must be of type '
58+
'Worker'.format(data_provider.__class__)
59+
)
60+
61+
assert isinstance(data_provider, DataProviderInterface), (
62+
'Data provider {} must be of type '
63+
'DataProviderInterface'.format(data_provider.__class__)
64+
)
65+
5166
DataProvidingState.registered_data_providers = data_providers
Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
from typing import List
2+
import logging
23

4+
from investing_algorithm_framework.core.executors import Executor
35
from investing_algorithm_framework.core.state import State
46
from investing_algorithm_framework.core.exceptions import OperationalException
5-
from investing_algorithm_framework.templates.order_executors \
6-
import OrderExecutor
7+
from investing_algorithm_framework.core.workers import Worker
8+
from investing_algorithm_framework.configuration.config_constants import \
9+
SETTINGS_MAX_CONCURRENT_WORKERS, DEFAULT_MAX_WORKERS
10+
from investing_algorithm_framework.templates.order_executors.order_executor \
11+
import OrderExecutorInterface
712

813

914
class OrderingState(State):
@@ -12,21 +17,40 @@ class OrderingState(State):
1217
import DataProvidingState
1318
transition_state_class = DataProvidingState
1419

15-
order_executors: List[OrderExecutor] = None
20+
registered_order_executors: List[Worker] = None
1621

1722
def __init__(self, context) -> None:
1823
super(OrderingState, self).__init__(context)
1924

20-
if self.order_executors is None or len(self.order_executors) < 1:
25+
if self.registered_order_executors is None \
26+
or len(self.registered_order_executors) < 1:
2127
raise OperationalException(
2228
"OrderingState state has not any order executors configured"
2329
)
2430

2531
def run(self) -> None:
2632

27-
for order_executor in OrderingState.order_executors:
28-
order_executor.execute_orders()
33+
# Execute all the order executors
34+
executor = Executor(
35+
workers=self.registered_order_executors,
36+
max_concurrent_workers=self.context.config.get(
37+
SETTINGS_MAX_CONCURRENT_WORKERS, DEFAULT_MAX_WORKERS
38+
)
39+
)
40+
executor.start()
2941

3042
@staticmethod
31-
def register_order_executors(order_executors: List[OrderExecutor]) -> None:
32-
OrderingState.order_executors = order_executors
43+
def register_order_executors(order_executors: List) -> None:
44+
45+
for order_executor in order_executors:
46+
assert isinstance(order_executor, Worker), (
47+
'Order executor {} must be of type '
48+
'Worker'.format(order_executor.__class__)
49+
)
50+
51+
assert isinstance(order_executor, OrderExecutorInterface), (
52+
'Order executor {} must be of type '
53+
'OrderExecutorInterface'.format(order_executor.__class__)
54+
)
55+
56+
OrderingState.registered_order_executors = order_executors

investing_algorithm_framework/templates/states/setup_state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def run(self) -> None:
2121
"""
2222

2323
# Load the settings
24-
if not self.context.settings.configured:
24+
if not self.context.config.configured:
2525
raise ImproperlyConfigured(
2626
"Settings module is not specified, make sure you have setup "
2727
"a investing_algorithm_framework project and the "

investing_algorithm_framework/templates/states/strategy_state.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
from investing_algorithm_framework.core.exceptions import OperationalException
55
from investing_algorithm_framework.core.executors import Executor
66
from investing_algorithm_framework.configuration.config_constants \
7-
import DEFAULT_MAX_WORKERS, SETTINGS_MAX_WORKERS
7+
import DEFAULT_MAX_WORKERS, SETTINGS_MAX_CONCURRENT_WORKERS
88
from investing_algorithm_framework.core.workers import Worker
9+
from investing_algorithm_framework.templates.strategies.strategy \
10+
import StrategyInterface
911

1012

1113
class StrategyState(State):
@@ -33,14 +35,27 @@ def run(self) -> None:
3335
# Execute all the strategies
3436
executor = Executor(
3537
workers=self.registered_strategies,
36-
max_concurrent_workers=self.context.settings.get(
37-
SETTINGS_MAX_WORKERS, DEFAULT_MAX_WORKERS
38+
max_concurrent_workers=self.context.config.get(
39+
SETTINGS_MAX_CONCURRENT_WORKERS, DEFAULT_MAX_WORKERS
3840
)
3941
)
4042
executor.start()
4143

4244
@staticmethod
4345
def register_strategies(strategies: List) -> None:
46+
47+
for strategy in strategies:
48+
49+
assert isinstance(strategy, Worker), (
50+
'Strategy {} must be of type '
51+
'Worker'.format(strategy.__class__)
52+
)
53+
54+
assert isinstance(strategy, StrategyInterface), (
55+
'Strategy {} must be of type '
56+
'StrategyInterface'.format(strategy.__class__)
57+
)
58+
4459
StrategyState.registered_strategies = strategies
4560

4661
def get_transition_state_class(self):

0 commit comments

Comments
 (0)