Skip to content

Commit 8ff08ca

Browse files
authored
Add TT JSON object representation (#34)
* add TypedDicts for TT JSON objects * add typeddict docs * small typing changes * docs overhaul; use README in rtd and github
1 parent 4ba23be commit 8ff08ca

File tree

17 files changed

+462
-432
lines changed

17 files changed

+462
-432
lines changed

README.md

Lines changed: 0 additions & 34 deletions
This file was deleted.

README.rst

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
.. image:: https://readthedocs.org/projects/tastyworks-api/badge/?version=latest
2+
:target: https://tastyworks-api.readthedocs.io/en/latest/?badge=latest
3+
:alt: Documentation Status
4+
5+
.. image:: https://img.shields.io/pypi/v/tastytrade
6+
:target: https://pypi.org/project/tastytrade
7+
:alt: PyPI Package
8+
9+
.. image:: https://static.pepy.tech/badge/tastytrade
10+
:target: https://pepy.tech/project/tastytrade
11+
:alt: PyPI Downloads
12+
13+
Tastytrade Python SDK
14+
=====================
15+
16+
.. inclusion-marker
17+
18+
A simple, reverse-engineered SDK for Tastytrade built on their (mostly) public API. This will allow you to create trading algorithms for whatever strategies you may have quickly and painlessly in Python.
19+
20+
Installation
21+
------------
22+
23+
.. code-block:: bash
24+
25+
$ pip install tastytrade
26+
27+
Creating a session
28+
------------------
29+
30+
A session object is required to authenticate your requests to the Tastytrade API.
31+
You can create a real session using your normal login, or a certification (test) session using your certification login.
32+
33+
.. code-block:: python
34+
35+
from tastytrade.session import Session
36+
session = Session('username', 'password')
37+
38+
Using the streamer
39+
------------------
40+
41+
The streamer is a websocket connection to the Tastytrade API that allows you to subscribe to real-time data for Quotes, Greeks, and more.
42+
43+
.. code-block:: python
44+
45+
from tastytrade.streamer import DataStreamer, EventType
46+
47+
streamer = await DataStreamer.create(session)
48+
subs_list = ['SPY', 'SPX']
49+
50+
quotes = await streamer.oneshot(EventType.QUOTE, subs_list)
51+
print(quotes)
52+
53+
>>> [Quote(eventSymbol='SPY', eventTime=0, sequence=0, timeNanoPart=0, bidTime=0, bidExchangeCode='Q', bidPrice=411.58, bidSize=400.0, askTime=0, askExchangeCode='Q', askPrice=411.6, askSize=1313.0), Quote(eventSymbol='SPX', eventTime=0, sequence=0, timeNanoPart=0, bidTime=0, bidExchangeCode='\x00', bidPrice=4122.49, bidSize='NaN', askTime=0, askExchangeCode='\x00', askPrice=4123.65, askSize='NaN')]
54+
55+
Getting current positions
56+
-------------------------
57+
58+
.. code-block:: python
59+
60+
from tastytrade.account import Account
61+
62+
account = Account.get_accounts(session)[0]
63+
positions = account.get_positions(session)
64+
print(positions[0])
65+
66+
>>> {'account-number': '########', 'symbol': 'INTC', 'instrument-type': 'Equity', 'underlying-symbol': 'INTC', 'quantity': 1, 'quantity-direction': 'Long', 'close-price': '29.8', 'average-open-price': '29.2997', 'average-yearly-market-close-price': '29.2997', 'average-daily-market-close-price': '29.8', 'multiplier': 1, 'cost-effect': 'Credit', 'is-suppressed': False, 'is-frozen': False, 'restricted-quantity': 0, 'realized-day-gain': '0.015', 'realized-day-gain-effect': 'Debit', 'realized-day-gain-date': '2023-05-15', 'realized-today': '0.015', 'realized-today-effect': 'Debit', 'realized-today-date': '2023-05-15', 'created-at': '2023-05-15T15:38:38.124+00:00', 'updated-at': '2023-05-15T15:42:08.991+00:00'}
67+
68+
Symbol search
69+
-------------
70+
71+
.. code-block:: python
72+
73+
from tastytrade.search import symbol_search
74+
75+
results = symbol_search(session, 'AAP')
76+
print(results)
77+
78+
>>> [{'symbol': 'AAP', 'description': 'Advance Auto Parts Inc.'}, {'symbol': 'AAPL', 'description': 'Apple Inc. - Common Stock'}]
79+
80+
For more documentation and examples, check out: <https://tastyworks-api.readthedocs.io/en/latest/>.
81+
82+
Disclaimer
83+
----------
84+
85+
This is an unofficial SDK for Tastytrade. There is no implied warranty for any actions and results which arise from using it.

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"sphinx.ext.doctest",
2020
"sphinx.ext.autodoc",
2121
"sphinx.ext.autosummary",
22-
"sphinx.ext.intersphinx"
22+
"sphinx.ext.intersphinx",
23+
"sphinx_toolbox.more_autodoc.autotypeddict"
2324
]
2425

2526
intersphinx_mapping = {

docs/getting-started.rst

Lines changed: 0 additions & 30 deletions
This file was deleted.

docs/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ tastytrade: An unofficial Python SDK for Tastytrade!
55
:maxdepth: 2
66
:caption: Documentation:
77

8-
install
9-
getting-started
8+
.. include:: ../README.rst
9+
:start-after: inclusion-marker
1010

1111
.. toctree::
1212
:maxdepth: 2
13-
:caption: API Reference:
13+
:caption: SDK Reference:
1414

1515
tastytrade
1616
dxfeed

docs/install.rst

Lines changed: 0 additions & 10 deletions
This file was deleted.

docs/requirements.txt

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,3 @@
1-
#
2-
# This file is autogenerated by pip-compile with python 3.10
3-
# To update, run:
4-
#
5-
# pip-compile requirements.in
6-
#
7-
alabaster==0.7.12
8-
# via sphinx
9-
babel==2.10.3
10-
# via sphinx
11-
certifi==2022.9.14
12-
# via requests
13-
charset-normalizer==2.1.1
14-
# via requests
15-
docutils==0.17.1
16-
# via
17-
# sphinx
18-
# sphinx-rtd-theme
19-
idna==3.4
20-
# via requests
21-
imagesize==1.4.1
22-
# via sphinx
23-
jinja2==3.1.2
24-
# via sphinx
25-
markupsafe==2.1.1
26-
# via jinja2
27-
packaging==21.3
28-
# via sphinx
29-
pygments==2.13.0
30-
# via sphinx
31-
pyparsing==3.0.9
32-
# via packaging
33-
pytz==2022.2.1
34-
# via babel
35-
requests==2.28.1
36-
# via sphinx
37-
snowballstemmer==2.2.0
38-
# via sphinx
39-
sphinx==5.1.1
40-
# via
41-
# -r requirements.in
42-
# sphinx-rtd-theme
43-
sphinx-rtd-theme==1.0.0
44-
# via -r requirements.in
45-
sphinxcontrib-applehelp==1.0.2
46-
# via sphinx
47-
sphinxcontrib-devhelp==1.0.2
48-
# via sphinx
49-
sphinxcontrib-htmlhelp==2.0.0
50-
# via sphinx
51-
sphinxcontrib-jsmath==1.0.1
52-
# via sphinx
53-
sphinxcontrib-qthelp==1.0.3
54-
# via sphinx
55-
sphinxcontrib-serializinghtml==1.1.5
56-
# via sphinx
57-
urllib3==1.26.12
58-
# via requests
1+
sphinx==5.3.0
2+
sphinx-rtd-theme==1.1.1
3+
sphinx-toolbox==3.4.0

docs/tastytrade.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ Account
88
.. autoclass:: Account
99
:members:
1010

11+
.. autotypeddict:: AccountBalance
12+
13+
.. autotypeddict:: AccountBalanceSnapshot
14+
15+
.. autotypeddict:: CurrentPosition
16+
17+
.. autotypeddict:: MarginRequirement
18+
19+
.. autotypeddict:: NetLiqOhlc
20+
21+
.. autotypeddict:: PositionLimit
22+
23+
.. autotypeddict:: Transaction
24+
25+
.. autotypeddict:: TradingStatus
26+
1127
Instruments
1228
-----------
1329
.. module:: tastytrade.instruments
@@ -46,12 +62,20 @@ Metrics
4662

4763
.. autofunction:: get_earnings
4864

65+
.. autotypeddict:: MarketMetricInfo
66+
67+
.. autotypeddict:: DividendInfo
68+
69+
.. autotypeddict:: EarningsInfo
70+
4971
Search
5072
------
5173
.. module:: tastytrade.search
5274

5375
.. autofunction:: symbol_search
5476

77+
.. autotypeddict:: SymbolData
78+
5579
Session
5680
-------
5781
.. module:: tastytrade.session
@@ -85,6 +109,10 @@ Utils
85109

86110
.. autofunction:: get_third_friday
87111

112+
.. autofunction:: snakeify
113+
114+
.. autofunction:: desnakeify
115+
88116
Watchlists
89117
----------
90118

requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ requests==2.26.0
44
mypy==0.931
55
flake8==3.9.2
66
isort==5.8.0
7-
sphinx==5.3.0
8-
sphinx_rtd_theme==1.0.0
97
types-requests==2.28.10
108
websockets==11.0.3

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
url='https://github.com/tastyware/tastytrade',
1919
license='Apache',
2020
install_requires=[
21-
'aiohttp<4',
2221
'requests<3',
2322
'tastyworks-aiocometd>=1.0',
24-
'dataclasses'
23+
'dataclasses',
24+
'websockets>=11.0.3'
2525
],
2626
packages=find_packages(exclude=['ez_setup', 'tests*']),
2727
include_package_data=True,

0 commit comments

Comments
 (0)