tastytrade.paper

class tastytrade.paper.PaperAlertStreamer(**kwargs)

Bases: AlertStreamer

Currently only supports listening to orders.

class tastytrade.paper.PaperSession(api_key: str | None, **client_kwargs: Any)

Bases: Session

Contains a session which can be used to interact with the paper trading API. Note these sessions are only valid for endpoints in the Account class.

Parameters:
api_key: str | None

tastyware paper API key, buy one at https://tastyware.dev/login defaults to the $TW_API_KEY environment variable

async create_account(name: str, margin_or_cash: 'Cash' | 'Margin' = 'Margin', initial_deposit: int = 100000) Account

Create a new paper trading account with the given configuration.

Parameters:
name: str

name for the account

margin_or_cash: 'Cash' | 'Margin' = 'Margin'

whether the account should be margin or cash

initial_deposit: int = 100000

the initial balance for the new account

async delete_account(account: Account) None

Delete the given paper trading account along with its orders, transactions, etc.

Parameters:
account: Account

account to delete

async deposit(account: Account, amount: Decimal) None

Deposit the given quantity of fake dollars into the paper trading account. Use with a negative number for withdrawals.

Parameters:
account: Account

account to deposit into

amount: Decimal

amount of money to deposit/withdraw

temporary_account(margin_or_cash: 'Cash' | 'Margin' = 'Margin') AsyncGenerator[Account, None]

Create an account for temporary use that will be cleaned up when exiting the context manager. Useful for unit testing.

Parameters:
margin_or_cash: 'Cash' | 'Margin' = 'Margin'

whether the account should be margin or cash