graphenecommon.price module¶
-
class
graphenecommon.price.
Price
(*args, base=None, quote=None, base_asset=None, **kwargs)¶ Bases:
dict
,graphenecommon.instance.AbstractBlockchainInstanceProvider
This class deals with all sorts of prices of any pair of assets to simplify dealing with the tuple:
(quote, base)
each being an instance of
amount.Amount
. The amount themselves define the price.Note
The price (floating) is derived as
base/quote
Parameters: - args (list) – Allows to deal with different representations of a price
- base (asset.Asset) – Base asset
- quote (asset.Asset) – Quote asset
- blockchain_instance (instance) – instance to use when accesing a RPC
Returns: All data required to represent a price
Return type: dict
Way to obtain a proper instance:
args
is a str with a price and two assetsargs
can be a floating number andbase
andquote
being instances ofasset.Asset
args
can be a floating number andbase
andquote
being instances ofstr
args
can be dict with keysprice
,base
, andquote
(graphene balances)args
can be dict with keysbase
andquote
args
can be dict with keyreceives
(filled orders)args
being a list of[quote, base]
both being instances ofamount.Amount
args
being a list of[quote, base]
both being instances ofstr
(amount symbol
)base
andquote
being instances ofasset.Amount
This allows instanciations like:
Price("0.315 USD/BTS")
Price(0.315, base="USD", quote="BTS")
Price(0.315, base=self.asset_class("USD"), quote=self.asset_class("BTS"))
Price({"base": {"amount": 1, "asset_id": "1.3.0"}, "quote": {"amount": 10, "asset_id": "1.3.106"}})
Price({"receives": {"amount": 1, "asset_id": "1.3.0"}, "pays": {"amount": 10, "asset_id": "1.3.106"}}, base_asset=self.asset_class("1.3.0"))
Price(quote="10 GOLD", base="1 USD")
Price("10 GOLD", "1 USD")
Price(self.amount_class("10 GOLD"), self.amount_class("1 USD"))
Price(1.0, "USD/GOLD")
Instances of this class can be used in regular mathematical expressions (
+-*/%
) such as:>>> from price import Price >>> Price("0.3314 USD/BTS") * 2 0.662600000 USD/BTS
-
as_base
(base)¶ Returns the price instance so that the base asset is
base
.Note: This makes a copy of the object!
-
as_quote
(quote)¶ Returns the price instance so that the quote asset is
quote
.Note: This makes a copy of the object!
-
copy
() → a shallow copy of D¶
-
invert
()¶ Invert the price (e.g. go from
USD/BTS
intoBTS/USD
)
-
json
()¶ - return {
- “base”: self[“base”].json(), “quote”: self[“quote”].json()
}
-
symbols
()¶