.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: try:
src_name_start = bs_mktid.rindex(src) src_name_start: str = bs_mktid.rindex(src)
except ( except (
ValueError, # substr not found ValueError, # substr not found
): ):
@ -99,8 +99,8 @@ def get_likely_pair(
# log.warning( # log.warning(
# f'No src fiat {src} found in {bs_mktid}?' # 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: if likely_dst == dst:
return bs_mktid return bs_mktid

View File

@ -28,6 +28,7 @@ from typing import (
Any, Any,
Callable, Callable,
Generator, Generator,
Literal,
TYPE_CHECKING, TYPE_CHECKING,
) )
@ -51,6 +52,18 @@ if TYPE_CHECKING:
log = get_logger(__name__) 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): class Transaction(Struct, frozen=True):
# NOTE: this is a unified acronym also used in our `MktPair` # 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 cost: float # commisions or other additional costs
dt: DateTime dt: DateTime
# the "event type" in terms of "market events" see # the "event type" in terms of "market events" see above and
# https://github.com/pikers/piker/issues/510 for where we're # https://github.com/pikers/piker/issues/510
# probably going with this. etype: TxnType = 'clear'
etype: str = 'clear'
# TODO: we can drop this right since we # TODO: we can drop this right since we
# can instead expect the backend to provide this # can instead expect the backend to provide this