tastyware / tastytrade

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

Candle streaming not returning the latest candle #173

Closed inanisvitae closed 1 month ago

inanisvitae commented 1 month ago

Describe the bug When I run this on weekend like Sunday,

async def test_dxlink_streamer(s):
    async with DXLinkStreamer(s, ssl.SSLContext(cafile=certifi.where())) as streamer:
        subs = ["GOOG"]
        await streamer.subscribe(Quote, subs)
        start_date = datetime.today() - timedelta(days=300)
        print(start_date)
        await streamer.subscribe_candle(subs, "1w", start_date)
        _ = await streamer.get_event(Candle)
        async for c in streamer.listen(Candle):
            print(c)
        streamer.unsubscribe_all()

somehow it doesn't return the latest weekly data, eventSymbol='GOOG{=w,tho=true}' eventTime=0 eventFlags=0 index=7425414339231744000 time=1728864000000 sequence=0 count=860998 open=Decimal('164.91') high=Decimal('169.09') low=Decimal('164.37') close=Decimal('165.06') volume=Decimal('47603566.0') vwap=Decimal('166.1442368957657') bidVolume=Decimal('23371380.0') askVolume=Decimal('24232186.0') impVolatility=Decimal('0.3523') openInterest=None is the latest candle. 1728864000000 is 2 weeks ago instead of the most recent Monday. Same issue also exists with daily timeframe. Thanks in advance. How to reproduce Post your code so the source of the problem can be identified.

Graeme22 commented 1 month ago

The parameter to subscribe_candle is start_time not start_date, and should be a datetime object.

inanisvitae commented 1 month ago

Hi, It is datetime object I'm just using the example in https://github.com/tastyware/tastytrade/blob/master/tests/test_streamer.py The last candle's timestamp is 1728864000000 which is October 14 instead of October 20. The last Monday.

Graeme22 commented 1 month ago

Ah my bad! You were indeed using it correctly. I ran it and got the latest week's data just fine. I think your problem is you're throwing away the most recent data with this line:

_ = await streamer.get_event(Candle)
inanisvitae commented 1 month ago

Right! Thanks a lot.