summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrique Joaquim <henriquecjoaquim@gmail.com>2024-05-14 13:15:33 +0100
committerGitHub <noreply@github.com>2024-05-14 12:15:33 +0000
commit88cdd75a6d14f3f0143c5b8dcc94417c0968b02d (patch)
tree2807765910d7ddfd39c1dfd3884fee978ccbf2bc
parent0eee602098d9b783ec0df03c464ee6bc1da4d9bf (diff)
[Feature] Custom Provider choices available on the `reference.json` (#6409)
* change package builder and argparse translator to account for custom chocies defined in providers * default reference
-rw-r--r--cli/openbb_cli/argparse_translator/argparse_translator.py14
-rw-r--r--openbb_platform/core/openbb_core/app/static/package_builder.py5
-rw-r--r--openbb_platform/openbb/assets/reference.json9410
3 files changed, 6375 insertions, 3054 deletions
diff --git a/cli/openbb_cli/argparse_translator/argparse_translator.py b/cli/openbb_cli/argparse_translator/argparse_translator.py
index 724c2bea306..7931b22304f 100644
--- a/cli/openbb_cli/argparse_translator/argparse_translator.py
+++ b/cli/openbb_cli/argparse_translator/argparse_translator.py
@@ -42,7 +42,7 @@ class CustomArgument(BaseModel):
action: Literal["store_true", "store"]
help: str
nargs: Optional[Literal["+"]]
- choices: Optional[Any]
+ choices: Optional[Tuple]
@model_validator(mode="after") # type: ignore
@classmethod
@@ -117,7 +117,7 @@ class ReferenceToCustomArgumentsProcessor:
return "+"
return None
- def _get_choices(self, type_: str) -> Tuple:
+ def _get_choices(self, type_: str, custom_choices: Any) -> Tuple:
"""Get the choices for the given type."""
type_ = self._make_type_parsable(type_) # type: ignore
type_origin = get_origin(type_)
@@ -126,14 +126,12 @@ class ReferenceToCustomArgumentsProcessor:
if type_origin is Literal:
choices = get_args(type_)
- # param_type = type(choices[0])
if type_origin is list:
type_ = get_args(type_)[0]
if get_origin(type_) is Literal:
choices = get_args(type_)
- # param_type = type(choices[0])
if type_origin is Union and type(None) in get_args(type_):
# remove NoneType from the args
@@ -145,7 +143,9 @@ class ReferenceToCustomArgumentsProcessor:
if get_origin(type_) is Literal:
choices = get_args(type_)
- # param_type = type(choices[0])
+
+ if custom_choices:
+ return tuple(custom_choices)
return choices
@@ -174,7 +174,9 @@ class ReferenceToCustomArgumentsProcessor:
action="store" if type_ != bool else "store_true",
help=arg["description"],
nargs=self._get_nargs(type_), # type: ignore
- choices=self._get_choices(arg["type"]),
+ choices=self._get_choices(
+ arg["type"], custom_choices=arg["choices"]
+ ),
)
)
diff --git a/openbb_platform/core/openbb_core/app/static/package_builder.py b/openbb_platform/core/openbb_core/app/static/package_builder.py
index 11fcc5766b0..feb3803f6ed 100644
--- a/openbb_platform/core/openbb_core/app/static/package_builder.py
+++ b/openbb_platform/core/openbb_core/app/static/package_builder.py
@@ -1483,8 +1483,10 @@ class ReferenceGenerator:
.strip().replace("\n", " ").replace(" ", " ").replace('"', "'")
) # fmt: skip
+ extra = field_info.json_schema_extra or {}
+
# Add information for the providers supporting multiple symbols
- if params_type == "QueryParams" and (extra := field_info.json_schema_extra):
+ if params_type == "QueryParams" and extra:
providers = []
for p, v in extra.items(): # type: ignore[union-attr]
@@ -1512,6 +1514,7 @@ class ReferenceGenerator:
"description": cleaned_description,
"default": default_value,
"optional": not is_required,
+ "choices": extra.get("choices"),
}
)
diff --git a/openbb_platform/openbb/assets/reference.json b/openbb_platform/openbb/assets/reference.json
index 91095c1bd2a..f184e92a4c4 100644
--- a/openbb_platform/openbb/assets/reference.json
+++ b/openbb_platform/openbb/assets/reference.json
@@ -50,21 +50,24 @@
"type": "Union[str, List[str]]",
"description": "Symbol to get data for. Can use CURR1-CURR2 or CURR1CURR2 format. Multiple items allowed for provider(s): fmp, polygon, tiingo, yfinance.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "start_date",
"type": "Union[date, str]",
"description": "Start date of the data, in YYYY-MM-DD format.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "end_date",
"type": "Union[date, str]",
"description": "End date of the data, in YYYY-MM-DD format.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "provider",
@@ -80,7 +83,8 @@
"type": "Literal['1m', '5m', '15m', '30m', '1h', '4h', '1d']",
"description": "Time interval of the data to return.",
"default": "1d",
- "optional": true
+ "optional": true,
+ "choices": null
}
],
"polygon": [
@@ -89,21 +93,24 @@
"type": "str",
"description": "Time interval of the data to return. The numeric portion of the interval can be any positive integer. The letter portion can be one of the following: s, m, h, d, W, M, Q, Y",
"default": "1d",
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "sort",
"type": "Literal['asc', 'desc']",
"description": "Sort order of the data. This impacts the results in combination with the 'limit' parameter. The results are always returned in ascending order by date.",
"default": "asc",
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "limit",
"type": "int",
"description": "The number of data entries to return.",
"default": 49999,
- "optional": true
+ "optional": true,
+ "choices": null
}
],
"tiingo": [
@@ -112,14 +119,16 @@
"type": "Literal['1m', '5m', '15m', '30m', '1h', '4h', '1d']",
"description": "Time interval of the data to return.",
"default": "1d",
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "exchanges",
"type": "List[str]",
"description": "To limit the query to a subset of exchanges e.g. ['POLONIEX', 'GDAX']",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
}
],
"yfinance": [
@@ -128,7 +137,8 @@
"type": "Literal['1m', '2m', '5m', '15m', '30m', '60m', '90m', '1h', '1d', '5d', '1W', '1M', '1Q']",
"description": "Time interval of the data to return.",
"default": "1d",
- "optional": true
+ "optional": true,
+ "choices": null
}
]
},
@@ -168,49 +178,56 @@
"type": "Union[date, datetime]",
"description": "The date of the data.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "open",
"type": "float",
"description": "The open price.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "high",
"type": "float",
"description": "The high price.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "low",
"type": "float",
"description": "The low price.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "close",
"type": "float",
"description": "The close price.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "volume",
"type": "float",
"description": "The trading volume.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "vwap",
"type": "Annotated[float, Gt(gt=0)]",
"description": "Volume Weighted Average Price over the period.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
}
],
"fmp": [
@@ -219,21 +236,24 @@
"type": "float",
"description": "The adjusted close price.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "change",
"type": "float",
"description": "Change in the price from the previous close.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "change_percent",
"type": "float",
"description": "Change in the price from the previous close, as a normalized percent.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
}
],
"polygon": [
@@ -242,7 +262,8 @@
"type": "Annotated[int, Gt(gt=0)]",
"description": "Number of transactions for the symbol in the time period.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
}
],
"tiingo": [
@@ -251,14 +272,16 @@
"type": "int",
"description": "Number of transactions for the symbol in the time period.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "volume_notional",
"type": "float",
"description": "The last size done for the asset on the specific date in the quote currency. The volume of the asset on the specific date in the quote currency.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
}
],
"yfinance": []
@@ -279,7 +302,8 @@
"type": "str",
"description": "Search query.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "provider",
@@ -327,14 +351,16 @@
"type": "str",
"description": "Symbol representing the entity requested in the data. (Crypto)",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "name",
"type": "str",
"description": "Name of the crypto.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
}
],
"fmp": [
@@ -343,21 +369,24 @@
"type": "str",
"description": "The currency the crypto trades for.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "exchange",
"type": "str",
"description": "The exchange code the crypto trades on.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "exchange_name",
"type": "str",
"description": "The short name of the exchange the crypto trades on.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
}
]
},
@@ -377,21 +406,24 @@
"type": "Union[str, List[str]]",
"description": "Symbol to get data for. Can use CURR1-CURR2 or CURR1CURR2 format. Multiple items allowed for provider(s): fmp, polygon, tiingo, yfinance.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "start_date",
"type": "Union[date, str]",
"description": "Start date of the data, in YYYY-MM-DD format.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "end_date",
"type": "Union[date, str]",
"description": "End date of the data, in YYYY-MM-DD format.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "provider",
@@ -407,7 +439,8 @@
"type": "Literal['1m', '5m', '15m', '30m', '1h', '4h', '1d']",
"description": "Time interval of the data to return.",
"default": "1d",
- "optional": true
+ "optional": true,
+ "choices": null
}
],
"polygon": [
@@ -416,21 +449,24 @@
"type": "str",
"description": "Time interval of the data to return. The numeric portion of the interval can be any positive integer. The letter portion can be one of the following: s, m, h, d, W, M, Q, Y",
"default": "1d",
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "sort",
"type": "Literal['asc', 'desc']",
"description": "Sort order of the data. This impacts the results in combination with the 'limit' parameter. The results are always returned in ascending order by date.",
"default": "asc",
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "limit",
"type": "int",
"description": "The number of data entries to return.",
"default": 49999,
- "optional": true
+ "optional": true,
+ "choices": null
}
],
"tiingo": [
@@ -439,7 +475,8 @@
"type": "Literal['1m', '5m', '15m', '30m', '1h', '4h', '1d']",
"description": "Time interval of the data to return.",
"default": "1d",
- "optional": true
+ "optional": true,
+ "choices": null
}
],
"yfinance": [
@@ -448,7 +485,8 @@
"type": "Literal['1m', '2m', '5m', '15m', '30m', '60m', '90m', '1h', '1d', '5d', '1W', '1M', '1Q']",
"description": "Time interval of the data to return.",
"default": "1d",
- "optional": true
+ "optional": true,
+ "choices": null
}
]
},
@@ -488,49 +526,56 @@
"type": "Union[date, datetime]",
"description": "The date of the data.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "open",
"type": "float",
"description": "The open price.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "high",
"type": "float",
"description": "The high price.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "low",
"type": "float",
"description": "The low price.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "close",
"type": "float",
"description": "The close price.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "volume",
"type": "float",
"description": "The trading volume.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "vwap",
"type": "Annotated[float, Gt(gt=0)]",
"description": "Volume Weighted Average Price over the period.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
}
],
"fmp": [
@@ -539,21 +584,24 @@
"type": "float",
"description": "The adjusted close price.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "change",
"type": "float",
"description": "Change in the price from the previous close.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "change_percent",
"type": "float",
"description": "Change in the price from the previous close, as a normalized percent.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
}
],
"polygon": [
@@ -562,7 +610,8 @@
"type": "Annotated[int, Gt(gt=0)]",
"description": "Number of transactions for the symbol in the time period.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
}
],
"tiingo": [],
@@ -584,7 +633,8 @@
"type": "str",
"description": "Query to search for currency pairs.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "provider",
@@ -634,14 +684,16 @@
"type": "str",
"description": "Symbol representing the entity requested in the data.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "name",
"type": "str",
"description": "Name of the currency pair.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
}
],
"fmp": [
@@ -650,28 +702,32 @@
"type": "str",
"description": "Symbol of the currency pair.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "currency",
"type": "str",
"description": "Base currency of the currency pair.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "stock_exchange",
"type": "str",
"description": "Stock exchange of the currency pair.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "exchange_short_name",
"type": "str",
"description": "Short name of the stock exchange of the currency pair.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
}
],
"intrinio": [
@@ -680,14 +736,16 @@
"type": "str",
"description": "ISO 4217 currency code of the base currency.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "quote_currency",
"type": "str",
"description": "ISO 4217 currency code of the quote currency.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
}
],
"polygon": [
@@ -696,49 +754,56 @@
"type": "str",
"description": "The symbol of the quote currency.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "base_currency_symbol",
"type": "str",
"description": "The symbol of the base currency.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "base_currency_name",
"type": "str",
"description": "Name of the base currency.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "market",
"type": "str",
"description": "Name of the trading market. Always 'fx'.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "locale",
"type": "str",
"description": "Locale of the currency pair.",
"default": "",
- "optional": false
+ "optional": false,
+ "choices": null
},
{
"name": "last_updated",
"type": "date",
"description": "The date the reference data was last updated.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "delisted",
"type": "date",
"description": "The date the item was delisted.",
"default": null,
- "optional": true
+ "optional": true,
+ "choices": null
}
]
},
@@ -758,21 +823,24 @@
"type": "Union[str, List[str]]",
"description": "The base currency symbol. Multiple items allowed for provider(s): fmp, polygon.",
"default": "usd",
- "optional": true
+ "optional": true,
+ "choices": null
},
{
"name": "quote_type",
"type": "Literal['direct', 'indirect']",
"description": "Whether the quote is direct or indirect. Selecting 'direct' will return the exchange rate as the amount of domestic currency required to buy one unit of th