[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
This commit is contained in:
asymness
2022-07-26 17:23:35 +05:00
committed by GitHub
parent a768e545a8
commit 9f91cf8ae8
2 changed files with 14 additions and 12 deletions

View File

@@ -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('_', ' ')}"

View File

@@ -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 │
├───────────┼─────────────────────────────────────────────────────┼───────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤