summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhjoaquim <h.joaquim@campus.fct.unl.pt>2024-02-21 12:18:01 +0000
committerhjoaquim <h.joaquim@campus.fct.unl.pt>2024-02-21 12:18:01 +0000
commitcc8625c70050a866801d7b4c93caf36a832e15ae (patch)
treea462a5d42f78e2648201794189e79239354c8dd6
parentb5442ed3c7c0721ebaabecc0dba755ae6cb40266 (diff)
standard model
-rw-r--r--openbb_platform/core/openbb_core/provider/standard_models/market_historical.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/openbb_platform/core/openbb_core/provider/standard_models/market_historical.py b/openbb_platform/core/openbb_core/provider/standard_models/market_historical.py
new file mode 100644
index 00000000000..ebe02a4c4ce
--- /dev/null
+++ b/openbb_platform/core/openbb_core/provider/standard_models/market_historical.py
@@ -0,0 +1,54 @@
+"""Market Historical Price Standard Model."""
+
+from datetime import (
+ date as dateType,
+ datetime,
+)
+from typing import Optional
+
+from dateutil import parser
+from pydantic import Field, PositiveFloat, field_validator
+
+from openbb_core.provider.abstract.data import Data
+from openbb_core.provider.abstract.query_params import QueryParams
+from openbb_core.provider.utils.descriptions import (
+ DATA_DESCRIPTIONS,
+ QUERY_DESCRIPTIONS,
+)
+
+
+class MarketHistoricalQueryParams(QueryParams):
+ """Market Historical Price Query."""
+
+ symbol: str = Field(description=QUERY_DESCRIPTIONS.get("symbol", ""))
+ start_date: Optional[dateType] = Field(
+ default=None,
+ description=QUERY_DESCRIPTIONS.get("start_date", ""),
+ )
+ end_date: Optional[dateType] = Field(
+ default=None,
+ description=QUERY_DESCRIPTIONS.get("end_date", ""),
+ )
+
+ @field_validator("symbol", mode="before", check_fields=False)
+ @classmethod
+ def upper_symbol(cls, v: str) -> str:
+ """Convert symbol to uppercase."""
+ return v.upper()
+
+
+class MarketHistoricalData(Data):
+ """Market Historical Price Data."""
+
+ date: datetime = Field(description=DATA_DESCRIPTIONS.get("date", ""))
+ open: PositiveFloat = Field(description=DATA_DESCRIPTIONS.get("open", ""))
+ high: PositiveFloat = Field(description=DATA_DESCRIPTIONS.get("high", ""))
+ low: PositiveFloat = Field(description=DATA_DESCRIPTIONS.get("low", ""))
+ close: PositiveFloat = Field(description=DATA_DESCRIPTIONS.get("close", ""))
+ volume: float = Field(description=DATA_DESCRIPTIONS.get("volume", ""))
+
+ @field_validator("date", mode="before", check_fields=False)
+ @classmethod
+ def date_validate(cls, v): # pylint: disable=E0213
+ """Return formatted datetime."""
+ return parser.isoparse(str(v))