Skip to content

Commit 07f1e9c

Browse files
committed
cr fixes
1 parent d54f662 commit 07f1e9c

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

alpaca_trade_api/stream2.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def __init__(
231231
self._data_stream = _data_stream
232232
self._debug = debug
233233
self._raw_data = raw_data
234-
self.stop_stream_queue = queue.Queue()
234+
self._stop_stream_queue = queue.Queue()
235235

236236
self.trading_ws = _StreamConn(self._key_id,
237237
self._secret_key,
@@ -342,8 +342,8 @@ def run(self, initial_channels: List[str] = []):
342342
logging.error(f"error while consuming ws messages: {m}")
343343
if self._debug:
344344
traceback.print_exc()
345-
if not self.stop_stream_queue.empty():
346-
self.stop_stream_queue.get()
345+
if not self._stop_stream_queue.empty():
346+
self._stop_stream_queue.get()
347347
should_renew = False
348348
loop.run_until_complete(self.close(should_renew))
349349
if loop.is_running():
@@ -378,12 +378,11 @@ async def close(self, renew):
378378
self._oauth,
379379
raw_data=self._raw_data)
380380

381-
async def signal_stop_ws(self):
381+
async def stop_ws(self):
382382
"""
383-
Signal the ws connections to stop.
384-
We set a signal in a Queue and then call cancel_task
383+
Signal the ws connections to stop listenning to api stream.
385384
"""
386-
self.stop_stream_queue.put_nowait({"should_stop": True})
385+
self._stop_stream_queue.put_nowait({"should_stop": True})
387386
if self.trading_ws is not None:
388387
logging.info("Stopping the trading websocket connection")
389388
await self.trading_ws.cancel_task()

examples/websockets/streamconn_on_and_off.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ async def on_trades(conn, channel, trade):
5959
while 1:
6060
threading.Thread(target=consumer_thread).start()
6161
time.sleep(5)
62-
loop.run_until_complete(conn.close(renew=False))
62+
loop.run_until_complete(conn.stop_ws())
6363
time.sleep(20)

0 commit comments

Comments
 (0)