From 89e8a834bf29a7aec1c56669313c60287d2de129 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 17 May 2023 16:47:15 -0400 Subject: [PATCH] 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`. --- piker/accounting/_mktinfo.py | 46 ++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/piker/accounting/_mktinfo.py b/piker/accounting/_mktinfo.py index b01d72fc..73f2f49a 100644 --- a/piker/accounting/_mktinfo.py +++ b/piker/accounting/_mktinfo.py @@ -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: