From 9f91cf8ae8c4ded1a0cc948b522e3b3cffad1c52 Mon Sep 17 00:00:00 2001 From: asymness Date: Tue, 26 Jul 2022 17:23:35 +0500 Subject: [PATCH] [Bugfix/TradeBalance] Fix parameter name for TradeBalance and handle 'null' response from EconDB API (#2179) * Fix parameter name for Trade Balance * Handle the case of 'null' response content with OK status code * Change TBFR parameter name to TB in hugo docs --- openbb_terminal/economy/econdb_model.py | 24 ++++++++++--------- .../content/terminal/economy/macro/_index.md | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/openbb_terminal/economy/econdb_model.py b/openbb_terminal/economy/econdb_model.py index c94c70751dc..4e35b42f2fd 100644 --- a/openbb_terminal/economy/econdb_model.py +++ b/openbb_terminal/economy/econdb_model.py @@ -354,7 +354,7 @@ PARAMETERS = { "period": "Monthly", "description": "A record of a country's international transactions with the rest of the world", }, - "TBFR": { + "TB": { "name": "Trade balance", "period": "Monthly", "description": "The difference between the monetary value of a nation's exports and imports over a " @@ -515,18 +515,20 @@ def get_macro_data( r = requests.get( f"https://www.econdb.com/series/context/?tickers={parameter}{country_code}" ) - data = r.json()[0] - scale = data["td"]["scale"] - units = data["td"]["units"] + res_json = r.json() + if res_json: + data = res_json[0] + scale = data["td"]["scale"] + units = data["td"]["units"] - df = pd.DataFrame(data["dataarray"]) - df = ( - df.set_index(pd.to_datetime(df["date"]))[f"{parameter}{country_code}"] - * SCALES[scale] - ) - df = df.sort_index().dropna() + df = pd.DataFrame(data["dataarray"]) + df = ( + df.set_index(pd.to_datetime(df["date"]))[f"{parameter}{country_code}"] + * SCALES[scale] + ) + df = df.sort_index().dropna() - if df.empty: + if not res_json or df.empty: console.print( f"No data available for {parameter} ({PARAMETERS[parameter]['name']}) " f"of country {country.replace('_', ' ')}" diff --git a/website/content/terminal/economy/macro/_index.md b/website/content/terminal/economy/macro/_index.md index 37d09362759..79a9bb4ec33 100644 --- a/website/content/terminal/economy/macro/_index.md +++ b/website/content/terminal/economy/macro/_index.md @@ -105,7 +105,7 @@ Example: ├───────────┼─────────────────────────────────────────────────────┼───────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ CA │ Current account balance │ Monthly │ A record of a country's international transactions with the rest of the world │ ├───────────┼─────────────────────────────────────────────────────┼───────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ -│ TBFR │ Trade balance │ Monthly │ The difference between the monetary value of a nation's exports and imports over a certain time period. │ +│ TB │ Trade balance │ Monthly │ The difference between the monetary value of a nation's exports and imports over a certain time period. │ ├───────────┼─────────────────────────────────────────────────────┼───────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ NIIP │ Net international investment position │ Quarterly │ Measures the gap between a nation's stock of foreign assets and a foreigner's stock of that nation's assets │ ├───────────┼─────────────────────────────────────────────────────┼───────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤