mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-08 18:32:21 +00:00
[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:
@@ -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('_', ' ')}"
|
||||
|
||||
@@ -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 │
|
||||
├───────────┼─────────────────────────────────────────────────────┼───────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
|
||||
|
||||
Reference in New Issue
Block a user