You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/CONTRIBUTING.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,6 @@ Since Tastytrade certification sessions are severely limited in capabilities, th
5
5
## Steps to follow to contribute
6
6
7
7
1. Fork the repository to your personal Github account and make your proposed changes.
8
-
2. Export your username, password, and account number to the following Github Actions repository secrets: `TT_USERNAME`, `TT_PASSWORD`, and `TT_ACCOUNT`. The account should be a margin account.
8
+
2. Export your username, password, and account number to the following Github Actions repository secrets: `TT_SECRET`, `TT_REFRESH`, and `TT_ACCOUNT`. The account should be a margin account.
9
9
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.
10
10
4. Run `make install` to create the virtual environment, `make lint` to format your code, and `make test` to run the tests locally.
Copy file name to clipboardExpand all lines: .github/pull_request_template.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ Fixes ...
6
6
## Pre-merge checklist
7
7
-[ ] Code formatted correctly (check with `make lint`)
8
8
-[ ] Code implemented for both sync and async
9
-
-[ ] Passing tests locally (check with `make test`, make sure you have `TT_USERNAME`, `TT_PASSWORD`, and `TT_ACCOUNT` environment variables set)
9
+
-[ ] Passing tests locally (check with `make test`, make sure you have `TT_REFRESH`, `TT_SECRET`, and `TT_ACCOUNT` environment variables set)
10
10
-[ ] New tests added (if applicable)
11
11
12
12
Please note that, in order to pass the tests, you'll need to set up your Tastytrade credentials as repository secrets on your local fork. Read more at CONTRIBUTING.md.
A session object is required to authenticate your requests to the Tastytrade API.
8
-
To create a production (real) session using your normal login:
7
+
A session object is required to authenticate your requests to the Tastytrade API. Tastytrade uses OAuth logins, which allow you to connect applications (third-party or private) to your trading account to use the API.
9
8
10
-
.. code-block:: python
9
+
To get started, create a new OAuth application `here <https://my.tastytrade.com/app.html#/manage/api-access/oauth-applications>`_. Check all the scopes you plan to use, then create the application. **Save the client secret**, then go to OAuth Applications > Manage > Create Grant to create a new grant with the same scopes. This will give you a refresh token, **which you should also save**.
11
10
12
-
from tastytrade import Session
13
-
session = Session('username', 'password')
11
+
At this point, OAuth is now setup correctly! Doing the above once is sufficient for **indefinite usage** of ``Session`` for authentication to the API, since refresh tokens never expire. From now on you can simply authenticate with your client secret and refresh token.
14
12
15
-
A certification (test) account can be created `here <https://developer.tastytrade.com/sandbox/>`_, then used to create a session.
If you used a certification (test) account to create the session associated with the `remember_token`, you must set `is_test=True` when creating subsequent sessions.
33
-
34
-
OAuth sessions
35
-
--------------
36
-
37
-
Tastytrade has recently added support for OAuth logins, which allow you to connect an application for the purposes of managing trades on your behalf. Apart from allowing you to connect to 3rd-party apps (or build your own), you can also build a private OAuth application, which provides better security compared to username/password authentication since you don't have to expose your login information.
38
-
39
-
To get started, create a new OAuth application `here <https://my.tastytrade.com/app.html#/manage/api-access/oauth-applications>`_. You'll need to check all the scopes and save the client ID and client secret. Then, run this code:
40
19
41
-
.. code-block:: python
42
-
43
-
from tastytrade.oauth import login
44
-
45
-
login()
46
-
47
-
This will open up a web interface in your browser where you'll be prompted to paste your client ID and client secret. These credentials will then be used to connect your application to Tastytrade. After following the steps in your browser, you should see your refresh token in the browser and in the console, which you should save.
48
-
49
-
At this point, OAuth is now setup correctly! Doing the above once is sufficient for **indefinite usage** of ``OAuthSession`` for authentication to the API, since refresh tokens never expire. From now on you can simply authenticate like so:
These session objects can be used almost anywhere you can use a normal session:
22
+
These session objects can be used to make API requests:
58
23
59
24
.. code-block:: python
60
25
61
26
from tastytrade import Account
62
27
63
28
accounts = Account.get(session)
64
29
65
-
Note that OAuth sessions make API requests using a special session token, which has a duration of only 15 minutes. However, since the refresh tokens last forever, you can call ``OAuthSession.refresh()`` to refresh the session token whenever needed. The session object will keep track of session expiration time for you to make it easier to know when to refresh:
30
+
Note that OAuth sessions make API requests using a special session token, which has a duration of only 15 minutes. However, since the refresh tokens last forever, you can call ``Session.refresh()`` to refresh the session token whenever needed. The session object will keep track of session expiration time for you to make it easier to know when to refresh:
66
31
67
32
.. code-block:: python
68
33
@@ -71,3 +36,10 @@ Note that OAuth sessions make API requests using a special session token, which
71
36
if now_in_new_york() > session.session_expiration:
72
37
session.refresh()
73
38
print(Account.get(session))
39
+
40
+
A sandbox account for testing can be created `here <https://developer.tastytrade.com/sandbox/>`_, then used to create a session in the same way:
0 commit comments