Skip to content

Releases: tastyware/tastytrade

tastyware/tastytrade:v9.10

17 Feb 18:13
dc24afb
Compare
Choose a tag to compare

What's Changed

Adds a new module, market_sessions to the SDK which implements the new API endpoints used for checking exchange status and market calendars. This is an alternative to some of the utility functions in tastytrade.utils which uses Tastytrade endpoints. Check out the new docs page here!

This adds a new optional parameter, proxy, to the Session class to proxy all requests through a proxy server. Proxies will also apply to all web socket connections (so DXLinkStreamer and AlertStreamer) created with that session.

session = Session('username', 'password', proxy="http://user:[email protected]:8080")
accounts = Account.get_accounts(session)  # proxied!
async with DXLinkStreamer(session) as streamer:  # proxied!
    # ...
  • sessions now have a context manager, which can be used like this:
with Session('username', 'password') as session:
    # ...

which is equivalent to:

session = Session('username', 'password')
session.destroy()

Full Changelog: v9.9...v9.10

tastyware/tastytrade:v9.9

05 Feb 21:50
a5788cf
Compare
Choose a tag to compare

What's Changed

  • Added missing: used_derivative_buying_power data field by @JBlohm in #210. This allows you to calculate buying power usage in the same way Tasty does it. This can be accessed as AccountBalance.used_derivative_buying_power and AccountBalanceSnapshot.used_derivative_buying_power.
  • add streamer refresh interval by @Graeme22 in #212, many thanks to @bonkzwonil for opening #211!
    Previously, the dubiously named "acceptAggregationPeriod" parameter to newly created DXLink channels was hardcoded to 10 seconds. This resulted in events like Quote being updated only once every 10 seconds, a far cry from live streaming! Now this value is adjustable as a new parameter to DXLinkStreamer, but it defaults to 0.1 which should be close to live for most use cases.

Example usage:

streamer = await DXLinkStreamer(session, refresh_interval=5)

Since the new default is 0.1, most users should immediately see a benefit without making any changes at all.

New Contributors

Full Changelog: v9.8...v9.9

tastyware/tastytrade:v9.8

29 Jan 19:00
0091777
Compare
Choose a tag to compare

What's Changed

  • notional orders support by @Graeme22 in #207, thanks to @vadimtk for opening #206 and noticing this issue!
    You can now place notional market orders like so:
symbol = Equity.get_equity(session, 'AAPL')
order = NewOrder(
    time_in_force=OrderTimeInForce.DAY,
    order_type=OrderType.NOTIONAL_MARKET,
    value=Decimal(-10),  # $10 debit, this will result in fractional shares
    legs=[
        symbol.build_leg(None, OrderAction.BUY_TO_OPEN),
    ]
)
resp = account.place_order(session, order, dry_run=False)
  • Streamer shutdown bug fixed in 7928e9b, see #194, #205. Thanks to @militantwalrus for helping identify the issue!
  • Add note about using is_test and remember_token for additional sessions by @danstever in #203
  • order source field is now present for placed orders, detected by @salamad in #204
  • unit tests are now fully annotated for type safety
  • renames three internal utility functions, _set_sign_for, _get_sign, and _validate_response to not use a leading underscore in utils.py, since they are used in various modules.

New Contributors

Full Changelog: v9.7...v9.8

tastyware/tastytrade:v9.7

12 Jan 22:40
df9a9f9
Compare
Choose a tag to compare

What's Changed

  • [BREAKING] Update instruments.py by @Quenos in #192
    This PR changes the signature of the NestedOptionChain.get_chain (and NestedOptionChain.a_get_chain) functions. Certain symbols, like VIX and SPX, may have more than one root symbol (eg SPX and SPXW), which are parsed as different chains in the API. Previously, some of that data was being thrown away, but now these functions return list[NestedOptionChain] instead of a single NestedOptionChain.

  • add serialization for sessions by @Graeme22 in #197
    This PR adds new functions to the tastytrade.Session class, serialize and deserialize, which allow for safely and easily storing sessions for later use. Example usage:

session = Session('username', 'password')
# ...
data = session.serialize()
redis.set("session", data)
# ...
session = Session.deserialize(redis.get("session"))

Full Changelog: v9.6...v9.7

tastyware/tastytrade:v9.6

06 Jan 22:41
Compare
Choose a tag to compare

What's Changed

Tiny release to make sure the Account class keeps working for everybody!

  • Fix the wrong usage in the example by @steven5538 in #189
  • Gives the field Account.is_test_drive a default value of False as it may not always be present

New Contributors

Full Changelog: v9.5...v9.6

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