Releases: tastyware/tastytrade
tastyware/tastytrade:v9.12
What's Changed
NestedOptionChain.deliverablesis now optional, as sandbox sessions often don't include it- Add session token and streamer token expiration information to session
- Better error handling and reconnection callbacks in streamer
Full Changelog: v9.11...v9.12
tastyware/tastytrade:v9.11
What's Changed
- added refresh_interval to subscribe method by @CosmicTrader in #221
Frequency of streamed events can now be changed on a per-event basis:
await streamer.subscribe(Quote, ['AAPL', 'MSFT'], refresh_interval=0.5)- added a new session,
OAuthSession, for users who have been granted Tastytrade OAuth access
from tastytrade.session import OAuthSession
session = OAuthSession('provider_secret', 'refresh_token')This session can be used in most of the same places as a normal session, allowing you to manage connected user accounts.
- fixes bug in #222 due to tastytrade changing their account streamer API
New Contributors
- @CosmicTrader made their first contribution in #221
Full Changelog: v9.10...v9.11
tastyware/tastytrade:v9.10
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:pass@127.0.0.1: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
What's Changed
- Added missing:
used_derivative_buying_powerdata field by @JBlohm in #210. This allows you to calculate buying power usage in the same way Tasty does it. This can be accessed asAccountBalance.used_derivative_buying_powerandAccountBalanceSnapshot.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 toDXLinkStreamer, 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
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_responseto not use a leading underscore in utils.py, since they are used in various modules.
New Contributors
- @danstever made their first contribution in #203
Full Changelog: v9.7...v9.8
tastyware/tastytrade:v9.7
What's Changed
-
[BREAKING] Update instruments.py by @Quenos in #192
This PR changes the signature of theNestedOptionChain.get_chain(andNestedOptionChain.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 returnlist[NestedOptionChain]instead of a singleNestedOptionChain. -
add serialization for sessions by @Graeme22 in #197
This PR adds new functions to thetastytrade.Sessionclass,serializeanddeserialize, 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
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_drivea default value ofFalseas it may not always be present
New Contributors
- @steven5538 made their first contribution in #189
Full Changelog: v9.5...v9.6
tastyware/tastytrade:v9.5
What's Changed
Small release with mostly internal changes.
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.CancelledErrorin cancelled heartbeat/main loop tasks for bothAlertStreamerandDXLinkStreamer. - Uses a
pydantic.WrapValidatorfor candle OHLC instead of a bunch ofcomputed_fields as in v9.4
Full Changelog: v9.4...v9.5
tastyware/tastytrade:v9.4
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 flagsThis 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:
passThe 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
What's Changed
- All event fields from
tastytrade.dxfeedchanged 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, andTradeevents fromtastytrade.dxfeedhave lessOptionalfields.
Previously, the streamer would return a lot of "garbage" events that would have to be handled in some way. For example, listening toQuoteevents 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: ignoreThis 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_priceFull Changelog: v9.2...v9.3