interactive-broker-python-api
interactive-broker-python-api copied to clipboard
Implementing streaming market data
Hi,
Thank you for all the work you did on this API.
I've been following the YouTube videos, it seems like the API does not provide support for streaming data.
Could you explain how one might integrate streaming data with the existing functionality?
It would be nice to have a stream of market data, and for those using technical indicators, a bit of historical data to warm up the indicators that require more than 1 pricing data point.
Thank you!
Fixes #26
Heres how I have it implemented. Its a little bit more complicated than simply going to the endpoint, you need to use a websocket (and SSL) to stream data, which also requires that you use a little bit of asyncio. Let me know if you have any questions. The print messages are where my logic would go
import websockets
import asyncio
async def stream_data():
async with websockets.connect('wss://localhost:5000/v1/api/ws', ssl=context) as ibsock:
async for message in ibsock:
print(message)
asyncio.run(stream_data()