.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
account_tests
Tyler Goodlet 2023-07-16 21:22:15 -04:00
parent 4c5507301e
commit 430309b5dc
2 changed files with 19 additions and 7 deletions

View File

@ -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

View File

@ -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