Skip to content

Commit

Permalink
rename param account number hash
Browse files Browse the repository at this point in the history
  • Loading branch information
rcholic committed Jun 8, 2024
1 parent e340ea0 commit d4a09cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
19 changes: 9 additions & 10 deletions cschwabpy/SchwabAsyncClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ async def get_account_numbers_async(self) -> List[AccountNumberWithHashID]:
async def get_accounts_async(
self,
include_positions: bool = True,
with_account_number: Optional[AccountNumberWithHashID] = None,
with_account_number_hash: Optional[AccountNumberWithHashID] = None,
) -> List[Account]:
"""get all accounts except a specific account_number is provided."""
await self._ensure_valid_access_token()
target_url = f"{SCHWAB_TRADER_API_BASE_URL}/accounts"
if with_account_number is not None:
target_url = f"{target_url}/{with_account_number.hashValue}"
if with_account_number_hash is not None:
target_url = f"{target_url}/{with_account_number_hash.hashValue}"

if include_positions:
target_url = f"{target_url}?fields=positions"
Expand All @@ -151,7 +151,7 @@ async def get_accounts_async(
)
if response.status_code == 200:
json_res = response.json()
if with_account_number is None:
if with_account_number_hash is None:
accounts: List[SecuritiesAccount] = []
for account_json in json_res:
securities_account = SecuritiesAccount(
Expand All @@ -172,12 +172,13 @@ async def get_accounts_async(

async def get_single_account_async(
self,
with_account_number: AccountNumberWithHashID,
with_account_number_hash: AccountNumberWithHashID,
include_positions: bool = True,
) -> Optional[Account]:
"""Convenience method to get a single account by account number's encrypted ID."""
account = await self.get_accounts_async(
include_positions=include_positions, with_account_number=with_account_number
include_positions=include_positions,
with_account_number_hash=with_account_number_hash,
)
if account is None or len(account) == 0:
return None
Expand All @@ -186,16 +187,14 @@ async def get_single_account_async(

async def get_orders_async(
self,
account_number: AccountNumberWithHashID,
account_number_hash: AccountNumberWithHashID,
from_entered_time: datetime,
to_entered_time: datetime,
max_count: int = 1000,
status: Optional[OrderStatus] = None,
) -> List[Order]:
await self._ensure_valid_access_token()
target_url = (
f"{SCHWAB_TRADER_API_BASE_URL}/accounts/{account_number.hashValue}/orders"
)
target_url = f"{SCHWAB_TRADER_API_BASE_URL}/accounts/{account_number_hash.hashValue}/orders"
target_url += f"?fromEnteredTime={util.to_iso8601_str(from_entered_time)}&toEnteredTime={util.to_iso8601_str(to_entered_time)}&maxResults={max_count}"
if status is not None:
target_url += f"&status={status.value}"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async def test_get_order(httpx_mock: HTTPXMock):
http_client=client,
)
retrieved_orders = await cschwab_client.get_orders_async(
account_number=mock_account(),
account_number_hash=mock_account(),
from_entered_time=from_entered_time,
to_entered_time=to_entered_time,
status=OrderStatus.FILLED,
Expand Down Expand Up @@ -142,7 +142,7 @@ async def test_get_single_account(httpx_mock: HTTPXMock):
http_client=client,
)
single_account = await cschwab_client.get_single_account_async(
with_account_number=mock_account(), include_positions=True
with_account_number_hash=mock_account(), include_positions=True
)
assert single_account is not None
assert single_account.accountNumber == "123"
Expand Down

0 comments on commit d4a09cb

Please sign in to comment.