Skip to content

Commit

Permalink
fix dry run bug (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
Graeme22 authored Nov 11, 2024
1 parent 0cf0ce0 commit a160827
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async with DXLinkStreamer(session) as streamer:
```

```python
>>> [Quote(eventSymbol='SPY', eventTime=0, sequence=0, timeNanoPart=0, bidTime=0, bidExchangeCode='Q', bidPrice=411.58, bidSize=400.0, askTime=0, askExchangeCode='Q', askPrice=411.6, askSize=1313.0), Quote(eventSymbol='SPX', eventTime=0, sequence=0, timeNanoPart=0, bidTime=0, bidExchangeCode='\x00', bidPrice=4122.49, bidSize='NaN', askTime=0, askExchangeCode='\x00', askPrice=4123.65, askSize='NaN')]
>>> Quote(eventSymbol='SPY', eventTime=0, sequence=0, timeNanoPart=0, bidTime=0, bidExchangeCode='Q', bidPrice=411.58, bidSize=400.0, askTime=0, askExchangeCode='Q', askPrice=411.6, askSize=1313.0)
```

Note that this is asynchronous code, so you can't run it as is unless you're using a Jupyter notebook or something similar.
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
project = "tastytrade"
copyright = "2024, Graeme Holliday"
author = "Graeme Holliday"
release = "9.0"
release = "9.1"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
4 changes: 2 additions & 2 deletions docs/data-streamer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Once you've created the streamer, you can subscribe/unsubscribe to events, like
.. code-block:: python
from tastytrade.dxfeed import Quote
subs_list = ['SPY', 'SPX']
subs_list = ['SPY'] # you can add more symbols here!
async with DXLinkStreamer(session) as streamer:
await streamer.subscribe(Quote, subs_list)
Expand All @@ -36,7 +36,7 @@ Once you've created the streamer, you can subscribe/unsubscribe to events, like
break
print(quotes)
>>> {'SPY': Quote(eventSymbol='SPY', eventTime=0, sequence=0, timeNanoPart=0, bidTime=0, bidExchangeCode='Q', bidPrice=411.58, bidSize=400.0, askTime=0, askExchangeCode='Q', askPrice=411.6, askSize=1313.0), 'SPX': Quote(eventSymbol='SPX', eventTime=0, sequence=0, timeNanoPart=0, bidTime=0, bidExchangeCode='\x00', bidPrice=4122.49, bidSize='NaN', askTime=0, askExchangeCode='\x00', askPrice=4123.65, askSize='NaN')}
>>> [{'SPY': Quote(eventSymbol='SPY', eventTime=0, sequence=0, timeNanoPart=0, bidTime=0, bidExchangeCode='Q', bidPrice=411.58, bidSize=400.0, askTime=0, askExchangeCode='Q', askPrice=411.6, askSize=1313.0), 'SPX': Quote(eventSymbol='SPX', eventTime=0, sequence=0, timeNanoPart=0, bidTime=0, bidExchangeCode='\x00', bidPrice=4122.49, bidSize='NaN', askTime=0, askExchangeCode='\x00', askPrice=4123.65, askSize='NaN')}]

Note that these are ``asyncio`` calls, so you'll need to run this code asynchronously. Here's an example:

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "tastytrade"
version = "9.0"
version = "9.1"
description = "An unofficial, sync/async SDK for Tastytrade!"
readme = "README.md"
requires-python = ">=3.8"
Expand Down
2 changes: 1 addition & 1 deletion tastytrade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
BACKTEST_URL = "https://backtester.vast.tastyworks.com"
CERT_URL = "https://api.cert.tastyworks.com"
VAST_URL = "https://vast.tastyworks.com"
VERSION = "9.0"
VERSION = "9.1"

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
Expand Down
6 changes: 4 additions & 2 deletions tastytrade/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ class PlacedOrder(TastytradeJsonDataclass):
"""

account_number: str
id: int
time_in_force: OrderTimeInForce
order_type: OrderType
underlying_symbol: str
Expand All @@ -292,6 +291,8 @@ class PlacedOrder(TastytradeJsonDataclass):
edited: bool
updated_at: datetime
legs: List[Leg]
#: the ID of the order; test orders placed with dry_run don't have an ID
id: int = -1
size: Optional[Decimal] = None
price: Optional[Decimal] = None
gtc_date: Optional[date] = None
Expand Down Expand Up @@ -328,9 +329,10 @@ class PlacedComplexOrder(TastytradeJsonDataclass):
"""

account_number: str
id: int
type: str
orders: List[PlacedOrder]
#: the ID of the order; test orders placed with dry_run don't have an ID
id: int = -1
trigger_order: Optional[PlacedOrder] = None
terminal_at: Optional[str] = None
ratio_price_threshold: Optional[Decimal] = None
Expand Down
4 changes: 2 additions & 2 deletions tastytrade/streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ async def create(cls, session: Session) -> "AlertStreamer":
self = cls(session)
return await self.__aenter__()

async def __aexit__(self, exc_type, exc, tb):
async def __aexit__(self, *exc):
await self.close()

async def close(self):
Expand Down Expand Up @@ -381,7 +381,7 @@ async def create(
self = cls(session, ssl_context=ssl_context)
return await self.__aenter__()

async def __aexit__(self, exc_type, exc, tb):
async def __aexit__(self, *exc):
await self.close()

async def close(self):
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a160827

Please sign in to comment.