Skip to content

Commit b43f945

Browse files
committed
streaming
1 parent 08f1981 commit b43f945

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

stream_client.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ def __init__(self, client: APIClient):
2323
async def start(self):
2424
response = self.client.get_user_preferences()
2525
if not response:
26-
self.color_print.print("error", f"Failed to get streamer info: {response.status_code}")
26+
self.color_print.print("error", f"Failed to get streamer info: {response.text}")
2727
exit(1)
2828
self.streamer_info = response['streamerInfo'][0]
2929
login = self._construct_login_message()
30-
30+
self.color_print.print("info", "Starting stream...")
31+
self.color_print.print("info", f"Streamer info: {self.streamer_info}")
32+
self.color_print.print("info", f"Login message: {login}")
3133
while True:
3234
try:
3335
await self._connect_and_stream(login)
@@ -37,13 +39,15 @@ async def start(self):
3739
except Exception as e:
3840
self.color_print.print("error", f"{e}")
3941
self._handle_stream_error(e)
40-
42+
4143
def _construct_login_message(self):
4244
self.request_id += 1
4345
return basic_request("ADMIN", "LOGIN", self.request_id, {
4446
"Authorization": self.client.token_info.get("access_token"),
4547
"SchwabClientChannel": self.streamer_info.get("schwabClientChannel"),
46-
"SchwabClientFunctionId": self.streamer_info.get("schwabClientFunctionId")
48+
"SchwabClientFunctionId": self.streamer_info.get("schwabClientFunctionId"),
49+
"SchwabClientCustomerId": self.streamer_info.get("schwabClientCustomerId"),
50+
"SchwabClientCorrelId": self.streamer_info.get("schwabClientCorrelId")
4751
})
4852

4953
async def _connect_and_stream(self, login):
@@ -71,15 +75,13 @@ def _handle_stream_error(self, error):
7175
else:
7276
self.terminal.print("[WARNING]: Connection lost to server, reconnecting...")
7377

74-
def send(self, listOfRequests):
75-
async def _send(to_send):
76-
await self.websocket.send(to_send)
78+
async def send(self, listOfRequests):
7779

7880
if not isinstance(listOfRequests, list):
7981
listOfRequests = [listOfRequests]
8082
if self.active:
8183
to_send = json.dumps({"requests": listOfRequests})
82-
asyncio.run(_send(to_send))
84+
await self.websocket.send(to_send)
8385
else:
8486
self.color_print.print("warning", "Stream is not active, nothing sent.")
8587

0 commit comments

Comments
 (0)