Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed complex orders + error messages #133

Merged
merged 4 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tastytrade/order.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import date, datetime
from decimal import Decimal
from enum import Enum
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Union

from tastytrade import VERSION
from tastytrade.utils import TastytradeJsonDataclass
Expand Down Expand Up @@ -283,9 +283,9 @@ class PlacedOrder(TastytradeJsonDataclass):
user_id: Optional[str] = None
username: Optional[str] = None
terminal_at: Optional[datetime] = None
complex_order_id: Optional[str] = None
complex_order_id: Optional[Union[str, int]] = None
complex_order_tag: Optional[str] = None
preflight_id: Optional[str] = None
preflight_id: Optional[Union[str, int]] = None
order_rule: Optional[OrderRule] = None


Expand All @@ -296,7 +296,7 @@ class PlacedComplexOrder(TastytradeJsonDataclass):
account_number: str
type: str
orders: List[PlacedOrder]
id: Optional[str] = None
id: Optional[Union[str, int]] = None
trigger_order: Optional[PlacedOrder] = None
terminal_at: Optional[str] = None
ratio_price_threshold: Optional[Decimal] = None
Expand Down
5 changes: 4 additions & 1 deletion tastytrade/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ def validate_response(response: Response) -> None:
errors = content.get('errors')
if errors is not None:
for error in errors:
error_message += f"\n{error['code']}: {error['message']}"
if "code" in error:
error_message += f"\n{error['code']}: {error['message']}"
else:
error_message += f"\n{error['domain']}: {error['reason']}"

raise TastytradeError(error_message)
Loading