tastyware / tastytrade

An unofficial Python SDK for Tastytrade!
MIT License
98 stars 33 forks source link

Missing bidTime and askTime in EventType.QUOTE #119

Closed pressplay21 closed 1 week ago

pressplay21 commented 5 months ago

Describe the bug I'm trying out the new DXLinkStreamer. bidTime and askTime are missing from the event data. Without any timestamp, we wouldn't know if quotes are still streaming. I'm still using the old DataStreamer and I can confirm that the bidTime and askTime are available.

Symbol = 'SPX' Streamer Symbol = 'SPXW240119P4975'

'.SPXW240119P4975': Quote(eventSymbol='.SPXW240119P4975', eventTime=0, sequence=0, timeNanoPart=0, bidTime=0, bidExchangeCode='C', bidPrice=137.9, bidSize=1.0, askTime=0, askExchangeCode='C', askPrice=138.7, askSize=1.0)}

How to reproduce

from tastytrade import DXLinkStreamer
from tastytrade.dxfeed import EventType

async with DXLinkStreamer(session) as streamer:
    subs_list = ['SPX']  # list of symbols to subscribe to
    await streamer.subscribe(EventType.QUOTE, subs_list)
    # this example fetches quotes once, then exits
    quote = await streamer.get_event(EventType.QUOTE)
    print(quote)

Quote(eventSymbol='SPX', eventTime=0, sequence=0, timeNanoPart=0, bidTime=0, bidExchangeCode='', bidPrice=4835.73, bidSize='NaN', askTime=0, askExchangeCode='', askPrice=4837.39, askSize='NaN')

Graeme22 commented 5 months ago

I'm a bit confused, in both the examples you posted bidTime and askTime are equivalent, so it doesn't seem to be a difference between the DXFeedStreamer and DXLinkStreamer... Did you mean size perhaps?

pressplay21 commented 5 months ago

Sorry about the confusion. Both examples are using DXLinkStreamer. The streamer symbols are just different.

Here's an example of Datastreamer. askTime and bidTime are in millisecond epoch.

(If you look at the event symbol, it is today. Datastreamer is still working. I haven't got a chance to look deeper at the diff between Datastreamer and DXLinkStreamer. I notice that you changed how you handle the websocket???) Quote(eventSymbol='.SPXW240119C4985', eventTime=0, sequence=0, timeNanoPart=0, bidTime=1705674603000, bidExchangeCode='C', bidPrice=0.0, bidSize='NaN', askTime=1705696318000, askExchangeCode='C', askPrice=0.05, askSize=4419.0)

BTW, I'm using version 6.1 Tastytrade. It was called Datastreamer. I think DXFeedStreamer was introduced in newer version than 6.1.

Graeme22 commented 5 months ago

Could you see if it's still a problem with the latest version?

Graeme22 commented 5 months ago

Although I suspect that this is on the API end so there's likely nothing that can be done

pressplay21 commented 5 months ago

Yeah I tried the latest DXLinkStreamer. It's still missing bidTime and askTime. The latest DXFeedStreamer still has them so I will continue to use DXFeed. In the meantime, I'll email Tastytrade support about DXLink and see what they have to say about it.

On a side note, I've been trying to test how long I can keep the streams alive for both DXLink and DXFeed. I'm streaming SPX EventType.TRADE and EventType.QUOTE. Are you noticing that the streams stop after a few hours??? On last friday, the streams stop 30mins before the market close. Are you aware of any rate limit or stream limit?

DXLinkStreamer output:

from tastytrade import DXLinkStreamer, DXFeedStreamer
from tastytrade.dxfeed import EventType

async with DXLinkStreamer(session) as streamer:
    subs_list = ['SPX']  # list of symbols to subscribe to
    await streamer.subscribe(EventType.QUOTE, subs_list)
    # this example fetches quotes once, then exits
    quote = await streamer.get_event(EventType.QUOTE)
    print(quote)

Quote(eventSymbol='SPX', eventTime=0, sequence=0, timeNanoPart=0, bidTime=0, bidExchangeCode='', bidPrice=4790.51, bidSize='NaN', askTime=0, askExchangeCode='', askPrice=4898.59, askSize='NaN')

DXFeedStreamer output:

from tastytrade import DXLinkStreamer, DXFeedStreamer
from tastytrade.dxfeed import EventType

async with DXFeedStreamer(session) as streamer:
    subs_list = ['SPX']  # list of symbols to subscribe to
    await streamer.subscribe(EventType.QUOTE, subs_list)
    # this example fetches quotes once, then exits
    quote = await streamer.get_event(EventType.QUOTE)
    print(quote)

Quote(eventSymbol='SPX', eventTime=0, sequence=0, timeNanoPart=0, bidTime=1705702549000, bidExchangeCode='\x00', bidPrice=4790.51, bidSize='NaN', askTime=1705702549000, askExchangeCode='\x00', askPrice=4898.59, askSize='NaN')
Graeme22 commented 5 months ago

Yeah I tried the latest DXLinkStreamer. It's still missing bidTime and askTime. The latest DXFeedStreamer still has them so I will continue to use DXFeed. In the meantime, I'll email Tastytrade support about DXLink and see what they have to say about it.

Sounds good, let me know if you hear anything from them and this gets fixed!

On a side note, I've been trying to test how long I can keep the streams alive for both DXLink and DXFeed. I'm streaming SPX EventType.TRADE and EventType.QUOTE. Are you noticing that the streams stop after a few hours??? On last friday, the streams stop 30mins before the market close. Are you aware of any rate limit or stream limit?

I definitely haven't noticed anything like that, that's weird considering that the streamer should keep on sending heartbeat messages as long as it's open. Are you sure the market was still open? It closes at 4pm EST. Was that the only time you had your streamers die on you?

Quenos commented 1 month ago

@Graeme22 @pressplay21 If you are streaming a lot of option series this might be due to a memory overflow. The number of quotes that are sent per second is insane.

The oeverflow exception is unfortunately not always propagated and the streamer just hangs.