From 430309b5dc506a6c4325c063e3973f07b3e8e3a0 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 16 Jul 2023 21:22:15 -0400 Subject: [PATCH] .accounting: type `Transaction.etype` as a `Literal` Start working out the set of possible "txn types" we want to define in a simple set. Relates to #510 --- piker/accounting/__init__.py | 6 +++--- piker/accounting/_ledger.py | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/piker/accounting/__init__.py b/piker/accounting/__init__.py index 167dbcc2..d6e1c3b6 100644 --- a/piker/accounting/__init__.py +++ b/piker/accounting/__init__.py @@ -88,7 +88,7 @@ def get_likely_pair( ''' try: - src_name_start = bs_mktid.rindex(src) + src_name_start: str = bs_mktid.rindex(src) except ( ValueError, # substr not found ): @@ -99,8 +99,8 @@ def get_likely_pair( # log.warning( # f'No src fiat {src} found in {bs_mktid}?' # ) - return + return None - likely_dst = bs_mktid[:src_name_start] + likely_dst: str = bs_mktid[:src_name_start] if likely_dst == dst: return bs_mktid diff --git a/piker/accounting/_ledger.py b/piker/accounting/_ledger.py index b6f0ee74..f4cb3f38 100644 --- a/piker/accounting/_ledger.py +++ b/piker/accounting/_ledger.py @@ -28,6 +28,7 @@ from typing import ( Any, Callable, Generator, + Literal, TYPE_CHECKING, ) @@ -51,6 +52,18 @@ if TYPE_CHECKING: log = get_logger(__name__) +TxnType = Literal[ + 'clear', + 'transfer', + + # TODO: see https://github.com/pikers/piker/issues/510 + # 'split', + # 'rename', + # 'resize', + # 'removal', +] + + class Transaction(Struct, frozen=True): # NOTE: this is a unified acronym also used in our `MktPair` @@ -70,10 +83,9 @@ class Transaction(Struct, frozen=True): cost: float # commisions or other additional costs dt: DateTime - # the "event type" in terms of "market events" see - # https://github.com/pikers/piker/issues/510 for where we're - # probably going with this. - etype: str = 'clear' + # the "event type" in terms of "market events" see above and + # https://github.com/pikers/piker/issues/510 + etype: TxnType = 'clear' # TODO: we can drop this right since we # can instead expect the backend to provide this