currencies.php
Helper functions that retrieve currencies.
Tags
Table of Contents
- load_currencies() : array<string|int, mixed>
- Takes an array of currency post_ids and instantiates them into an array of Currency objects.
- get_coingecko_currencies() : array<string|int, mixed>
- get_coingecko_platforms() : array<string|int, mixed>
- get_currency_ids_for_wallet() : array<string|int, mixed>
- Retrieve the currency IDs associated with the specified wallet.
- get_currencies_for_wallet() : array<string|int, mixed>
- Retrieve the currency or currencies associated with the specified wallet.
- get_currency_symbols_names_for_wallet() : array<string|int, mixed>
- Retrieves the sumbols and names for the currencies associated with the specified wallet.
- get_all_currencies() : array<string|int, Currency>
- Retrieve all published currencies.
- get_all_enabled_currencies() : array<string|int, Currency>
- Retrieve all enabled currencies.
- get_currencies_with_wallets_with_unlocked_adapters() : array<string|int, Currency>
- Gets all currencies backed by wallets with unlocked adapters. Useful for executing transactions on cron.
- get_first_currency_by_symbol() : Currency|null
- Retrieves the first currencies that has the specified ticker symbol.
- get_all_currencies_by_symbol() : array<string|int, mixed>
- Retrieves all currencies that match the specified ticker symbol.
- get_first_currency_by_coingecko_id() : Currency|null
- Retrieves a currency by its unique CoinGecko id.
- get_currency_ids() : array<string|int, mixed>
- Gets currency IDs by tag and status.
- get_all_fiat_currencies() : array<string|int, Currency>
- Retrieves all fiat currencies.
- get_all_cryptocurrencies() : array<string|int, Currency>
- Retrieves all cryptocurrencies.
- has_transactions() : bool
- Determines whether there are transactions for the specified currency.
- get_ids_for_coingecko_currencies_without_icon() : array<string|int, int>
- Retrieve all currencies with a CoinGecko ID, but without an icon assigned.
- get_currency_by_wallet_id_and_ticker_symbol() : Currency|null
- get_paged_currencies_with_coingecko_id() : array<string|int, Currency>
- Retrieve currencies having a CoinGecko ID, with pagination.
- get_vs_decimals() : int
Functions
load_currencies()
Takes an array of currency post_ids and instantiates them into an array of Currency objects.
    
                    load_currencies(array<string|int, mixed> $post_ids) : array<string|int, mixed>
        If a currency cannot be loaded due to Currency::load() throwing (i.e. bad DB data), then it is skipped and the rest of the currencies will be loaded.
Parameters
- $post_ids : array<string|int, mixed>
- 
                    The array of integer post_ids 
Tags
Return values
array<string|int, mixed> —The array of Currency objects.
get_coingecko_currencies()
    
                    get_coingecko_currencies() : array<string|int, mixed>
        
    
    
        Return values
array<string|int, mixed> —get_coingecko_platforms()
    
                    get_coingecko_platforms() : array<string|int, mixed>
        
    
    
        Return values
array<string|int, mixed> —get_currency_ids_for_wallet()
Retrieve the currency IDs associated with the specified wallet.
    
                    get_currency_ids_for_wallet( $wallet) : array<string|int, mixed>
    
        Parameters
Return values
array<string|int, mixed> —get_currencies_for_wallet()
Retrieve the currency or currencies associated with the specified wallet.
    
                    get_currencies_for_wallet( $wallet) : array<string|int, mixed>
    
        Parameters
Return values
array<string|int, mixed> —get_currency_symbols_names_for_wallet()
Retrieves the sumbols and names for the currencies associated with the specified wallet.
    
                    get_currency_symbols_names_for_wallet(Wallet $wallet) : array<string|int, mixed>
        Does not instantiate the currencies.
Parameters
- $wallet : Wallet
- 
                    The wallet to lookup. 
Return values
array<string|int, mixed> —An associative array of smybols to names.
get_all_currencies()
Retrieve all published currencies.
    
                    get_all_currencies() : array<string|int, Currency>
        Returns all currencies that are not drafts, pending review, trashed, etc. Some of these currencies may not be currently attached to wallets.
Return values
array<string|int, Currency> —The currencies found on the system.
get_all_enabled_currencies()
Retrieve all enabled currencies.
    
                    get_all_enabled_currencies([bool $with_wallet = true ]) : array<string|int, Currency>
        Useful for the WP REST API. Only returns currencies that are enabled (meta wallets_wallet_id exists and is a positive integer)
Parameters
- $with_wallet : bool = true
- 
                    If true, only returns currencies that have a valid, enabled adapter. 
Return values
array<string|int, Currency> —The enabled currencies found on the system.
get_currencies_with_wallets_with_unlocked_adapters()
Gets all currencies backed by wallets with unlocked adapters. Useful for executing transactions on cron.
    
                    get_currencies_with_wallets_with_unlocked_adapters([bool $include_fiat = true ]) : array<string|int, Currency>
    
        Parameters
- $include_fiat : bool = true
- 
                    Whether to include fiat currencies. 
Tags
Return values
array<string|int, Currency> —The found currencies.
get_first_currency_by_symbol()
Retrieves the first currencies that has the specified ticker symbol.
    
                    get_first_currency_by_symbol(string $symbol) : Currency|null
        This will only return the first currency that matches. There may be others, since ticker symbols are NOT unique.
Parameters
- $symbol : string
- 
                    The ticker symbol. Case sensitive. 
Tags
Return values
Currency|null —The currency found, or NULL if no currency matches.
get_all_currencies_by_symbol()
Retrieves all currencies that match the specified ticker symbol.
    
                    get_all_currencies_by_symbol(string $symbol) : array<string|int, mixed>
        There may be many currencies for one symbol, since ticker symbols are NOT unique.
Parameters
- $symbol : string
- 
                    The ticker symbol. Case sensitive. 
Tags
Return values
array<string|int, mixed> —The currencies found.
get_first_currency_by_coingecko_id()
Retrieves a currency by its unique CoinGecko id.
    
                    get_first_currency_by_coingecko_id(string $coingecko_id) : Currency|null
        This is the most reliable way to get a coin, if it's in the list of known CoinGecko coins. When creating/editing a coin, you should set the coingecko_id correctly for this to work.
Parameters
- $coingecko_id : string
- 
                    A unique id such as "bitcoin", "ethereum", etc. Case sensitive. 
Tags
Return values
Currency|null —The currency object from the DB, or null if not found.
get_currency_ids()
Gets currency IDs by tag and status.
    
                    get_currency_ids([string|array<string|int, mixed>|null $having_tag = null ][, string|array<string|int, mixed> $having_status = 'publish' ]) : array<string|int, mixed>
        This is useful for quickly getting the post_ids of currencies belonging to a specific group. e.g. Fixer currencies, fiat currencies, CP currencies, etc.
Parameters
- $having_tag : string|array<string|int, mixed>|null = null
- 
                    A term slug or array of term slugs. 
- $having_status : string|array<string|int, mixed> = 'publish'
- 
                    A post status (publish,draft,pending,trash) or array of post statuses. 
Return values
array<string|int, mixed> —Integer post ids for currencies found matching the query.
get_all_fiat_currencies()
Retrieves all fiat currencies.
    
                    get_all_fiat_currencies() : array<string|int, Currency>
        Fiat currencies are those that are assigned the fiat adapter. These are usually created via fixer.io, but can also be assigned manually.
Tags
Return values
array<string|int, Currency> —The found currencies.
get_all_cryptocurrencies()
Retrieves all cryptocurrencies.
    
                    get_all_cryptocurrencies() : array<string|int, Currency>
        Cryptocurrencies are the currencies that are not fiat currencies.
Tags
Return values
array<string|int, Currency> —The found currencies.
has_transactions()
Determines whether there are transactions for the specified currency.
    
                    has_transactions(Currency $currency) : bool
        Any trashed transactions are excluded, as well as cancelled/failed transactions. Only pending and done transactions count. This helper lets us know when it's safe to modify the number of decimals in a currency.
Parameters
- $currency : Currency
Tags
Return values
bool —get_ids_for_coingecko_currencies_without_icon()
Retrieve all currencies with a CoinGecko ID, but without an icon assigned.
    
                    get_ids_for_coingecko_currencies_without_icon() : array<string|int, int>
        Icons are assigned to currencies as featured images.
Return values
array<string|int, int> —The currency ids found.
get_currency_by_wallet_id_and_ticker_symbol()
    
                    get_currency_by_wallet_id_and_ticker_symbol(int $wallet_id, string $symbol) : Currency|null
    
        Parameters
- $wallet_id : int
- $symbol : string
- 
                    The ticker symbol. Case sensitive. 
Return values
Currency|null —The currency found, or NULL if no currency matches.
get_paged_currencies_with_coingecko_id()
Retrieve currencies having a CoinGecko ID, with pagination.
    
                    get_paged_currencies_with_coingecko_id([int $limit = 10 ], int $page) : array<string|int, Currency>
    
        Parameters
- $limit : int = 10
- $page : int
Return values
array<string|int, Currency> —The currencies found.
get_vs_decimals()
    
                    get_vs_decimals() : int