Releases: tastyware/tastytrade
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
tastyware/tastytrade:v9.2
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.Listandtyping.Dict - Slightly improves streamer typing using bounded generic
TypeVars - Switches to the standard library's
ZoneInfoinstead of usingpytz - Fixes a bug in
Equity.get_active_equitieswhere some results may not contain thelisted_marketfield
Full Changelog: v9.1...v9.2
tastyware/tastytrade:v9.1
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
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 thea_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 calledPriceEffect). 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 theAccountclass 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 theAlertStreamerfor 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-aioto 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.Selffor classmethods -
add
CustomerandUserdataclasses for data returned bySession -
add tests for
dxfeedmodule -
unclutter
tastytradepackage-level exports, which are now restricted to justAccount,AlertStreamer,DXLinkStreamer,Session, andWatchlist -
no longer using
Optionaltypes for some common, important fields, such asPlacedOrder.idandOption.streamer_symbol. -
add
unsubscribe_allfunction to streamer to unsubscribe from all events of a certain type -
return type of
Account.place_orderandAccount.place_complex_ordernow returntastytrade.order.PlacedOrderResponseandtastytrade.order.PlacedComplexOrderResponserespectively, which are guaranteed to contain theorderorcomplex_orderproperties.
Full Changelog: v8.5...v9.0