tastytrade.paper

class tastytrade.paper.PaperAlertStreamer(session: PaperSession)

Bases: AlertStreamer

Designed to mimic the behavior and API of tastytrade.AlertStreamer. Currently only supports listening to orders.

fail() None

Raise an exception in the streamer that can be used to test retries.

class tastytrade.paper.PaperSession(api_key: str, **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

user’s paper API key, buy one at https://tastyware.dev/login

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 automated testing.

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

whether the account should be margin or cash