tastyware / tastytrade

An unofficial, sync/async Python SDK for Tastytrade!
https://tastyworks-api.rtfd.io
MIT License
126 stars 43 forks source link

pulling historical ohlc? #108

Closed fritol closed 6 months ago

fritol commented 1 year ago

Is there any way to pull historical data? I mean how does their web UI pull chart data?

Quenos commented 1 year ago

This can be done with the DXLinkStreamer

async with DXLinkStreamer(session) as streamer:
    subs = ['SPY', 'AAPL']
    await streamer.subscribe_candle(subs, '1d', start_date)
    candle = await streamer.get_event(EventType.CANDLE)
Graeme22 commented 1 year ago

OHLC data is obtained through Candle events. See more here: https://tastyworks-api.readthedocs.io/en/latest/sessions.html#events https://tastyworks-api.readthedocs.io/en/latest/tastytrade.html#tastytrade.streamer.DXLinkStreamer.subscribe_candle

autsauce commented 10 months ago

This can be done with the DXLinkStreamer

async with DXLinkStreamer(session) as streamer:
    subs = ['SPY', 'AAPL']
    await streamer.subscribe_candle(subs, '1d', start_date)
    candle = await streamer.get_event(EventType.CANDLE)

Is this supposed to work with futures contracts as well?

Graeme22 commented 10 months ago

Yes, you'll need to use dxfeed notation for futures though: https://tastyworks-api.readthedocs.io/en/latest/dxfeed.html