Support fqme rendering *without* the src key

Since most (legacy) stock brokers design their symbology without
including the target exchange's source asset name - normally a fiat
currency like USD - this adds an option for rendering market endpoints
without that token for simpler use in backends for such brokers.

As an example IB doesn't expect a `mnq/usd.cme.ib` symbol and instead
presumes that since the CME lists all assets in USD then the source
asset is implied.

Impl details:
- add `MktPair.pair: str` which replaces `.key` as a better name.
- offer a `without_src: bool` to a new `.get_fqme()` getter method
  which will render everything the same minus the src token.
- expose the new flag through both the new `.get_fqme()` and
  `.get_bs_fqme()` methods and wrap those both under the original
  property names `.bs_fqme` and `.fqme`.
master
Tyler Goodlet 2023-05-17 16:47:15 -04:00
parent 12bfabf056
commit 89e8a834bf
1 changed files with 34 additions and 12 deletions

View File

@ -356,6 +356,13 @@ class MktPair(Struct, frozen=True):
'''
The "endpoint key" for this market.
'''
return self.pair
@property
def pair(self) -> str:
'''
The "endpoint asset pair key" for this market.
Eg. mnq/usd or btc/usdt or xmr/btc
In most other tina platforms this is referred to as the
@ -390,13 +397,16 @@ class MktPair(Struct, frozen=True):
return maybe_cons_tokens(field_strs)
# NOTE: the main idea behind an fqme is to map a "market address"
# to some endpoint from a transaction provider (eg. a broker) such
# that we build a table of `fqme: str -> bs_mktid: Any` where any "piker
# market address" maps 1-to-1 to some broker trading endpoint.
# @cached_property
@property
def fqme(self) -> str:
def get_fqme(
self,
# NOTE: allow dropping the source asset from the
# market endpoint's pair key. Eg. to change
# mnq/usd.<> -> mnq.<> which is useful when
# searching (legacy) stock exchanges.
without_src: bool = False,
) -> str:
'''
Return the fully qualified market endpoint-address for the
pair of transacting assets.
@ -431,21 +441,33 @@ class MktPair(Struct, frozen=True):
https://github.com/pikers/piker/issues/467
'''
key: str = self.pair if not without_src else str(self.dst)
return maybe_cons_tokens([
self.key, # final "pair name" (eg. qqq[/usd], btcusdt)
key, # final "pair name" (eg. qqq[/usd], btcusdt)
self.venue,
self.suffix, # includes expiry and other con info
self.broker,
])
@property
def bs_fqme(self) -> str:
# NOTE: the main idea behind an fqme is to map a "market address"
# to some endpoint from a transaction provider (eg. a broker) such
# that we build a table of `fqme: str -> bs_mktid: Any` where any "piker
# market address" maps 1-to-1 to some broker trading endpoint.
# @cached_property
fqme = property(get_fqme)
def get_bs_fqme(
self,
**kwargs,
) -> str:
'''
FQME sin broker part XD
'''
head, _, broker = self.fqme.rpartition('.')
return head
sin_broker, *_ = self.get_fqme(**kwargs).rpartition('.')
return sin_broker
bs_fqme = property(get_bs_fqme)
@property
def fqsn(self) -> str: