graphenecommon.aio.price module¶
-
class
graphenecommon.aio.price.Price(*args, base=None, quote=None, base_asset=None, **kwargs)¶ Bases:
graphenecommon.price.PriceThis 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/quoteParameters: - 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:
argsis a str with a price and two assetsargscan be a floating number andbaseandquotebeing instances ofasset.Assetargscan be a floating number andbaseandquotebeing instances ofstrargscan be dict with keysprice,base, andquote(graphene balances)argscan be dict with keysbaseandquoteargscan be dict with keyreceives(filled orders)argsbeing a list of[quote, base]both being instances ofamount.Amountargsbeing a list of[quote, base]both being instances ofstr(amount symbol)baseandquotebeing 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/BTSintoBTS/USD)