Skip to content

Commit d07d995

Browse files
authored
Merge pull request #4 from tastyware/rewrite
code reorg, more docs
2 parents a41272e + 157ceee commit d07d995

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+936
-1341
lines changed

.github/workflows/python-app.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ jobs:
2222
python -m pip install --upgrade pip
2323
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
2424
- name: Sorting...
25-
run: isort --check --diff tastyworks/ tests/
25+
run: isort --check --diff tastytrade/
2626
- name: Linting...
27-
run: flake8 --count --show-source --statistics --ignore=E501 tastyworks/ tests/
27+
run: flake8 --count --show-source --statistics --ignore=E501 tastytrade/
2828
- name: Type checking...
29-
run: mypy -p tastyworks
30-
- name: Testing...
31-
run: python -m pytest --cov=src --cov-report=term-missing tests/
29+
run: mypy -p tastytrade

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ venv:
88
env/bin/pip install -r requirements.txt
99

1010
test:
11-
isort --check --diff tastyworks/ tests/
12-
flake8 --count --show-source --statistics --ignore=E501 tastyworks/ tests/
13-
mypy -p tastyworks
14-
python -m pytest --cov=tastyworks --cov-report=term-missing tests/
11+
isort --check --diff tastytrade/
12+
flake8 --count --show-source --statistics --ignore=E501 tastytrade/
13+
mypy -p tastytrade
1514

1615
install:
1716
env/bin/pip install -e .

README.md

Lines changed: 8 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,17 @@
1-
[![PyPI version](https://badge.fury.io/py/tastyworks-api.svg)](https://badge.fury.io/py/tastyworks-api)
2-
[![Downloads](https://pepy.tech/badge/tastyworks-api)](https://pepy.tech/project/tastyworks-api)
3-
[![Docs](https://readthedocs.org/projects/tastyworks-api/badge/?version=latest)](https://tastyworks-api.readthedocs.io/en/latest/?badge=latest)
1+
[![PyPI version](https://badge.fury.io/py/tastytrade.svg)](https://badge.fury.io/py/tastytrade)
2+
[![Downloads](https://pepy.tech/badge/tastytrade)](https://pepy.tech/project/tastytrade)
3+
[![Docs](https://readthedocs.org/projects/tastytrade/badge/?version=latest)](https://tastytrade.readthedocs.io/en/latest/?badge=latest)
44

5-
# Tastyworks API (unofficial)
5+
# Tastytrade API (unofficial)
66

7-
A simple, async-based, reverse-engineered API for tastyworks. This will allow you to create trading algorithms for whatever strategies you may have.
8-
9-
Please note that this is in the very early stages of development so any and all contributions are welcome. Please submit an issue and/or a pull request.
10-
11-
This is a fork with modified and added features. You can find the original (unmaintained) GitHub repo at: https://github.com/boyan-soubachov/tastyworks_api
7+
A simple, async-based, reverse-engineered API for tastytrade. This will allow you to create trading algorithms for whatever strategies you may have.
128

139
## Installation
14-
```
15-
$ pip install tastyworks-api
16-
```
17-
18-
## Usage
19-
20-
Here's a simple example which showcases many different aspects of the API:
21-
22-
```python
23-
import asyncio
24-
from datetime import date
25-
from decimal import Decimal as D
26-
27-
from tastyworks.models import option_chain, underlying
28-
from tastyworks.models.greeks import Greeks
29-
from tastyworks.models.option import Option, OptionType
30-
from tastyworks.models.order import (Order, OrderDetails, OrderPriceEffect,
31-
OrderType)
32-
from tastyworks.models.session import TastyAPISession
33-
from tastyworks.models.trading_account import TradingAccount
34-
from tastyworks.models.underlying import UnderlyingType
35-
from tastyworks.streamer import DataStreamer
36-
from tastyworks.tastyworks_api import tasty_session
37-
from tastyworks.utils import get_third_friday
38-
39-
40-
async def main_loop(session: TastyAPISession, streamer: DataStreamer):
41-
accounts = await TradingAccount.get_remote_accounts(session)
42-
acct = accounts[0]
43-
print(f'Accounts available: {accounts}')
44-
45-
orders = await Order.get_remote_orders(session, acct)
46-
print(f'Number of active orders: {len(orders)}')
47-
48-
# Execute an order
49-
details = OrderDetails(
50-
type=OrderType.LIMIT,
51-
price=D(400),
52-
price_effect=OrderPriceEffect.CREDIT)
53-
new_order = Order(details)
54-
55-
opt = Option(
56-
ticker='AKS',
57-
quantity=1,
58-
expiry=get_third_friday(date.today()),
59-
strike=D(3),
60-
option_type=OptionType.CALL,
61-
underlying_type=UnderlyingType.EQUITY
62-
)
63-
new_order.add_leg(opt)
64-
65-
res = await acct.execute_order(new_order, session, dry_run=True)
66-
print(f'Order executed successfully: {res}')
67-
68-
# Get an options chain
69-
undl = underlying.Underlying('AKS')
7010

71-
chain = await option_chain.get_option_chain(session, undl)
72-
print(f'Chain strikes: {chain.get_all_strikes()}')
73-
74-
# Get all expirations for the options for the above equity symbol
75-
exp = chain.get_all_expirations()
76-
77-
# Choose the next expiration as an example & fetch the entire options chain for that expiration (all strikes)
78-
next_exp = exp[0]
79-
chain_next_exp = await option_chain.get_option_chain(session, undl, next_exp)
80-
options = []
81-
for option in chain_next_exp.options:
82-
options.append(option)
83-
84-
# Get the greeks data for all option symbols via the streamer by subscribing
85-
options_symbols = [options[x].symbol_dxf for x in range(len(options))]
86-
greeks_data = await streamer.stream('Greeks', options_symbols)
87-
88-
for data in greeks_data:
89-
gd = Greeks().from_streamer_dict(data)
90-
# gd = Greeks(kwargs=data)
91-
idx_match = [options[x].symbol_dxf for x in range(len(options))].index(gd.symbol)
92-
options[idx_match].greeks = gd
93-
print('> Symbol: {}\tPrice: {}\tDelta {}'.format(gd.symbol, gd.price, gd.delta))
94-
95-
96-
quote = await streamer.stream('Quote', sub_values)
97-
print(f'Received item: {quote}')
98-
99-
await streamer.close()
100-
101-
102-
if __name__ == '__main__':
103-
tasty_client = tasty_session.create_new_session('foo', 'bar')
104-
streamer = DataStreamer(tasty_client)
105-
loop = asyncio.get_event_loop()
106-
107-
try:
108-
loop.run_until_complete(main_loop(tasty_client, streamer))
109-
except Exception:
110-
print('Exception in main loop')
111-
finally:
112-
# find all futures/tasks still running and wait for them to finish
113-
pending_tasks = [
114-
task for task in asyncio.Task.all_tasks() if not task.done()
115-
]
116-
loop.run_until_complete(asyncio.gather(*pending_tasks))
117-
loop.close()
11811
```
119-
120-
## Guidelines and caveats
121-
122-
There are a few useful things to know which will help you get the most out of this API and use it in the way it was intended.
123-
124-
1. All objects are designed to be independent of each other in their _steady-state_. That is, unless executing an action, all objects are not bound to each other and have no knowledge of each other's awareness.
125-
1. One can have multiple sessions and, due to the inter-object independence, can execute identical actions on identical objects in different sessions.
126-
1. Given the above points, this API *does not* implement state management and synchronization (i.e. are my local object representations identical to the remote [Tastyworks] ones?). This is not an indefinitely closed matter and may be re-evaluated if the need arises.
12+
$ pip install tastytrade
13+
```
12714

12815
## Disclaimer
12916

130-
This is an unofficial, reverse-engineered API for Tastyworks. There is no implied warranty for any actions and results which arise from using it.
131-
The only guarantee I make is that you will lose all your money if you use this API.
17+
This is an unofficial, reverse-engineered API for Tastytrade. There is no implied warranty for any actions and results which arise from using it.

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
# -- Project information -----------------------------------------------------
77
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
88

9-
project = 'tastyworks-api'
10-
copyright = '2022, Graeme Holliday'
9+
project = 'tastytrade'
10+
copyright = '2023, Graeme Holliday'
1111
author = 'Graeme Holliday'
12-
release = '4.4.0'
12+
release = '1.0'
1313

1414
# -- General configuration ---------------------------------------------------
1515
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

docs/dough.rst

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

docs/dxfeed.rst

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,64 @@
1-
dxfeed
2-
======
1+
tastytrade.dxfeed
2+
=================
33

4-
Mapped Item
5-
-----------
4+
For general dxfeed symbology, go to `Formats <https://kb.dxfeed.com/en/data-model/symbology-guide/general-provisions.html#formats-60641>`_, where you'll find information on various kinds of formatting.
65

7-
.. module:: tastyworks.dxfeed.mapped_item
6+
For options on futures symbology, go to `CME Group <https://cmegroup.com/>`_ and look at the 'Specs' section for the given futures symbol.
87

9-
.. autoclass:: MappedItem
10-
:members:
8+
If you want to double-check you typed the symbol right, or want to troubleshoot a hanging request, go to `dxfeed Symbol Lookup <https://symbol-lookup.dxfeed.com/>`_ and type in the same symbol.
119

12-
Mapper
13-
------
10+
Event
11+
-----
1412

15-
.. module:: tastyworks.dxfeed.mapper
13+
.. module:: tastytrade.dxfeed.event
1614

17-
.. autofunction:: map_message
15+
.. autoclass:: Event
16+
:members:
1817

1918
Greeks
2019
------
2120

22-
.. module:: tastyworks.dxfeed.greeks
21+
.. module:: tastytrade.dxfeed.greeks
2322

2423
.. autoclass:: Greeks
2524
:members:
2625

2726
Profile
2827
-------
2928

30-
.. module:: tastyworks.dxfeed.profile
29+
.. module:: tastytrade.dxfeed.profile
3130

3231
.. autoclass:: Profile
3332
:members:
3433

3534
Quote
3635
-----
3736

38-
.. module:: tastyworks.dxfeed.quote
37+
.. module:: tastytrade.dxfeed.quote
3938

4039
.. autoclass:: Quote
4140
:members:
4241

4342
Summary
4443
-------
4544

46-
.. module:: tastyworks.dxfeed.summary
45+
.. module:: tastytrade.dxfeed.summary
4746

4847
.. autoclass:: Summary
4948
:members:
5049

50+
TheoPrice
51+
---------
52+
53+
.. module:: tastytrade.dxfeed.theoprice
54+
55+
.. autoclass:: TheoPrice
56+
:members:
57+
5158
Trade
52-
------
59+
-----
5360

54-
.. module:: tastyworks.dxfeed.trade
61+
.. module:: tastytrade.dxfeed.trade
5562

5663
.. autoclass:: Trade
5764
:members:

docs/index.rst

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,18 @@
1-
tastyworks-api: A simple, async-based, reverse-engineered API for Tastyworks
2-
============================================================================
1+
tastytrade: A reverse-engineered Python API for Tastytrade
2+
==========================================================
33

44
.. toctree::
55
:maxdepth: 2
6-
:caption: Contents:
6+
:caption: Documentation:
77

8-
dough
9-
dxfeed
10-
models
11-
tastyworks_api
12-
13-
Utilities
14-
---------
15-
16-
.. module:: tastyworks.utils
17-
18-
.. autofunction:: get_third_friday
8+
install
199

20-
Streamer
21-
--------
22-
.. module:: tastyworks.streamer
23-
24-
.. autoclass:: DataStreamer
25-
:members:
10+
.. toctree::
11+
:maxdepth: 2
12+
:caption: API Reference:
2613

27-
.. autoclass:: AuthExtension
28-
:members:
14+
tastytrade
15+
dxfeed
2916

3017
Indices and tables
3118
==================

docs/install.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Installation
2+
============
3+
4+
pip
5+
---
6+
7+
:: pip install tastytrade

0 commit comments

Comments
 (0)