Skip to content

Commit

Permalink
[Display] handle missing run metadata for live displayed elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume De Saint Martin committed Mar 21, 2023
1 parent 4b0301b commit 6b80f02
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
31 changes: 20 additions & 11 deletions Meta/Keywords/scripting_library/UI/plots/displayed_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ async def fill_from_database(self, trading_mode, database_manager, exchange_name
exchange_name, symbol, time_frame = \
await self._adapt_inputs_for_backtesting_results(meta_db, exchange_name, symbol, time_frame)
run_db = meta_db.get_run_db()
metadata = (await run_db.all(commons_enums.DBTables.METADATA.value))[0]
account_type = trading_api.get_account_type_from_run_metadata(metadata)
metadata_rows = await run_db.all(commons_enums.DBTables.METADATA.value)
metadata = metadata_rows[0] if metadata_rows else None
account_type = trading_api.get_account_type_from_run_metadata(metadata) \
if database_manager.is_backtesting() \
else trading_api.get_account_type_from_exchange_manager(
trading_api.get_exchange_manager_from_exchange_id(exchange_id)
)
dbs = [
run_db,
meta_db.get_transactions_db(account_type, exchange_name),
Expand Down Expand Up @@ -107,15 +112,19 @@ async def _adapt_inputs_for_backtesting_results(self, meta_db, exchange_name, sy
exchange_name = single_exchange
if not await meta_db.run_dbs_identifier.symbol_base_identifier_exists(exchange_name, symbol):
run_metadata = await meta_db.get_run_db().all(commons_enums.DBTables.METADATA.value)
symbols = run_metadata[0].get(commons_enums.DBRows.SYMBOLS.value, [])
if len(symbols) == 1:
# retarget symbol
symbol = symbols[0]
else:
# no single exchange with data
raise commons_errors.MissingExchangeDataError(
f"No symbol related data for {exchange_name}"
)
try:
symbols = run_metadata[0].get(commons_enums.DBRows.SYMBOLS.value, [])
if len(symbols) == 1:
# retarget symbol
symbol = symbols[0]
else:
# no single exchange with data
raise commons_errors.MissingExchangeDataError(
f"No symbol related data for {exchange_name}"
)
except IndexError:
# no run metadata, try to continue
pass
return exchange_name, symbol, time_frame

def _plot_graphs(self, graphs_by_parts):
Expand Down
7 changes: 4 additions & 3 deletions Services/Interfaces/web_interface/models/backtesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@ def start_backtesting_using_current_bot_data(data_source, exchange_id, source, r

def stop_previous_backtesting():
previous_independent_backtesting = web_interface_root.WebInterface.tools[constants.BOT_TOOLS_BACKTESTING]
if previous_independent_backtesting and \
not octobot_api.is_independent_backtesting_stopped(previous_independent_backtesting):
if previous_independent_backtesting \
and not octobot_api.is_independent_backtesting_stopped(previous_independent_backtesting):
interfaces_util.run_in_bot_main_loop(
octobot_api.stop_independent_backtesting(previous_independent_backtesting))
octobot_api.stop_independent_backtesting(previous_independent_backtesting)
)
return True, "Backtesting is stopping"
return True, "No backtesting to stop"

Expand Down

0 comments on commit 6b80f02

Please sign in to comment.