Skip to content

Commit

Permalink
Merge pull request #37 from rcholic/minor_fix2
Browse files Browse the repository at this point in the history
equity market check
  • Loading branch information
rcholic authored Jul 21, 2024
2 parents a4b3a2c + 311fdd5 commit 2fac2f8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
27 changes: 19 additions & 8 deletions cschwabpy/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,32 +207,43 @@ 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):
equity: Optional[EquityMarket] = None
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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cschwabpy"
version = "0.1.3.7"
version = "0.1.3.8"
description = ""
authors = ["Tony Wang <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2fac2f8

Please sign in to comment.