interactive-broker-python-api icon indicating copy to clipboard operation
interactive-broker-python-api copied to clipboard

Implementing streaming market data

Open orshemtov opened this issue 3 years ago • 1 comments

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!

orshemtov avatar May 05 '21 20:05 orshemtov

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()

leowotzak avatar Jun 08 '21 16:06 leowotzak