"""SEC ETF Holings Model."""
# pylint: disable =[unused-argument,too-many-locals,too-many-branches]
import asyncio
from datetime import date as dateType
from typing import Any, Dict, List, Optional, Union
from warnings import warn
import pandas as pd
import xmltodict
from aiohttp_client_cache import SQLiteBackend
from aiohttp_client_cache.session import CachedSession
from openbb_core.app.utils import get_user_cache_directory
from openbb_core.provider.abstract.annotated_result import AnnotatedResult
from openbb_core.provider.abstract.fetcher import Fetcher
from openbb_core.provider.standard_models.etf_holdings import (
EtfHoldingsData,
EtfHoldingsQueryParams,
)
from openbb_core.provider.utils.descriptions import QUERY_DESCRIPTIONS
from openbb_core.provider.utils.errors import EmptyDataError
from openbb_core.provider.utils.helpers import amake_request
from openbb_sec.utils.helpers import HEADERS, get_nport_candidates
from pandas.tseries.offsets import MonthEnd
from pydantic import Field, field_validator, model_validator
class SecEtfHoldingsQueryParams(EtfHoldingsQueryParams):
"""SEC ETF Holdings Query.
Source: https://www.sec.gov/Archives/edgar/data/
"""
date: Optional[Union[str, dateType]] = Field(
description=QUERY_DESCRIPTIONS.get("date", "")
+ " The date represents the period ending."
+ " The date entered will return the closest filing.",
default=None,
)
use_cache: bool = Field(
description="Whether or not to use cache for the request.",
default=True,
)
class SecEtfHoldingsData(EtfHoldingsData):
"""SEC ETF Holdings Data."""
__alias_dict__ = {"name": "title"}
lei: Optional[str] = Field(description="The LEI of the holding.", default=None)
cusip: Optional[str] = Field(description="The CUSIP of the holding.", default=None)
isin: Optional[str] = Field(description="The ISIN of the holding.", default=None)
other_id: Optional[str] = Field(
description="Internal identifier for the holding.", default=None
)
balance: Optional[float] = Field(
description="The balance of the holding.", default=None
)
weight: Optional[float] = Field(
description="The weight of the holding in ETF in %.",
alias="pctVal",
default=None,
json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
)
value: Optional[float] = Field(
description="The value of the holding in USD.", alias="valUSD", default=None
)
payoff_profile: Optional[str] = Field(
description="The payoff profile of the holding.",
alias="payoffProfile",
default=None,
)
units: Optional[Union[float, str]] = Field(
description="The units of the holding.", default=None
)
currency: Optional[str] = Field(
description="The currency of the holding.", alias="curCd", default=None
)
asset_category: Optional[str] = Field(
description="The asset category of the holding.", alias="assetCat", default=None
)
issuer_category: Optional[str] = Field(
description="The issuer category of the holding.",
alias="issuerCat",
default=None,
)
country: Optional[str] = Field(
description="The country of the holding.", alias="invCountry", default=None
)
is_restricted: Optional[str] = Field(
description="Whether the holding is restricted.",
alias="isRestrictedSec",
default=None,
)
fair_value_level: Optional[int] = Field(
description="The fair value level of the holding.",
alias="fairValLevel",
default=None,
)
is_cash_collateral: Optional[str] = Field(
description="Whether the holding is cash collateral.",
alias="isCashCollateral"