bitshares.amount module

class bitshares.amount.Amount(*args, **kwargs)[source]

Bases: bitshares.instance.BlockchainInstance, bitshares.amount.Amount

This class deals with Amounts of any asset to simplify dealing with the tuple:

(amount, asset)
  • 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 (bitshares.bitshares.BitShares) – BitShares instance

All data required to represent an Amount/Asset

Return type:



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", Asset("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 containing amount and asset_id
  • args can be a dictionary containing amount and asset
  • args can be a list of a float and str (symbol)
  • args can be a list of a float and a bitshares.asset.Asset
  • amount and asset are defined manually

An instance is a dictionary and comes with the following keys:

Instances of this class can be used in regular mathematical expressions (+-*/%) such as:

Amount("1 USD") * 2
Amount("15 GOLD") + Amount("0.5 GOLD")

Returns the amount as float


Returns the asset as instance of asset.Asset


Alias for the specific blockchain


alias of bitshares.instance.BlockchainInstance


Short form for blockchain (for the lazy)

clear() → None. Remove all items from D.

Copy the instance and make sure not to use a reference


Needs to define instance variables that provide classes


Returns a new dict with keys from iterable and values equal to value.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.

Should return the Chain instance class, e.g. bitshares.BitShares

classmethod inject(cls)
items() → a set-like object providing a view on D's items
keys() → a set-like object providing a view on D's keys
pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised

popitem() → (k, v), remove and return some (key, value) pair as a

2-tuple; but raise KeyError if D is empty.

static set_shared_blockchain_instance(instance)

This method allows us to override default instance for all users of SharedInstance.instance.

Parameters:instance (chaininstance) – Chain instance

This allows to set a config that will be used when calling shared_blockchain_instance and allows to define the configuration without requiring to actually create an instance

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D

This method will initialize SharedInstance.instance and return it. The purpose of this method is to have offer single default instance that can be reused by multiple classes.


Returns the symbol of the asset

update([E, ]**F) → None. Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() → an object providing a view on D's values