06/03 Optimize codes, fix Schwab Account sync errors

This commit is contained in:
2026-06-03 13:26:32 -04:00
parent e8601c59df
commit 56608ed220
2 changed files with 18 additions and 5 deletions
+11
View File
@@ -163,6 +163,17 @@ def _raise_for_status(resp, context=''):
# ── Public API helpers ────────────────────────────────────────────────────────
def get_account_number_hashes(connection):
"""
Return {accountNumber: hashValue} mapping.
Schwab requires the hashValue (encrypted account number) in all endpoint paths.
"""
data = _authed_get(connection, '/trader/v1/accounts/accountNumbers')
mapping = {item['accountNumber']: item['hashValue'] for item in data}
log.info('[schwab] get_account_number_hashes: %d account(s)', len(mapping))
return mapping
def get_accounts(connection):
"""Return list of Schwab account dicts."""
data = _authed_get(connection, '/trader/v1/accounts', params={'fields': 'positions'})