Source code for tensortrade.oms.instruments.trading_pair
# Copyright 2019 The TensorTrade Authors.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the LicensefromtypingimportAnyfromtensortrade.core.exceptionsimportInvalidTradingPair
[docs]classTradingPair:"""A pair of financial instruments to be traded on an exchange. Parameters ---------- base : `Instrument` The base instrument of the trading pair. quote : `Instrument` The quote instrument of the trading pair. Raises ------ InvalidTradingPair Raises if base and quote instrument are equal. """def__init__(self,base:"Instrument",quote:"Instrument")->None:ifbase==quote:raiseInvalidTradingPair(base,quote)self.base=baseself.quote=quotedef__hash__(self)->int:returnhash(str(self))def__eq__(self,other:"Any")->bool:ifisinstance(other,TradingPair):ifstr(self)==str(other):returnTruereturnFalsedef__ne__(self,other:"Any")->bool:returnnotself.__eq__(other)def__str__(self)->str:return"{}/{}".format(self.base.symbol,self.quote.symbol)def__repr__(self)->str:returnstr(self)