Skip to content

Commit

Permalink
Add sync/async functionality for all requests (#168)
Browse files Browse the repository at this point in the history
* add async

* add async tests

* add docs, fix a couple tests

* lint

* use py3.8
  • Loading branch information
Graeme22 authored Oct 9, 2024
1 parent f3c2c14 commit 0e93f55
Show file tree
Hide file tree
Showing 30 changed files with 2,178 additions and 431 deletions.
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Since Tastytrade certification sessions are severely limited in capabilities, th
## Steps to follow to contribute

1. Fork the repository to your personal Github account and make your proposed changes.
2. Export your username, password, and account number to the following environment variables: `TT_USERNAME`, `TT_PASSWORD`, and `TT_ACCOUNT`.
3. Make sure you have at least one share of long $F in your account, which will be used to place the OCO complex order (nothing will fill).
2. Export your username, password, and account number to the following environment variables: `TT_USERNAME`, `TT_PASSWORD`, and `TT_ACCOUNT`. The account should be a margin account.
3. Make sure you have at least one share of long $F in your account, which will be used to place the OCO complex order (nothing will fill), as well as at least $2 of buying power.
4. Run `make install` to create the virtual environment, then `make lint` and `make test` to run the tests locally.
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Fixes ...

## Pre-merge checklist
- [ ] Code formatted correctly with `uv run ruff format .`
- [ ] Code implemented for both sync and async
- [ ] Passing tests locally
- [ ] New tests added (if applicable)

Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.12
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: '3.12'
python-version: '3.8'
- uses: yezz123/setup-uv@v4
- name: Setup uv venv
run: |
uv sync
uv pip install .
- name: Lint with ruff
run: |
uv run ruff check tastytrade/
uv run ruff check tests/
uv run ruff check .
- name: Type check with mypy
run: |
uv run mypy -p tastytrade
Expand All @@ -34,3 +32,4 @@ jobs:
env:
TT_USERNAME: ${{ secrets.TT_USERNAME }}
TT_PASSWORD: ${{ secrets.TT_PASSWORD }}
TT_ACCOUNT: ${{ secrets.TT_ACCOUNT }}
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

install:
uv sync
uv pip install -e .

lint:
uv run ruff check .
uv run ruff format .
uv run ruff check --fix .
uv run mypy -p tastytrade
uv run mypy -p tests

test:
uv run pytest --cov=tastytrade --cov-report=term-missing tests/ --cov-fail-under=95

docs:
cd docs; make html
cd docs; uv pip install -r requirements.txt; make html
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Tastytrade Python SDK

A simple, reverse-engineered SDK for Tastytrade built on their (now mostly public) API. This will allow you to create trading algorithms for whatever strategies you may have quickly and painlessly in Python.
A simple, reverse-engineered, sync/async SDK for Tastytrade built on their (now mostly public) API. This will allow you to create trading algorithms for whatever strategies you may have quickly and painlessly in Python.

> [!NOTE]
> Want to see the SDK in action? Check out [tastytrade-cli](https://github.com/tastyware/tastytrade-cli), a CLI for Tastytrade that showcases many of the SDK's features.
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
project = "tastytrade"
copyright = "2024, Graeme Holliday"
author = "Graeme Holliday"
release = "8.5"
release = "9.0"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Tastytrade Python SDK
=====================

A simple, reverse-engineered SDK for Tastytrade built on their (now mostly public) API. This will allow you to create trading algorithms for whatever strategies you may have quickly and painlessly in Python.
A simple, reverse-engineered, sync/async SDK for Tastytrade built on their (now mostly public) API. This will allow you to create trading algorithms for whatever strategies you may have quickly and painlessly in Python.

.. tip::
Want to see the SDK in action? Check out `tastytrade-cli <https://github.com/tastyware/tastytrade-cli>`_, a CLI for Tastytrade that showcases many of the SDK's features.
Expand All @@ -24,6 +24,7 @@ A simple, reverse-engineered SDK for Tastytrade built on their (now mostly publi

installation
sessions
sync-async
accounts
instruments
orders
Expand Down
27 changes: 27 additions & 0 deletions docs/sync-async.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
sync/async
==========

After creating a session (which is always initialized synchronously), the rest of the API endpoints implemented in the SDK have both sync and async implementations as of version 9.0.

Let's see how this looks:

.. code-block:: python
from tastytrade Account, Session
session = Session(username, password)
# using sync implementation
accounts = Account.get_accounts(session)
The async implementation is similar:

.. code-block:: python
from tastytrade Account, Session
session = Session(username, password)
# using async implementation
accounts = await Account.a_get_accounts(session)
That's it! All sync methods have a parallel async method that starts with `a_`.

.. note::
Please note that two modules, `tastytrade.backtest` and `tastytrade.streamer`, only have async implementations. But for everything else, you can use what you'd like!
13 changes: 5 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ build-backend = "hatchling.build"

[project]
name = "tastytrade"
version = "8.5"
description = "An unofficial SDK for Tastytrade!"
version = "9.0"
description = "An unofficial, sync/async SDK for Tastytrade!"
readme = "README.md"
requires-python = ">=3.8"
license = {file = "LICENSE"}
authors = [
{name = "Graeme Holliday", email = "[email protected]"},
]

dependencies = [
"fake-useragent>=1.5.1",
"httpx>=0.27.2",
"pandas-market-calendars>=4.4.1",
"pydantic>=2.9.2",
Expand All @@ -29,11 +27,10 @@ Documentation = "https://tastyworks-api.readthedocs.io/en/latest"
dev-dependencies = [
"mypy>=1.11.2",
"pytest>=8.3.3",
"pytest-asyncio>=0.24.0",
"pytest-aio>=1.5.0",
"pytest-cov>=5.0.0",
"ruff>=0.6.7",
"types-pytz>=2024.2.0.20240913",
"types-requests>=2.32.0.20240914",
"ruff>=0.6.9",
"types-pytz>=2024.2.0.20241003",
]

[tool.setuptools.package-data]
Expand Down
2 changes: 1 addition & 1 deletion tastytrade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
API_URL = "https://api.tastyworks.com"
BACKTEST_URL = "https://backtester.vast.tastyworks.com"
CERT_URL = "https://api.cert.tastyworks.com"
VERSION = "8.5"
VERSION = "9.0"

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
Expand Down
Loading

0 comments on commit 0e93f55

Please sign in to comment.