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

Prepare v8.1: use httpx Session, prepare for async version, combine Production and Certification sessions #158

Merged
merged 4 commits into from
Jul 29, 2024
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
15 changes: 5 additions & 10 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
# Contributions

Since Tastytrade certification sessions are severely limited in capabilities, the test suite for this SDK requires the usage of your own Tastytrade credentials. In order to pass the tests, you'll need to set up your Tastytrade credentials as repository secrets on your local fork.

Secrets are protected by Github and are not visible to anyone. You can read more about repository secrets [here](https://docs.github.com/en/actions/reference/encrypted-secrets).
Since Tastytrade certification sessions are severely limited in capabilities, the test suite for this SDK requires the usage of your own Tastytrade credentials. In order to pass the tests, you'll need to set use your Tastytrade credentials to run the tests on your local fork.

## Steps to follow to contribute

1. Fork the repository to your personal Github account, NOT to an organization where others may be able to indirectly access your secrets.
2. Make your changes on the forked repository.
3. Go to the "Actions" page on the forked repository and enable actions.
4. Navigate to the forked repository's settings page and click on "Secrets and variables" > "Actions".
5. Click on "New repository secret" to add your Tastytrade username named `TT_USERNAME`.
6. Finally, do the same with your password, naming it `TT_PASSWORD`.
7. 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).
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).
4. Run `make venv` to create the virtual environment, then `make test` to run the tests locally.
4 changes: 2 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Python application

on:
push:
branches: [ master, advanced-streamer ]
branches: [ master ]
pull_request:
branches: [ master, advanced-streamer ]
branches: [ master ]

jobs:
build:
Expand Down
24 changes: 10 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
.PHONY: clean venv test install docs

clean:
find . -name '*.py[co]' -delete
.PHONY: venv lint test docs

venv:
python -m venv env
env/bin/pip install -r requirements.txt
python -m venv .venv
.venv/bin/pip install -r requirements.txt
.venv/bin/pip install -e .
.venv/bin/pip install -r docs/requirements.txt

lint:
isort --check --diff tastytrade/ tests/
flake8 --count --show-source --statistics tastytrade/ tests/
mypy -p tastytrade
mypy -p tests
.venv/bin/isort --check --diff tastytrade/ tests/
.venv/bin/flake8 --count --show-source --statistics tastytrade/ tests/
.venv/bin/mypy -p tastytrade
.venv/bin/mypy -p tests

test:
python -m pytest --cov=tastytrade --cov-report=term-missing tests/ --cov-fail-under=95

install:
env/bin/pip install -e .
.venv/bin/pytest --cov=tastytrade --cov-report=term-missing tests/ --cov-fail-under=95

docs:
cd docs; make html
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ A session object is required to authenticate your requests to the Tastytrade API
You can create a real session using your normal login, or a certification (test) session using your certification login.

```python
from tastytrade import ProductionSession
session = ProductionSession('username', 'password')
from tastytrade import Session
session = Session('username', 'password')
```

## Using the streamer
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
project = 'tastytrade'
copyright = '2024, Graeme Holliday'
author = 'Graeme Holliday'
release = '7.9'
release = '8.1'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
12 changes: 6 additions & 6 deletions docs/sessions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ To create a production (real) session using your normal login:

.. code-block:: python

from tastytrade import ProductionSession
session = ProductionSession('username', 'password')
from tastytrade import Session
session = Session('username', 'password')

A certification (test) account can be created `here <https://developer.tastytrade.com/sandbox/>`_, then used to create a session:

.. code-block:: python

from tastytrade import CertificationSession
session = CertificationSession('username', 'password')
from tastytrade import Session
session = Session('username', 'password', is_test=True)

You can make a session persistent by generating a remember token, which is valid for 24 hours:

.. code-block:: python

session = ProductionSession('username', 'password', remember_me=True)
session = Session('username', 'password', remember_me=True)
remember_token = session.remember_token
# remember token replaces the password for the next login
new_session = ProductionSession('username', remember_token=remember_token)
new_session = Session('username', remember_token=remember_token)
4 changes: 2 additions & 2 deletions docs/watchlists.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ To use watchlists you'll need a production session:

.. code-block:: python

from tastytrade import ProductionSession
session = ProductionSession(user, password)
from tastytrade import Session
session = Session(user, password)

Now we can fetch the watchlist:

Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
requests==2.32.1
httpx==0.27.0
mypy==1.10.0
flake8==7.0.0
isort==5.13.2
types-requests==2.31.0.20240406
types-pytz==2024.1.0.20240417
websockets==12.0
pandas_market_calendars==4.3.3
pydantic==2.7.1
pytest==8.2.1
pytest_cov==5.0.0
pytest-asyncio==0.23.7
fake-useragent==1.5.1
fake-useragent==1.5.1
numpy<2
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='tastytrade',
version='7.9',
version='8.1',
description='An unofficial SDK for Tastytrade!',
long_description=LONG_DESCRIPTION,
long_description_content_type='text/markdown',
Expand All @@ -16,7 +16,7 @@
url='https://github.com/tastyware/tastytrade',
license='MIT',
install_requires=[
'requests<3',
'httpx>=0.27.0',
'websockets>=11.0.3',
'pydantic>=2.6.3',
'pandas_market_calendars>=4.3.3',
Expand Down
72 changes: 63 additions & 9 deletions tastytrade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,78 @@

API_URL = 'https://api.tastyworks.com'
CERT_URL = 'https://api.cert.tastyworks.com'
VERSION = '7.9'
VERSION = '8.1'

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

from .account import Account # noqa: E402
from .search import symbol_search # noqa: E402
from .session import CertificationSession, ProductionSession # noqa: E402
from .streamer import AlertStreamer, DXLinkStreamer # noqa: E402
from .watchlists import PairsWatchlist, Watchlist # noqa: E402
# flake8: noqa

from .account import Account
from .instruments import (Cryptocurrency, Equity, Future, FutureOption,
FutureOptionProduct, FutureProduct,
NestedFutureOptionChain, NestedOptionChain, Option,
OptionType, Warrant, get_future_option_chain,
get_option_chain, get_quantity_decimal_precisions)
from .metrics import (get_dividends, get_earnings, get_market_metrics,
get_risk_free_rate)
from .order import (ComplexOrderType, InstrumentType, NewComplexOrder,
NewOrder, OrderAction, OrderStatus, OrderTimeInForce,
OrderType, PriceEffect)
from .search import symbol_search
from .session import Session
from .streamer import AlertStreamer, AlertType, DXLinkStreamer
from .utils import (get_future_fx_monthly, get_future_grain_monthly,
get_future_index_monthly, get_future_metal_monthly,
get_future_oil_monthly, get_future_treasury_monthly,
get_tasty_monthly, get_third_friday, now_in_new_york,
today_in_new_york)
from .watchlists import PairsWatchlist, Watchlist

__all__ = [
'Account',
'AlertStreamer',
'CertificationSession',
'AlertType',
'ComplexOrderType',
'Cryptocurrency',
'DXLinkStreamer',
'Equity',
'Future',
'FutureOption',
'FutureOptionProduct',
'FutureProduct',
'InstrumentType',
'NestedFutureOptionChain',
'NestedOptionChain',
'NewComplexOrder',
'NewOrder',
'Option',
'OptionType',
'OrderAction',
'OrderStatus',
'OrderTimeInForce',
'OrderType',
'PairsWatchlist',
'ProductionSession',
'PriceEffect',
'Session',
'Warrant',
'Watchlist',
'symbol_search'
'get_dividends',
'get_earnings',
'get_future_fx_monthly',
'get_future_grain_monthly',
'get_future_index_monthly',
'get_future_metal_monthly',
'get_future_oil_monthly',
'get_future_option_chain',
'get_future_treasury_monthly',
'get_market_metrics',
'get_option_chain',
'get_quantity_decimal_precisions',
'get_risk_free_rate',
'get_tasty_monthly',
'get_third_friday',
'now_in_new_york',
'symbol_search',
'today_in_new_york'
]
Loading
Loading