bhive.amount module¶
-
class
bhive.amount.Amount(amount, asset=None, fixed_point_arithmetic=False, new_appbase_format=True, hive_instance=None)¶ Bases:
dictThis 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)
fixed_point_arithmetic (boolean) – when set to True, all operation are fixed point operations and the amount is always be rounded down to the precision
hive_instance (Hive) – Hive instance
- Returns
All data required to represent an Amount/Asset
- Return type
dict
- Raises
ValueError – if the data provided is not recognized
Way to obtain a proper instance:
argscan be a string, e.g.: “1 HBD”argscan be a dictionary containingamountandasset_idargscan be a dictionary containingamountandassetargscan be a list of afloatandstr(symbol)argscan be a list of afloatand abhive.asset.Assetamountandassetare defined manually
An instance is a dictionary and comes with the following keys:
amount(float)symbol(str)asset(instance ofbhive.asset.Asset)
Instances of this class can be used in regular mathematical expressions (
+-*/%) such as:from bhive.amount import Amount from bhive.asset import Asset a = Amount("1 HIVE") b = Amount(1, "HIVE") c = Amount("20", Asset("HIVE")) a + b a * 2 a += b a /= 2.0
2.000 HIVE 2.000 HIVE
-
property
amount¶ Returns the amount as float
-
property
amount_decimal¶ Returns the amount as decimal
-
property
asset¶ Returns the asset as instance of
hive.asset.Asset
-
copy()¶ Copy the instance and make sure not to use a reference
-
json()¶
-
property
symbol¶ Returns the symbol of the asset
-
tuple()¶
-
bhive.amount.check_asset(other, self)¶
-
bhive.amount.quantize(amount, precision)¶