Skip to content

Commit

Permalink
Delete account finding code in the streaming client as the account in…
Browse files Browse the repository at this point in the history
…fo is contained in the streamer data now
  • Loading branch information
alexgolec committed May 4, 2024
1 parent d22b13a commit e9717f3
Showing 1 changed file with 2 additions and 42 deletions.
44 changes: 2 additions & 42 deletions schwab/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ def __init__(self, client, *, account_id=None,
self._ssl_context = ssl_context
self._client = client

# If None, will be set by the login() function
self._account_id = account_id

# Set by the login() function
self._account = None
self._stream_correl_id = None
Expand Down Expand Up @@ -196,37 +193,9 @@ async def _receive(self):
return ret

async def _init_from_preferences(self, prefs, websocket_connect_args):
# Initialize accounts and streamer keys.
# Assume a 1-to-1 mapping of streamer keys to accounts.
accounts = prefs['accounts']
num_accounts = len(accounts)
assert num_accounts > 0, 'zero accounts found'

# If there's only one account, use it. Otherwise require an account ID.
streamer_info_idx = 0
if num_accounts == 1:
self._account = accounts[0]
else:
if self._account_id is None:
raise ValueError(
'multiple accounts found and StreamClient was ' +
'initialized with unspecified account_id')
for idx, account in enumerate(accounts):
if int(account['accountId']) == self._account_id:
self._account = account
streamer_info_idx = idx
break

if self._account is None:
raise ValueError(
'no account found with account_id {}'.format(
self._account_id))

if self._account_id is None:
self._account_id = self._account['accountNumber']

# Record streamer subscription keys
stream_info = prefs['streamerInfo'][streamer_info_idx]
stream_info = prefs['streamerInfo'][0]

self._stream_correl_id = stream_info['schwabClientCorrelId']
self._stream_customer_id = stream_info['schwabClientCustomerId']
self._stream_channel = stream_info['schwabClientChannel']
Expand All @@ -235,15 +204,6 @@ async def _init_from_preferences(self, prefs, websocket_connect_args):
# Initialize socket
wss_url = stream_info['streamerSocketUrl']

# TODO: Is this still necessary?
if 'extensions' not in websocket_connect_args:
websocket_connect_args['extensions'] = [
ClientPerMessageDeflateFactory()
]
else:
websocket_connect_args['extensions'].append(
ClientPerMessageDeflateFactory())

self._socket = await ws_client.connect(
wss_url, **websocket_connect_args)

Expand Down

0 comments on commit e9717f3

Please sign in to comment.