Skip to content

Using Historical Data Websocket for Real-Time OHLC Data #38

@jackroc97

Description

@jackroc97

I am trying to stream 1 min OHLC data in real-time. I've tried using the market history example as a starting point for this. I am a little confused on how to interpret the data. The first response is OHLC for the 1 min bar for the previous minute (for example, if I run the script at 17:06, it would be the bar for 17:05). A sample response is shown below:

QueueAccessor(key=IbkrWsKey.MARKET_HISTORY, size=1) {'serverId': '588547', 'symbol': 'AAPL', 'text': 'APPLE INC', 'priceFactor': 100, 'startTime': '20241223-17:05:00', 'high': '25495/56.04/1', 'low': '25482/245.49/0', 'timePeriod': '60s', 'barLength': 60, 'mdAvailability': 'S', 'mktDataDelay': 0, 'outsideRth': False, 'volumeFactor': 100, 'priceDisplayRule': 1, 'priceDisplayValue': '2', 'negativeCapable': False, 'messageVersion': 2, 'data': [{'o': 254.91, 'c': 254.91, 'h': 254.94, 'l': 254.82}, {'o': 254.9, 'c': 254.9, 'h': 254.95, 'l': 254.9}], 'points': 1, 'travelTime': 9, 'topic': 'smh+265598', 'payload': '{"period": "1min", "bar": "1min", "outsideRTH": true, "source": "trades", "format": "%o/%c/%h/%l"}'}

The subsequent responses however only contain either just "open" or "open" and "close" data, with no time associated. For example:

QueueAccessor(key=IbkrWsKey.MARKET_HISTORY, size=2) {'serverId': '588547', 'tickNum': 36, 'negativeCapable': False, 'data': [{'o': 254.8}], 'points': 0, 'travelTime': 44668, 'topic': 'smh+265598', 'payload': '{"period": "1min", "bar": "1min", "outsideRTH": true, "source": "trades", "format": "%o/%c/%h/%l"}'}

Is it possible to use this websocket endpoint to get a real-time stream of OHLC bars, or would that be a misuse of it? It appears to return data in realtime, but seems to be incomplete... or perhaps I am misinterpreting the response.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions