Skip to content

Commit

Permalink
Fixed complex orders + error messages (#133)
Browse files Browse the repository at this point in the history
* Added error_message in case stop_trigger is missing

* complex-order.id can be int

* Changed type of preflight_id and complex_order_id

* Changed from | to Union
  • Loading branch information
rekroeg authored Mar 10, 2024
1 parent 8ea8e81 commit c029fcd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
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)

0 comments on commit c029fcd

Please sign in to comment.