def from_dict(cls, d: Dict) -> Stock: temp = dict(d) temp["asof"] = parse_date(d["asof"]) if d.get("asof") else None temp["indicators"] = {k: StockIndicator.from_dict(v) for k, v in d.get("indicators", dict()).items()} temp["realTimeDetails"] = StockRealTimeDetails.from_dict(d.get("realTimeDetails", dict())) temp.pop("historicPrices", []) return Stock(**temp)
def from_dict(cls, d: Dict) -> Fund: temp = dict(d) temp["type"] = FundType.from_str(d.get("type")) # type: ignore temp["shareClass"] = FundShareClass.from_str(d.get("shareClass")) # type: ignore temp["holdings"] = [FundHolding.from_dict(e) for e in d.get("holdings", [])] temp["asof"] = parse_date(d["asof"]) if d.get("asof") else None temp["indicators"] = {k: FundIndicator.from_dict(v) for k, v in d.get("indicators", dict()).items()} temp["realTimeDetails"] = FundRealTimeDetails.from_dict(d.get("realTimeDetails", dict())) temp.pop("historicPrices", []) return Fund(**temp)
def from_dict(cls, d: Dict) -> StockRealTimeDetails: temp = dict(d) temp["lastUpdated"] = parse_date(d["lastUpdated"]) if d.get("lastUpdated") else None return StockRealTimeDetails(**temp)
def test_parse_date(): s = "2019-01-01T00:00:00Z" assert parse_date(s) == datetime(2019, 1, 1, tzinfo=timezone.utc)
def _parse_date(cls, date_str: Optional[str]) -> Optional[date]: # type: ignore return parse_date(date_str).date() if date_str else None
def from_dict(cls, d: Dict) -> FundRealTimeDetails: temp = dict(d) temp["ci"] = tuple(d.get("ci", [None, None])) temp["holdings"] = [FundRealTimeHolding.from_dict(h) for h in d.get("holdings", [])] temp["lastUpdated"] = parse_date(d["lastUpdated"]) if d.get("lastUpdated") else None return FundRealTimeDetails(**temp)