Currency

class Currency ( unicode code , uint8_t precision , uint16_t iso4217 , unicode name , CurrencyType currency_type )

Bases: object

Represents a medium of exchange in a specified denomination with a fixed decimal precision.

Handles up to 9 decimals of precision.

Parameters
  • code ( str ) – The currency code.

  • precision ( uint8 ) – The currency decimal precision.

  • iso4217 ( uint16 ) – The currency ISO 4217 code.

  • name ( str ) – The currency name.

  • currency_type ( CurrencyType ) – The currency type.

Raises
  • ValueError – If code is not a valid string.

  • OverflowError – If precision is negative (< 0).

  • ValueError – If precision greater than 9.

  • ValueError – If name is not a valid string.

code

Return the currency code.

Returns

str

currency_type

Return the currency type.

Returns

CurrencyType

static from_str ( unicode code , bool strict=False )

Parse a currency from the given string (if found).

Parameters
  • code ( str ) – The code of the currency to get.

  • strict ( bool , default False ) – If strict mode is enabled. If not strict mode then it’s very likely a Cryptocurrency, so for robustness will then return a new Cryptocurrency using the code and a default precision of 8.

Returns

Currency or None

static is_crypto ( unicode code )

Return a value indicating whether a currency with the given code is CRYPTO .

Parameters

code ( str ) – The code of the currency.

Returns

bool – True if CRYPTO , else False.

Raises

ValueError – If code is not a valid string.

static is_fiat ( unicode code )

Return a value indicating whether a currency with the given code is FIAT .

Parameters

code ( str ) – The code of the currency.

Returns

bool – True if FIAT , else False.

Raises

ValueError – If code is not a valid string.

iso4217

Return the currency ISO 4217 code.

Returns

str

name

Return the currency name.

Returns

str

precision

Return the currency decimal precision.

Returns

uint8

static register ( Currency currency , bool overwrite=False )

Register the given currency.

Will override the internal currency map.

Parameters
  • currency ( Currency ) – The currency to register

  • overwrite ( bool ) – If the currency in the internal currency map should be overwritten.