Add `MktPair.suffix: str` read from contract info
To be compat with the `Symbol` (for now) and generally allow for reading the (derivative) contract specific part of the fqme. Adjust `contract_info: list[str]` and make `src: str = ''` by default.rekt_pps
parent
452cd7db8a
commit
d4a5a3057c
|
@ -154,7 +154,7 @@ def maybe_cons_tokens(
|
||||||
sequence of elements in ``tokens``.
|
sequence of elements in ``tokens``.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
return '.'.join(filter(bool, tokens)).lower()
|
return delim_char.join(filter(bool, tokens)).lower()
|
||||||
|
|
||||||
|
|
||||||
class MktPair(Struct, frozen=True):
|
class MktPair(Struct, frozen=True):
|
||||||
|
@ -195,7 +195,7 @@ class MktPair(Struct, frozen=True):
|
||||||
# required; the reason is for backward compat since more positioning
|
# required; the reason is for backward compat since more positioning
|
||||||
# calculations were not originally stored with a src asset..
|
# calculations were not originally stored with a src asset..
|
||||||
|
|
||||||
src: str | Asset | None = None
|
src: str | Asset = ''
|
||||||
# "source asset" (name) used to buy *from*
|
# "source asset" (name) used to buy *from*
|
||||||
# (or used to sell *to*).
|
# (or used to sell *to*).
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ class MktPair(Struct, frozen=True):
|
||||||
|
|
||||||
# for derivs, info describing contract, egs.
|
# for derivs, info describing contract, egs.
|
||||||
# strike price, call or put, swap type, exercise model, etc.
|
# strike price, call or put, swap type, exercise model, etc.
|
||||||
contract_info: str | None = None
|
contract_info: list[str] | None = None
|
||||||
|
|
||||||
_atype: str = ''
|
_atype: str = ''
|
||||||
|
|
||||||
|
@ -287,7 +287,32 @@ class MktPair(Struct, frozen=True):
|
||||||
"symbol".
|
"symbol".
|
||||||
|
|
||||||
'''
|
'''
|
||||||
return maybe_cons_tokens([str(self.dst), self.src])
|
return maybe_cons_tokens(
|
||||||
|
[str(self.dst), self.src],
|
||||||
|
delim_char='',
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def suffix(self) -> str:
|
||||||
|
'''
|
||||||
|
The "contract suffix" for this market.
|
||||||
|
|
||||||
|
Eg. mnq/usd.20230616.cme.ib
|
||||||
|
^ ----- ^
|
||||||
|
or tsla/usd.20230324.200c.cboe.ib
|
||||||
|
^ ---------- ^
|
||||||
|
|
||||||
|
In most other tina platforms they only show you these details in
|
||||||
|
some kinda "meta data" format, we have FQMEs so we do this up
|
||||||
|
front and explicit.
|
||||||
|
|
||||||
|
'''
|
||||||
|
field_strs = [self.expiry]
|
||||||
|
con_info = self.contract_info
|
||||||
|
if con_info is not None:
|
||||||
|
field_strs.extend(con_info)
|
||||||
|
|
||||||
|
return maybe_cons_tokens(field_strs)
|
||||||
|
|
||||||
# NOTE: the main idea behind an fqme is to map a "market address"
|
# NOTE: the main idea behind an fqme is to map a "market address"
|
||||||
# to some endpoint from a transaction provider (eg. a broker) such
|
# to some endpoint from a transaction provider (eg. a broker) such
|
||||||
|
@ -387,6 +412,7 @@ class MktPair(Struct, frozen=True):
|
||||||
|
|
||||||
def unpack_fqme(
|
def unpack_fqme(
|
||||||
fqme: str,
|
fqme: str,
|
||||||
|
|
||||||
) -> tuple[str, str, str]:
|
) -> tuple[str, str, str]:
|
||||||
'''
|
'''
|
||||||
Unpack a fully-qualified-symbol-name to ``tuple``.
|
Unpack a fully-qualified-symbol-name to ``tuple``.
|
||||||
|
|
Loading…
Reference in New Issue