Skip to content

Commit 223ba67

Browse files
pinzutuRealCLanger
andauthored
Prevent throwing KeyErrors for bond orders (#138)
* Ignore canceled deposits * Implement suggestion to ignore all events with status "canceled" and map card_failed_transaction to PPEventType.REMOVAL * Replace subscription '''return_vals[]''' with '''return_vals.get()''' in event.py/_parse_shares_and_fees --------- Co-authored-by: Christoph Langer <[email protected]>
1 parent 50ad548 commit 223ba67

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

pytr/event.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
class ConditionalEventType(Enum):
1010
"""Events that conditionally map to None or one/multiple PPEventType events"""
1111

12-
FAILED_CARD_TRANSACTION = auto()
1312
SAVEBACK = auto()
1413
TRADE_INVOICE = auto()
1514

@@ -50,7 +49,7 @@ class EventType(Enum):
5049
"CREDIT": PPEventType.DIVIDEND,
5150
"ssp_corporate_action_invoice_cash": PPEventType.DIVIDEND,
5251
# Failed card transactions
53-
"card_failed_transaction": ConditionalEventType.FAILED_CARD_TRANSACTION,
52+
"card_failed_transaction": PPEventType.REMOVAL,
5453
# Interests
5554
"INTEREST_PAYOUT": PPEventType.INTEREST,
5655
"INTEREST_PAYOUT_CREATED": PPEventType.INTEREST,
@@ -116,12 +115,8 @@ def _parse_type(event_dict: Dict[Any, Any]) -> Optional[EventType]:
116115
event_type: Optional[EventType] = tr_event_type_mapping.get(
117116
event_dict.get("eventType", ""), None
118117
)
119-
if event_type == ConditionalEventType.FAILED_CARD_TRANSACTION:
120-
event_type = (
121-
PPEventType.REMOVAL
122-
if event_dict.get("status", "").lower() == "executed"
123-
else None
124-
)
118+
if event_dict.get("status", "").lower() == "canceled":
119+
event_type = None
125120
return event_type
126121

127122
@classmethod
@@ -210,7 +205,7 @@ def _parse_shares_and_fees(
210205
titles, shares_dicts + fees_dicts, locales
211206
):
212207
return_vals[key] = cls._parse_float_from_detail(elem_dict, locale)
213-
return return_vals["shares"], return_vals.get("fees", None)
208+
return return_vals.get("shares"), return_vals.get("fees")
214209

215210
@classmethod
216211
def _parse_taxes(cls, event_dict: Dict[Any, Any]) -> Optional[float]:

0 commit comments

Comments
 (0)