Skip to content

Commit 14d0ac8

Browse files
committed
add crypto docs, better error handling
1 parent f250180 commit 14d0ac8

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

docs/orders.rst

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Note that to cancel complex orders, you need to use the ``delete_complex_order``
131131
Notional market orders
132132
----------------------
133133

134-
Notional orders are slightly different from normal orders. Since the market will determine both the quantity and the price for you, you need to pass `value` instead of price, and pass `None` for the `quantity` parameter to ``build_leg``.
134+
Notional orders are slightly different from normal orders. Since the market will determine both the quantity and the price for you, you need to pass ``value`` instead of price, and pass ``None`` for the ``quantity`` parameter to ``build_leg``.
135135

136136
.. code-block:: python
137137
@@ -145,3 +145,23 @@ Notional orders are slightly different from normal orders. Since the market will
145145
]
146146
)
147147
resp = account.place_order(session, order, dry_run=False)
148+
149+
Cryptocurrency orders
150+
---------------------
151+
152+
Cryptocurrency orders should use the special ``IOC`` TIF:
153+
154+
.. code-block:: python
155+
156+
order = NewOrder(
157+
time_in_force=OrderTimeInForce.IOC,
158+
order_type=OrderType.NOTIONAL_MARKET,
159+
value=-Decimal(100), # buy $100 of ETH
160+
legs=[
161+
Leg(
162+
instrument_type=InstrumentType.CRYPTOCURRENCY,
163+
action=OrderAction.BUY_TO_OPEN,
164+
symbol="ETH/USD",
165+
),
166+
],
167+
)

tastytrade/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
BACKTEST_URL = "https://backtester.vast.tastyworks.com"
55
CERT_URL = "https://api.cert.tastyworks.com"
66
VAST_URL = "https://vast.tastyworks.com"
7-
VERSION = "10.3.0"
7+
VERSION = "10.3.1"
88

99
__version__ = VERSION
1010
version_str: str = f"tastyware/tastytrade:v{VERSION}"

tastytrade/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from pandas_market_calendars import get_calendar # type: ignore[import-untyped]
1010
from pydantic import BaseModel, ConfigDict
1111

12+
from tastytrade import logger
13+
1214
NYSE: Any = get_calendar("NYSE")
1315
TZ = ZoneInfo("US/Eastern")
1416

@@ -259,10 +261,12 @@ def validate_response(response: Response) -> None:
259261
errors = content.get("errors") or [content]
260262
message = ""
261263
for error in errors:
262-
if "code" in error:
264+
if "code" in error and "message" in error:
263265
message += f"{error['code']}: {error['message']}\n"
264-
else:
266+
elif "domain" in error and "reason" in error:
265267
message += f"{error['domain']}: {error['reason']}\n"
268+
else:
269+
logger.debug(f"Unknown error type: {error}")
266270

267271
raise TastytradeError(message)
268272

0 commit comments

Comments
 (0)