From e4731eff1076a85d3717420cbd8514a8eb6dceca Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 17 Jul 2023 17:27:22 -0400 Subject: [PATCH] Fix `Position.expiry == None` bug --- piker/accounting/_pos.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/piker/accounting/_pos.py b/piker/accounting/_pos.py index 061a5b44..90b179f8 100644 --- a/piker/accounting/_pos.py +++ b/piker/accounting/_pos.py @@ -109,8 +109,17 @@ class Position(Struct): @property def expiry(self) -> datetime | None: - exp: str = self.mkt.expiry.lower() - match exp: + ''' + Security expiry if it has a limited lifetime. + + For non-derivative markets this is normally `None`. + + ''' + exp: str | None = self.mkt.expiry + if exp is None: + return None + + match exp.lower(): # empty str, 'perp' (contract) or simply a null # signifies instrument with NO expiry. case 'perp' | '' | None: