Skip to content

Releases: tastyware/tastytrade

tastyware/tastytrade:v9.5

16 Dec 22:31
Compare
Choose a tag to compare

What's Changed

Small release with mostly internal changes.

  • add advanced order instructions, handle CancelledError in streamer tasks by @Graeme22 in #187

Adds advanced order instructions, which can be used to control how the API handles orders in some edge cases. This is discussed in detail in #178.

  • Handles streamer closure better by catching asyncio.CancelledError in cancelled heartbeat/main loop tasks for both AlertStreamer and DXLinkStreamer.
  • Uses a pydantic.WrapValidator for candle OHLC instead of a bunch of computed_fields as in v9.4

Full Changelog: v9.4...v9.5

tastyware/tastytrade:v9.4

10 Dec 20:22
ce5ef1d
Compare
Choose a tag to compare

What's Changed

The datetime-related utilities in tastytrade.utils suffered from a hard-to-detect bug related to variable Python default arguments. These utilities will work correctly now, whereas previously something like this:

from tastytrade.utils import is_market_open_on
print(is_market_open_on())
# 5 hours later...
print(is_market_open_on())

could potentially yield incorrect results in long-running programs. This now behaves as expected, and no code changes are required.

This partially reverts the changes in v9.3 which excluded all Candle events without OHLC fields. @JBlohm brought to attention that these "empty" candles can still contain important information in the event_flags field. This was solved by re-allowing the empty candles (while still ensuring None values provided will be set to 0, which allows for filtering them out without messing with the types), and as a bonus a new class, tastytrade.dxfeed.IndexedEvent, was added which allows for easily parsing the event_flags field, which otherwise required some bitwise math. So upgrading will look something like this:

candles = []
async for candle in streamer.listen(Candle):
    if not Decimal.is_zero(candle.open):  # filter out invalid candles
        candles.append(candle)
    else:
        print(candle.snapshot_end)  # handle event flags

This updates the websockets dependency to >=14.1 and uses the new async websockets features to implement auto-reconnect functionality upon certain connection errors. This takes effect automatically and doesn't require any code changes. However, the reconnection algorithm's behavior can be modified through environment variables, documented here.

Building on the auto-reconnection functionality, this PR introduces callback functions that can be ran upon reconnection to handle common tasks, for example, re-subscribing to alerts or events. Here's how this looks:

async def callback(streamer: DXLinkStreamer, arg1, arg2):
    await streamer.subscribe(Trade, ["SPX"])
    print(arg1 + arg2)

async with DXLinkStreamer(session, reconnect_args=(arg1, arg2), reconnect_fn=callback) as streamer:
    pass

The first argument for the callback will always be the streamer itself; after that, the number and type of arguments is determined by your use case.
Additionally, a small change was made to the existing AlertStreamer.create and DXLinkStreamer.create functions. They have been switched to a simpler syntax that allows you to await the constructor directly. So this code:

streamer = await AlertStreamer.create(session)

becomes:

streamer = await AlertStreamer(session)

Full Changelog: v9.3...v9.4

tastyware/tastytrade:v9.3

03 Dec 19:24
Compare
Choose a tag to compare

What's Changed

  • All event fields from tastytrade.dxfeed changed to Pythonic snake_case instead of their previous names, which came directly from the Java documentation and therefore used camelCase.
    So this code:
print(quote.eventSymbol)

Becomes:

print(quote.event_symbol)
  • Candle, Quote, and Trade events from tastytrade.dxfeed have less Optional fields.
    Previously, the streamer would return a lot of "garbage" events that would have to be handled in some way. For example, listening to Quote events might have looked like this:
from tastytrade.dxfeed import Quote
# ...
async for quote in streamer.listen(Quote):
    if quote.bidPrice is not None and quote.askPrice is not None:
        quotes.append(quote)

To make things even worse, using the Quote objects returned down the road led to lots of # type: ignores littering the code as type checkers are unable to determine that quotes without crucial properties have already been filtered out:

# type checker will complain as these may be `None`!
mid = quote.bidPrice + quote.askPrice  # type: ignore

This mini-release solves these problems by making these fields non-optional, and not returning the events at all if they're missing crucial fields. (For example, Quotes are pretty much useless without the bid/ask, or Candles without OHLC.)
So the above code can be changed to:

from tastytrade.dxfeed import Quote
# ...
async for quote in streamer.listen(Quote):
    quotes.append(quote)

and

mid = quote.bid_price + quote.ask_price

Full Changelog: v9.2...v9.3

tastyware/tastytrade:v9.2

02 Dec 19:33
Compare
Choose a tag to compare

What's Changed

  • Removes support for Python 3.8, which has now reached end of life
  • Uses Python 3.9's simpler typing, removing the need to import typing.List and typing.Dict
  • Slightly improves streamer typing using bounded generic TypeVars
  • Switches to the standard library's ZoneInfo instead of using pytz
  • Fixes a bug in Equity.get_active_equities where some results may not contain the listed_market field

Full Changelog: v9.1...v9.2

tastyware/tastytrade:v9.1

11 Nov 23:38
a160827
Compare
Choose a tag to compare

What's Changed

Small release fixing a pretty important bug which prevents placing test (dry_run=True) orders.

Full Changelog: v9.0...v9.1

tastyware/tastytrade:v9.0

11 Oct 03:17
a3ac177
Compare
Choose a tag to compare

New major release! Warning: BREAKING CHANGES! See below.
This is a large release with many changes, so please report any issues you run across!

What's Changed

  • Add sync/async functionality for all requests by @Graeme22 in #168
    Simply add the a_ prefix to the sync method name and boom, async!
    Here's how it looks:

    acc = await Account.a_get_account(session, account_number)
  • Move from price effect to +/- for numbers by @Graeme22 in #169
    Previously, most number fields in the API were represented with two separate fields: one for the value, another for the sign (which in the SDK is called PriceEffect). This led to less readability and a lot of lines of code that looked like this:

    value *= -1 if price_effect == PriceEffect.DEBIT else 1

    However, as of this release, we can just use positive numbers for credits and negative ones for debits... Much easier! So this example from the old docs of building an order:

    order = NewOrder(
        time_in_force=OrderTimeInForce.DAY,
        order_type=OrderType.LIMIT,
        legs=[leg],  # you can have multiple legs in an order
        price=Decimal('10'),  # limit price, $10/share for a total value of $50
        price_effect=PriceEffect.DEBIT
    )

    Became this:

    order = NewOrder(
        time_in_force=OrderTimeInForce.DAY,
        order_type=OrderType.LIMIT,
        legs=[leg],  # you can have multiple legs in an order
        price=Decimal('-10')  # limit price, $10/share debit for a total value of $50
    )

    Under the hood interactions with the API remain unchanged, but for SDK users this should make life much more pleasant.

  • better typing for streamer, orders by @Graeme22 in #170
    Certain functions for the streamer ended up not working very cleanly with type checkers. So, with a few typing tricks, the streamer functions have changed their parameters, but in exchange we get type hints and a smoother workflow. Here's how the streamer worked before:

    from tastytrade.dxfeed import EventType
    async with DXLinkStreamer(session) as streamer:
        await streamer.subscribe(EventType.QUOTE, ['SPY'])
        quote = await streamer.get_event(EventType.QUOTE)

    And here's how it looks now:

    from tastytrade.dxfeed import Quote
    async with DXLinkStreamer(session) as streamer:
        await streamer.subscribe(Quote, ['SPY'])
        quote = await streamer.get_event(Quote)

    This makes life a lot easier for anyone doing type checking or even using an IDE, so pretty much everyone! The type you pass in will not only control the type of event you receive, but also the inferred return type.

  • add order chains, add is_market_open_on util by @Graeme22 in #171
    This adds a new function to the Account class allowing for fetching order chains (groups of trades in the same symbol used to track open, rolls, and close). Previously these were only available through the AlertStreamer for existing postions, but now you can query over a time range for a given underlying:

    chains = account.get_order_chains(session, 'SPX', start_time, end_time)

    Also, adds a utility function to check if the market is open on a specific date (defaults to today).

  • test coverage is now better and added for all async tests as well. Using pytest-aio to easily run all tests in the same event loop.

  • update docs with new functionality

  • switch to pyright over mypy for type checking

  • switch to Python 3.8 for building

  • replace several deprecated functions from pydantic v1

  • use typing_extensions.Self for classmethods

  • add Customer and User dataclasses for data returned by Session

  • add tests for dxfeed module

  • unclutter tastytrade package-level exports, which are now restricted to just Account, AlertStreamer, DXLinkStreamer, Session, and Watchlist

  • no longer using Optional types for some common, important fields, such as PlacedOrder.id and Option.streamer_symbol.

  • add unsubscribe_all function to streamer to unsubscribe from all events of a certain type

  • return type of Account.place_order and Account.place_complex_order now return tastytrade.order.PlacedOrderResponse and tastytrade.order.PlacedComplexOrderResponse respectively, which are guaranteed to contain the order or complex_order properties.

Full Changelog: v8.5...v9.0

tastyware/tastytrade:v8.5

01 Oct 22:34
Compare
Choose a tag to compare

Re-release of v8.4 with packaging fixed. Features:

  • Adds backtesting features! Currently in beta, so please report any issues.
  • Switches to httpx over requests
  • Fixes #165, adding new parameters to Account.get_balance_snapshots

Full Changelog: v8.3...v8.5

tastyware/tastytrade:v8.3

10 Sep 20:05
Compare
Choose a tag to compare

Small bug fixes: #163 as well as internal bugs having to do with cryptocurrencies.

Full Changelog: v8.2...v8.3

tastyware/tastytrade:v8.2

30 Jul 17:16
90204f5
Compare
Choose a tag to compare

What's Changed

  • go back to requests to fix problems with httpx by @Graeme22 in #159

Full Changelog: v8.1...v8.2

tastyware/tastytrade:v8.1

29 Jul 20:17
0128eee
Compare
Choose a tag to compare

What's Changed

  • Prepare v8.1: use httpx Session, prepare for async version, combine Production and Certification sessions by @Graeme22 in #158

Full Changelog: v7.9...v8.1