Source code for tensortrade.oms.instruments.exchange_pair
fromdecimalimportDecimal
[docs]classExchangePair:"""A pair of financial instruments to be traded on a specific exchange. Parameters ---------- exchange : `Exchange` An exchange that contains the `pair` for trading. pair : `TradingPair` A trading pair available on the `exchange`. """def__init__(self,exchange:"Exchange",pair:"TradingPair"):self.exchange=exchangeself.pair=pair@propertydefprice(self)->"Decimal":"""The quoted price of the trading pair. (`Decimal`, read-only)"""returnself.exchange.quote_price(self.pair)@propertydefinverse_price(self)->"Decimal":"""The inverse price of the trading pair. (`Decimal, read-only)"""quantization=Decimal(10)**-self.pair.quote.precisionreturnDecimal(self.price**Decimal(-1)).quantize(quantization)def__hash__(self):returnhash(str(self))def__eq__(self,other):ifisinstance(other,ExchangePair):ifstr(self)==str(other):returnTruereturnFalsedef__str__(self):return"{}:{}".format(self.exchange.name,self.pair)def__repr__(self):returnstr(self)