|
1 | 1 | from sysdata.data_blob import dataBlob |
2 | 2 | from syscore.constants import arg_not_supplied |
| 3 | +from syscore.exceptions import missingData |
3 | 4 | from syscore.interactive.menus import print_menu_of_values_and_get_response |
4 | 5 | from sysproduction.data.positions import diagPositions |
5 | 6 | from sysproduction.data.optimal_positions import dataOptimalPositions |
@@ -47,15 +48,16 @@ def config(self): |
47 | 48 |
|
48 | 49 |
|
49 | 50 | def get_list_of_strategies(data: dataBlob = arg_not_supplied, source="config") -> list: |
50 | | - if source == "config": |
51 | | - return get_list_of_strategies_from_config(data) |
52 | | - elif source == "positions": |
53 | | - return get_list_of_strategies_from_positions(data) |
54 | | - elif source == "optimal_positions": |
55 | | - return get_list_of_strategies_from_optimal_positions(data) |
56 | | - else: |
| 51 | + handlers = { |
| 52 | + "config": get_list_of_strategies_from_config, |
| 53 | + "positions": get_list_of_strategies_from_positions, |
| 54 | + "optimal_positions": get_list_of_strategies_from_optimal_positions, |
| 55 | + } |
| 56 | + if source not in handlers.keys(): |
57 | 57 | raise Exception("Source %s not recognised!" % source) |
58 | 58 |
|
| 59 | + return handlers[source](data) |
| 60 | + |
59 | 61 |
|
60 | 62 | def get_list_of_strategies_from_config(data: dataBlob = arg_not_supplied) -> list: |
61 | 63 | diag_strategies_config = diagStrategiesConfig(data) |
@@ -87,8 +89,19 @@ def get_valid_strategy_name_from_user( |
87 | 89 | allow_all: bool = False, |
88 | 90 | all_code: str = "ALL", |
89 | 91 | source: str = "config", |
90 | | -): |
| 92 | + prompt: str = "Which strategy?", |
| 93 | + backup_source: str = None, |
| 94 | +) -> str: |
| 95 | + assert source != backup_source |
| 96 | + print(prompt) |
91 | 97 | all_strategies = get_list_of_strategies(data=data, source=source) |
| 98 | + if not all_strategies and backup_source: |
| 99 | + print(f"No strategies found using source '{source}', trying '{backup_source}'") |
| 100 | + all_strategies = get_list_of_strategies(data=data, source=backup_source) |
| 101 | + |
| 102 | + if not all_strategies: |
| 103 | + raise missingData("No strategies found") |
| 104 | + |
92 | 105 | if allow_all: |
93 | 106 | default_strategy = all_code |
94 | 107 | else: |
|
0 commit comments