PyPI GitHub Discussions GitHub issues

Getting Started

Before using this SDK, ensure that you:

Install

pip install tastytrade-sdk

Use It

from tastytrade_sdk import Tastytrade

tasty = Tastytrade()

tasty.login(
    login='trader@email.com',
    password='password'
)

tasty.api.post('/sessions/validate')

tasty.logout()

Examples

Streaming Market Data

from tastytrade_sdk import Tastytrade

tasty = Tastytrade().login(login='trader@email.com', password='password')

# Subscribing to symbols across different instrument types
# Please note: The option symbols here are expired. You need to subscribe to an unexpired symbol to receive quote data
symbols = [
    'BTC/USD',
    'SPY',
    '/ESU3',
    'SPY   230630C00255000',
    './ESU3 EW2N3 230714C4310'
]

subscription = tasty.market_data.subscribe(
    symbols=symbols,
    on_quote=print,
    on_candle=print,
    on_greeks=print
)

# start streaming
subscription.open()

API Reference

class Tastytrade:

The SDK's top-level class

Tastytrade(api_base_url: str = 'api.tastytrade.com')
Parameters
  • api_base_url: Optionally override the base URL used by the API (when using the sandbox environment, for e.g.)
def login(self, login: str, password: str) -> tastytrade_sdk.Tastytrade:

Initialize a logged-in session

def logout(self) -> None:

End the session

Access the MarketData submodule

Access the Api submodule

class MarketData:

Submodule for streaming market data

def subscribe( self, symbols: List[str], on_candle: Callable[[dict], NoneType] = None, on_greeks: Callable[[dict], NoneType] = None, on_quote: Callable[[dict], NoneType] = None, aggregation_period: Optional[float] = None, event_fields: Optional[dict[str, list[str]]] = None, **kwargs) -> tastytrade_sdk.Subscription:

Subscribe to live feed data

Parameters
  • symbols: Symbols to subscribe to. Can be across multiple instrument types.
  • on_candle: Handler for candle events
  • on_greeks: Handler for greeks events
  • on_quote: Handler for quote events
  • aggregation_period: Desired aggregation period of events (in seconds)
  • event_fields: If provided, a dict mapping one or more event types to lists of event fields. The event types recognized are 'Quote', 'Greeks', and 'Candle'. If specified, the server will be asked to send only these fields in a compact format. Compact events will be translated to the same dictionary format as full events, though with missing keys. Example:
    {
        "Quote": ["eventType", "eventSymbol", "bidPrice", "askPrice", "bidSize", "askSize"]
    }
    
class Subscription:
def open(self) -> tastytrade_sdk.Subscription:

Start listening for feed events

def close(self) -> None:

Close the stream connection

@singleton
class Api:

In case an open API feature isn't supported by this SDK yet, use this submodule to make direct requests to the API.

The params argument can either be a Dict[str, Any] or a List[Tuple[str, Any]]

API endpoints that accept multiple symbols in the query string use the symbol[]=SPY&symbol[]=AAPL&... convention, in which case, params should be passed as a List[Tuple[str, Any]], since duplicate keys are not allowed in dicts. e.g:

equities = tasty.api.get(
    '/instruments/equities',
    params=[('symbol[]', 'SPY'), ('symbol[]', 'AAPL')]
)


def get( self, path: str, params: Union[Dict[str, Any], List[Tuple[str, Any]], NoneType] = None) -> Optional[dict]:

Make a GET request

def post( self, path: str, params: Union[Dict[str, Any], List[Tuple[str, Any]], NoneType] = None, data: Optional[dict] = None) -> Optional[dict]:

Make a POST request

def put( self, path: str, params: Union[Dict[str, Any], List[Tuple[str, Any]], NoneType] = None, data: Optional[dict] = None) -> Optional[dict]:

Make a PUT request

def patch( self, path: str, params: Union[Dict[str, Any], List[Tuple[str, Any]], NoneType] = None, data: Optional[dict] = None) -> Optional[dict]:

Make a PATCH request

def delete( self, path: str, params: Union[Dict[str, Any], List[Tuple[str, Any]], NoneType] = None) -> Optional[dict]:

Make a DELETE request