-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
684 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,44 @@ | ||
[](https://tradestation.readthedocs.io/en/latest/?badge=latest) | ||
[](https://pypi.org/project/tradestation) | ||
[](https://pepy.tech/project/tradestation) | ||
[](https://github.com/tastyware/tradestation/releases) | ||
|
||
# tradestation | ||
An unofficial Python SDK for Tradestation! | ||
A simple, unofficial, sync/async SDK for Tradestation built on their public API. This will allow you to create trading algorithms for whatever strategies you may have quickly and painlessly in Python. | ||
|
||
## Features | ||
|
||
- Up to 10x less code than using the API directly | ||
- Sync/async functions for all endpoints | ||
- Powerful websocket implementation for account alerts and data streaming, with support for auto-reconnection and reconnection callbacks | ||
- 100% typed, with Pydantic models for all JSON responses from the API | ||
- 95%+ unit test coverage | ||
- Comprehensive documentation | ||
- Utility functions for timezone calculations, futures monthly expiration dates, and more | ||
|
||
## Installation | ||
|
||
```console | ||
$ pip install tradestation | ||
``` | ||
|
||
## Initial setup | ||
|
||
Tradestation uses OAuth for secure authentication to the API. In order to obtain access tokens, you need to authenticate with OAuth 2's authorization code flow, which requires a local HTTP server running to handle the callback. Fortunately, the SDK makes doing this easy: | ||
|
||
```python | ||
from tradestation.oauth import login | ||
login() | ||
``` | ||
|
||
This will let you authenticate in your local browser. Fortunately, this only needs to be done once, as afterwards you can use the refresh token to obtain new access tokens indefinitely. | ||
|
||
## Creating a session | ||
|
||
A session object is required to authenticate your requests to the Tradestation API. | ||
You can create a simulation session by passing `is_test=True`. | ||
|
||
```python | ||
from tradestation import Session | ||
session = Session('api_key', 'secret_key', 'refresh_token') | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ authors = [ | |
dependencies = [ | ||
"httpx>=0.27.2", | ||
"pydantic>=2.9.2", | ||
"pyjwt>=2.10.1", | ||
] | ||
|
||
[project.urls] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
import os | ||
|
||
from tradestation.session import Session | ||
|
||
|
||
def test_session(): | ||
session = Session() | ||
assert session is not None | ||
|
||
api_key = os.getenv("TS_API_KEY") | ||
secret_key = os.getenv("TS_SECRET_KEY") | ||
refresh_token = os.getenv("TS_REFRESH") | ||
assert api_key is not None | ||
assert secret_key is not None | ||
assert refresh_token is not None | ||
session = Session(api_key, secret_key, refresh_token) | ||
assert session.user_info != {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from pydantic import Field | ||
|
||
from tradestation.utils import TradestationModel | ||
|
||
|
||
class AccountDetail(TradestationModel): | ||
day_trading_qualified: bool | ||
enrolled_in_reg_t_program: bool | ||
is_stock_locate_eligible: bool | ||
option_approval_level: int | ||
pattern_day_trader: bool | ||
requires_buying_power_warning: bool | ||
|
||
|
||
class Account(TradestationModel): | ||
account_detail: AccountDetail | None = None | ||
account_id: str = Field(alias="AccountID") | ||
account_type: str | ||
alias: str | None = None | ||
alt_id: str | None = Field(default=None, alias="AltID") | ||
currency: str | ||
status: str |
Oops, something went wrong.