nectar.price module

class nectar.price.FilledOrder(order: Dict[str, Any], blockchain_instance: Any | None = None, **kwargs: Any)

Bases: Price

This class inherits nectar.price.Price but has the base and quote Amounts not only be used to represent the price (as a ratio of base and quote) but instead has those amounts represent the amounts of an actually filled order!

Parameters:

blockchain_instance (Hive) – Hive instance

Note

Instances of this class come with an additional date key that shows when the order has been filled!

json() Dict[str, Any]
class nectar.price.Order(base: Dict[str, Any] | Amount, quote: Amount | None = None, blockchain_instance: Any | None = None, **kwargs: Any)

Bases: Price

This class inherits nectar.price.Price but has the base and quote Amounts not only be used to represent the price (as a ratio of base and quote) but instead has those amounts represent the amounts of an actual order!

Parameters:

blockchain_instance (Hive) – Hive instance

Note

If an order is marked as deleted, it will carry the ‘deleted’ key which is set to True and all other data be None.

class nectar.price.Price(price: str | Dict[str, Any] | Price | None = None, base: str | Amount | Asset | None = None, quote: str | Amount | Asset | None = None, base_asset: str | None = None, blockchain_instance: Any | None = None)

Bases: dict

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

Note

The price (floating) is derived as base/quote

Parameters:
  • args (list) – Allows to deal with different representations of a price

  • base (Asset) – Base asset

  • quote (Asset) – Quote asset

  • blockchain_instance (Hive) – Hive instance

Returns:

All data required to represent a price

Return type:

dictionary

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 nectar.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 nectar.amount.Amount

  • args being a list of [quote, base] both being instances of str (amount symbol)

  • base and quote being instances of nectar.asset.Amount

This allows instantiations like:

  • Price("0.315 HBD/HIVE")

  • Price(0.315, base="HBD", quote="HIVE")

  • Price(0.315, base=Asset("HBD"), quote=Asset("HIVE"))

  • Price({"base": {"amount": 1, "asset_id": "HBD"}, "quote": {"amount": 10, "asset_id": "HBD"}})

  • Price(quote="10 HIVE", base="1 HBD")

  • Price("10 HIVE", "1 HBD")

  • Price(Amount("10 HIVE"), Amount("1 HBD"))

  • Price(1.0, "HBD/HIVE")

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

>>> from nectar.price import Price
>>> from nectar import Hive
>>> hv = Hive("https://api.hive.blog")
>>> Price("0.3314 HBD/HIVE", blockchain_instance=hv) * 2
0.662804 HBD/HIVE
>>> Price(0.3314, "HBD", "HIVE", blockchain_instance=hv)
0.331402 HBD/HIVE
as_base(base: str | Asset) Price

Return a copy of this Price expressed with the given asset as the base.

If base matches the current base symbol this returns a shallow copy. If base matches the current quote symbol this returns a copy with base and quote inverted. Raises InvalidAssetException if base is neither the base nor the quote of this price.

Parameters:

base (str): Asset symbol to use as the base (e.g., “HIVE” or “HBD”).

Returns:

Price: A new Price instance whose base asset is base.

as_quote(quote: str | Asset) Price

Return a Price instance expressed with the given quote asset symbol.

If quote matches the current quote symbol, returns a copy of this Price. If quote matches the current base symbol, returns a copied, inverted Price. A new object is always returned (the original is not modified).

Parameters:

quote (str): Asset symbol to use as the quote (e.g., “HBD” or “HIVE”).

Returns:

Price: A Price object with quote as the quote asset.

Raises:

InvalidAssetException: If quote does not match either the current base or quote symbol.

copy() Price

Return a shallow copy of the dict.

invert() Price

Invert the price in place, swapping base and quote assets (e.g., HBD/HIVE -> HIVE/HBD).

Returns:

self: The same Price instance after inversion.

Example:
>>> from nectar.price import Price
>>> from nectar import Hive
>>> hv = Hive("https://api.hive.blog")
>>> Price("0.3314 HBD/HIVE", blockchain_instance=hv).invert()
3.017483 HIVE/HBD
json() Dict[str, Any]
property market: Market

Open the corresponding market

Returns:

Instance of nectar.market.Market for the corresponding pair of assets.

symbols() Tuple[str, str]