Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamer update for the new DXFeed API #83

Merged
merged 22 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ jobs:
run: |
python -m pytest --cov=tastytrade --cov-report=term-missing tests/ --cov-fail-under=95
env:
TT_USERNAME: ${{ secrets.TT_USERNAME }}
TT_PASSWORD: ${{ secrets.TT_PASSWORD }}
TT_USERNAME: tastyware
TT_PASSWORD: :4s-S9/9L&Q~C]@v
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ The streamer is a websocket connection to dxfeed (the Tastytrade data provider)

.. code-block:: python

from tastytrade import DataStreamer
from tastytrade import DXFeedStreamer
from tastytrade.dxfeed import EventType

streamer = await DataStreamer.create(session)
streamer = await DXFeedStreamer.create(session)
subs_list = ['SPY', 'SPX']

await streamer.subscribe(EventType.QUOTE, subs_list)
Expand Down
8 changes: 4 additions & 4 deletions docs/data-streamer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ You can create a streamer using an active production session:

.. code-block:: python

from tastytrade import DataStreamer
streamer = await DataStreamer.create(session)
from tastytrade import DXFeedStreamer
streamer = await DXFeedStreamer.create(session)

Once you've created the streamer, you can subscribe/unsubscribe to events, like ``Quote``:

Expand Down Expand Up @@ -67,7 +67,7 @@ For example, we can use the streamer to create an option chain that will continu
class LivePrices:
quotes: dict[str, Quote]
greeks: dict[str, Greeks]
streamer: DataStreamer
streamer: DXFeedStreamer
puts: list[Option]
calls: list[Option]

Expand All @@ -83,7 +83,7 @@ For example, we can use the streamer to create an option chain that will continu
# the `streamer_symbol` property is the symbol used by the streamer
streamer_symbols = [o.streamer_symbol for o in options]

streamer = await DataStreamer.create(session)
streamer = await DXFeedStreamer.create(session)
# subscribe to quotes and greeks for all options on that date
await streamer.subscribe(EventType.QUOTE, [symbol] + streamer_symbols)
await streamer.subscribe(EventType.GREEKS, streamer_symbols)
Expand Down
2 changes: 1 addition & 1 deletion docs/sessions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Events
------

A ``ProductionSession`` can be used to make simple requests to the dxfeed REST API and pull quotes, greeks and more.
These requests are slower than ``DataStreamer`` and a separate request is required for each event fetched, so they're really more appropriate for a task that just needs to grab some information once. For recurring data feeds/streams or more time-sensitive tasks, the streamer is more appropriate.
These requests are slower than ``DXFeedStreamer`` and a separate request is required for each event fetched, so they're really more appropriate for a task that just needs to grab some information once. For recurring data feeds/streams or more time-sensitive tasks, the streamer is more appropriate.

Events are simply market data at a specific timestamp. There's a variety of different kinds of events supported, including:

Expand Down
8 changes: 5 additions & 3 deletions tastytrade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
from .account import Account # noqa: E402
from .search import symbol_search # noqa: E402
from .session import CertificationSession, ProductionSession # noqa: E402
from .streamer import AlertStreamer, DataStreamer # noqa: E402
from .streamer import (AccountStreamer, DXFeedStreamer, # noqa: E402
DXLinkStreamer)
from .watchlists import PairsWatchlist, Watchlist # noqa: E402

__all__ = [
'Account',
'AlertStreamer',
'AccountStreamer',
'CertificationSession',
'DataStreamer',
'DXFeedStreamer',
'DXLinkStreamer',
'PairsWatchlist',
'ProductionSession',
'Watchlist',
Expand Down
5 changes: 3 additions & 2 deletions tastytrade/dxfeed/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ class EventType(str, Enum):
for the data streamer.

Information on different types of events, their uses and their properties
can be found at the `dxfeed Knowledge Base
can be found at the `dxfeed Knowledge Base.
<https://kb.dxfeed.com/en/data-model/dxfeed-api-market-events.html>`_.
"""

CANDLE = 'Candle'
GREEKS = 'Greeks'
PROFILE = 'Profile'
Expand All @@ -28,7 +29,7 @@ class Event(ABC):
def from_stream(cls, data: list) -> List['Event']: # pragma: no cover
"""
Makes a list of event objects from a list of raw trade data fetched by
a :class:`~tastyworks.streamer.DataStreamer`.
a :class:`~tastyworks.streamer.DXFeedStreamer`.

:param data: list of raw quote data from streamer

Expand Down
3 changes: 2 additions & 1 deletion tastytrade/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ def __init__(
data = response.json()['data']
self.streamer_token = data['token']
url = data['websocket-url'] + '/cometd'
self.streamer_url = url.replace('https', 'wss')
self.dxfeed_url = url.replace('https', 'wss')
self.dxlink_url = data['dxlink-url']
self.rest_url = data['websocket-url'] + '/rest/events.json'
self.streamer_headers = {
'Authorization': f'Bearer {self.streamer_token}'
Expand Down
Loading
Loading