Price

class bitshares.price.Price(*args, base=None, quote=None, base_asset=None, bitshares_instance=None)

This 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 bitshares.amount.Amount. The amount themselves define the price.

Note

The price (floating) is derived as base/quote

Parameters:
Returns:

All data required to represent a price

Return type:

dict

Way to obtain a proper instance:

  • args is a str with a price and two assets
  • args can be a floating number and base and quote being instances of bitshares.asset.Asset
  • args can be a floating number and base and quote being instances of str
  • args can be dict with keys price, base, and quote (graphene balances)
  • args can be dict with keys base and quote
  • args can be dict with key receives (filled orders)
  • args being a list of [quote, base] both being instances of bitshares.amount.Amount
  • args being a list of [quote, base] both being instances of str (amount symbol)
  • base and quote being instances of bitshares.asset.Amount

This allows instanciations like:

  • Price("0.315 USD/BTS")
  • Price(0.315, base="USD", quote="BTS")
  • Price(0.315, base=Asset("USD"), quote=Asset("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=Asset("1.3.0"))
  • Price(quote="10 GOLD", base="1 USD")
  • Price("10 GOLD", "1 USD")
  • Price(Amount("10 GOLD"), Amount("1 USD"))
  • Price(1.0, "USD/GOLD")

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

>>> from bitshares.price import Price
>>> Price("0.3314 USD/BTS") * 2
0.662600000 USD/BTS
invert()

Invert the price (e.g. go from USD/BTS into BTS/USD)

market

Open the corresponding market

Returns:Instance of bitshares.market.Market for the corresponding pair of assets.