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

Returns the amount as float

asset

Returns the asset as instance of asset.Asset

bitshares

Alias for the specific blockchain

blockchain
blockchain_instance_class

alias of bitshares.instance.BlockchainInstance

chain

Short form for blockchain (for the lazy)

clear() → None. Remove all items from D.
copy()[source]

Copy the instance and make sure not to use a reference

define_classes()[source]

Needs to define instance variables that provide classes

fromkeys()

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.
get_instance_class()

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
json()[source]
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
set_shared_config(config)

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
shared_blockchain_instance()

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.

symbol

Returns the symbol of the asset

tuple()[source]
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