diff options
author | hjoaquim <h.joaquim@campus.fct.unl.pt> | 2024-03-27 17:09:54 +0000 |
---|---|---|
committer | hjoaquim <h.joaquim@campus.fct.unl.pt> | 2024-03-27 17:09:54 +0000 |
commit | 6cd5d5c0a38077fd4fe929e1b4784b732298b625 (patch) | |
tree | 770dc69b0c8eae9ac7a5696a842902cc2f1e3ee2 | |
parent | 4b5787b11db395375ddbee0acaccdce79df6e740 (diff) |
adding sort to tiingo equity historicalbugfix/sort-tiingo-historical
-rw-r--r-- | openbb_platform/providers/tiingo/openbb_tiingo/models/equity_historical.py | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/openbb_platform/providers/tiingo/openbb_tiingo/models/equity_historical.py b/openbb_platform/providers/tiingo/openbb_tiingo/models/equity_historical.py index 401f1f14c01..38985858453 100644 --- a/openbb_platform/providers/tiingo/openbb_tiingo/models/equity_historical.py +++ b/openbb_platform/providers/tiingo/openbb_tiingo/models/equity_historical.py @@ -21,7 +21,7 @@ from openbb_core.provider.utils.helpers import ( amake_requests, get_querystring, ) -from pydantic import Field, PrivateAttr, model_validator +from pydantic import Field, PrivateAttr, field_validator, model_validator _warn = warnings.warn @@ -44,6 +44,24 @@ class TiingoEquityHistoricalQueryParams(EquityHistoricalQueryParams): _frequency: Literal["daily", "weekly", "monthly", "annually"] = PrivateAttr( default=None ) + sort: Literal[ + "adj_open", + "adj_high", + "adj_low", + "adj_close", + "adj_volume", + "split_ratio", + "dividend", + "open", + "high", + "low", + "close", + "volume", + "date", + ] = Field( + default="date", + description="Column to sort the data by. Default is by date.", + ) # pylint: disable=protected-access @model_validator(mode="after") # type: ignore[arg-type] @@ -61,6 +79,22 @@ class TiingoEquityHistoricalQueryParams(EquityHistoricalQueryParams): return values + @field_validator("sort", mode="after") + @classmethod + def map_sort(cls, v: str) -> str: + """Map the sort column to the Tiingo API columns.""" + sort_dict = { + "adj_open": "adjOpen", + "adj_high": "adjHigh", + "adj_low": "adjLow", + "adj_close": "adjClose", + "adj_volume": "adjVolume", + "split_ratio": "splitFactor", + "dividend": "divCash", + } + + return sort_dict[v] + class TiingoEquityHistoricalData(EquityHistoricalData): """Tiingo Equity Historical Price Data.""" @@ -142,7 +176,7 @@ class TiingoEquityHistoricalFetcher( async def callback(response: ClientResponse, _: Any) -> List[Dict]: data = await response.json() symbol = response.url.parts[-2] - results = [] + results: List[Any] = [] if not data: _warn(f"No data found the the symbol: {symbol}") return results |