diff --git a/cschwabpy/models/__init__.py b/cschwabpy/models/__init__.py index 6459efa..1d90673 100644 --- a/cschwabpy/models/__init__.py +++ b/cschwabpy/models/__init__.py @@ -207,12 +207,12 @@ class Market(JSONSerializableBaseModel): class EquityMarket(JSONSerializableBaseModel): - EQ: Market + EQ: Optional[Market] = None class OptionMarket(JSONSerializableBaseModel): - EQO: Market - IND: Market + EQO: Optional[Market] = None + IND: Optional[Market] = None class MarketHourInfo(JSONSerializableBaseModel): @@ -220,19 +220,30 @@ class MarketHourInfo(JSONSerializableBaseModel): option: Optional[OptionMarket] = None @property - def is_equity_market_open(self) -> Optional[bool]: - if self.equity is None: - return None + def is_equity_market_open(self) -> bool: + if self.equity is None or self.equity.EQ is None: + return False return self.equity.EQ.isOpen @property - def is_option_market_open(self) -> Optional[bool]: + def is_option_market_open(self) -> bool: if self.option is None: - return None + return False return self.option.EQO.isOpen or self.option.IND.isOpen + @property + def equity_regular_market_hours(self) -> List[MarketHours]: + if ( + self.equity is None + or self.equity.EQ is None + or self.equity.EQ.sessionHours is None + ): + return [] + + return self.equity.EQ.sessionHours.regularMarket + class OptionChainQueryFilter(QueryFilterBase): symbol: str diff --git a/pyproject.toml b/pyproject.toml index c751a8b..0511043 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cschwabpy" -version = "0.1.3.7" +version = "0.1.3.8" description = "" authors = ["Tony Wang "] readme = "README.md" diff --git a/setup.py b/setup.py index 5fd193b..0e52312 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="CSchwabPy", - version="0.1.3.7", + version="0.1.3.8", description="Charles Schwab Stock & Option Trade API Client for Python.", long_description=long_description, long_description_content_type="text/markdown", diff --git a/tests/test_models.py b/tests/test_models.py index d20ee5b..dc64c4b 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -97,6 +97,7 @@ async def test_market_hours(httpx_mock: HTTPXMock) -> None: all_market = MarketHourInfo(**all_market_json) assert all_market is not None assert all_market.equity is not None + assert all_market.equity.EQ is not None assert all_market.equity.EQ.sessionHours is not None assert all_market.equity.EQ.sessionHours.regularMarket is not None assert all_market.equity.EQ.sessionHours.preMarket is not None