graphenecommon.amount module¶
-
class
graphenecommon.amount.
Amount
(*args, **kwargs)¶ Bases:
dict
,graphenecommon.instance.AbstractBlockchainInstanceProvider
This class deals with Amounts of any asset to simplify dealing with the tuple:
(amount, asset)
Parameters: - args (list) – Allows to deal with different representations of an amount
- amount (float) – Let’s create an instance with a specific amount
- asset (str) – Let’s you create an instance with a specific asset (symbol)
- blockchain_instance (instance) – instance to use when accesing a RPC
Returns: All data required to represent an Amount/Asset
Return type: dict
Raises: ValueError – if the data provided is not recognized
from peerplays.amount import Amount from peerplays.asset import Asset a = Amount("1 USD") b = Amount(1, "USD") c = Amount("20", self.asset_class("USD")) a + b a * 2 a += b a /= 2.0
Way to obtain a proper instance:
args
can be a string, e.g.: “1 USD”args
can be a dictionary containingamount
andasset_id
args
can be a dictionary containingamount
andasset
args
can be a list of afloat
andstr
(symbol)args
can be a list of afloat
and aasset.Asset
amount
andasset
are defined manually
An instance is a dictionary and comes with the following keys:
amount
(float)symbol
(str)asset
(instance ofasset.Asset
)
Instances of this class can be used in regular mathematical expressions (
+-*/%
) such as:Amount("1 USD") * 2 Amount("15 GOLD") + Amount("0.5 GOLD")
-
amount
¶ Returns the amount as float
-
asset
¶ Returns the asset as instance of
asset.Asset
-
copy
()¶ Copy the instance and make sure not to use a reference
-
json
()¶
-
symbol
¶ Returns the symbol of the asset
-
tuple
()¶