boyan-soubachov / tastyworks_api

An unofficial, reverse-engineered Python API for tastyworks.
Apache License 2.0
209 stars 79 forks source link

Time does not exist in quote the response #30

Closed tylerfloyd closed 5 years ago

tylerfloyd commented 5 years ago

Describe the bug When getting a quote, the error is KeyError: time on : tastyworks/dxfeed/quote.py", line 10

To Reproduce Steps to reproduce the behavior:

  1. Execute tasty
  2. Allow the script to log in and create a test order
  3. See the error in terminal

Expected behavior The quote should be returned without error

Additional context

Stack trace:
2018-12-30 10:19:05,059 Exception in main loop
Traceback (most recent call last):
  File "/tastyworks_api/tastyworks/example.py", line 92, in main
    loop.run_until_complete(main_loop(tasty_client, streamer))
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
    return future.result()
  File "/tastyworks_api/tastyworks/example.py", line 67, in main_loop
    async for item in streamer.listen():
  File "/tastyworks_api/tastyworks/streamer.py", line 227, in listen
    res = await self._consumer(msg)
  File "/tastyworks_api/tastyworks/streamer.py", line 125, in _consumer
    return dxfeed_mapper.map_message(msg_object)
  File "/tastyworks_api/tastyworks/dxfeed/mapper.py", line 24, in map_message
    res = quote.Quote(data=data)
  File "/tastyworks_api/tastyworks/dxfeed/quote.py", line 16, in __init__
    super().__init__(data=data)
  File "/tastyworks_api/tastyworks/dxfeed/mapped_item.py", line 56, in __init__
    self.data = self._map_data(data)
  File "/tastyworks_api/tastyworks/dxfeed/mapped_item.py", line 44, in _map_data
    res.append(self._process_fields(dict(zip(keys, local_values))))
  File "/tastyworks_api/tastyworks/dxfeed/quote.py", line 10, in _process_fields
    data_dict[key] = datetime.datetime.fromtimestamp(data_dict[key] / 1000)
KeyError: 'time'
New Response

The new message return from Tasty has the following keys:

"eventSymbol"
"eventTime"
"sequence"
"timeNanoPart"
"bidTime"
"bidExchangeCode"
"bidPrice"
"bidSize"
"askTime"
"askExchangeCode"
"askPrice"
"askSize"
Additional Notes

I removed time from the loop and then received an error on the timeNanos key. I replaced timeNanos with eventTime and received quotes correctly. However, without fully understanding the context and how these values are used, I am not confident in that change.

carriere4 commented 5 years ago

I received the same error. I have not attempted any changes - this was my first time logging in. Definitely appreciate the fact that this API exists, so happy to help with my limited skillset.

boyan-soubachov commented 5 years ago

Thanks @tylerfloyd , it seems they've removed the time key. I will update and merge to master soon. Please let me know if the new version is still just as good or if any of those other keys should also be added in there.