-
-
Notifications
You must be signed in to change notification settings - Fork 341
Description
Description of Bug
The stream socket is closed abruptly, with a SSL error. The error message is,
Here is the main function executing
async def main():
global main_loop
main_loop = asyncio.get_running_loop()
await startSocket()
# Initialize Schwab API client
client = schwabdev.Client('adaad', 'adasda', 'https://127.0.0.1:8841')
# define a variable for the steamer:
global streamer
# Define the streamer
streamer = client.stream
# Manual start the stream with the handler
# streamer.start(handler_wrapper)
# Auto start the stream with the handler
start_time = datetime.time(9, 29, 50) # Create a time object
stop_time = datetime.time(16, 0, 0) # Create a time object
streamer.start_auto(
receiver=handler_wrapper,
start_time=start_time, # Hours and minutes are passed as integers
stop_time=stop_time, # Hours and minutes as integers
on_days=(0, 1, 2, 3, 4),
now_timezone=zoneinfo.ZoneInfo("America/New_York"),
daemon=True
)
# Subscribe to the desired data stream
await streamer.send_async(streamer.level_one_futures("/ES", fields=list(range(0, 43))))
await streamer.send_async(streamer.level_one_futures("/MES", fields=list(range(0, 43))))
await subscribe_to_equities(streamer, "$SPX", "SPXW")
await subscribe_to_equities(streamer, "SPY", "SPY ")
await generate_custom_instruments()
# Schedule the dynamic adjustment of the middle strike price every 2 minutes
# schedule.every(15).minutes.do(adjust_middle_strike)
# Schedule the dynamic adjustment of the middle strike price every 2 minutes
schedule.every(15).minutes.do(run_async_job)
asyncio.create_task(scheduler_loop())
#await scheduler_loop() # Start the scheduling loop
import time
try:
while True:
# time.sleep(1) # Sleep to reduce CPU usage in the loop
await asyncio.sleep(1) # Non-blocking sleep to keep the event loop alive
except KeyboardInterrupt:
# Handle clean shutdown on Ctrl+C
logging.info("Shutting down streamer...")
streamer.stop(clear_subscriptions=False)
# Stop the stream after 60 seconds for demo purposes
# time.sleep(60)
# streamer.stop()
if name == "main":
asyncio.run(main())
Expected Behavior
Stream should be close and reconnected
Actual Behavior
The stream isn't restarted
Error/Exception Log
ERROR:asyncio:Fatal error on SSL protocol
protocol: <asyncio.sslproto.SSLProtocol object at 0x7454f5c938d0>
transport: <_SelectorSocketTransport closing fd=11 read=idle write=<idle, bufsize=0>>
Traceback (most recent call last):
File "/usr/local/lib/python3.11/asyncio/sslproto.py", line 694, in _write_appdata
self._do_write()
File "/usr/local/lib/python3.11/asyncio/sslproto.py", line 709, in _do_write
del self._write_backlog[0]
~~~~~~~~~~~~~~~~~~~^^^
IndexError: deque index out of range
ERROR:Schwabdev:no close frame received or sent
INFO:Schwabdev:Stream is not active, request queued.
ERROR:Schwabdev:Stream connection Error. Reconnecting in 2.0 seconds...
INFO:Schwabdev:Stream is not active, request queued.
INFO:Schwabdev:Stream is not active, request queued.