Bitcoin and Altcoin Wallets: Exchange 2.3.3

markets.php

Helper functions that retrieve markets and market data.

Tags
author

Alexandros Georgiou info@dashed-slug.net

Table of Contents

get_market_ids()  : array<string|int, mixed>
get_market_id_by_symbols()  : int|null
Get a market ID by the base and quote symbols.
get_market_by_args()  : WP_Post
Parses shortcode arguments to determine the specified market via any of the following methods:
get_the_market_id()  : int|null
Gets the currently applicable market for shortcode UIs.
get_market_name()  : string
get_existing_market_migration_hashes()  : array<string|int, mixed>
Retrieve migration hashes for existing market posts.
check_market_order_amount_min_max()  : void
Check if amount is within range allowed by market settings.

Functions

get_market_ids()

get_market_ids([mixed $include_private = true ]) : array<string|int, mixed>
Parameters
$include_private : mixed = true
Return values
array<string|int, mixed>

get_market_id_by_symbols()

Get a market ID by the base and quote symbols.

get_market_id_by_symbols(string $base, string $quote) : int|null

Nowadays we store currency_ids, since the ticker symbols are not unique.

Therefore, there may be more than one markets matching the specified symbols. Only one market id is returned.

Parameters
$base : string

Ticker symbol for the base currency.

$quote : string

Ticker symbol for the quote currency.

Tags
since
2.0.0
Return values
int|null

Post id of the matching market, or null if none found.

get_market_by_args()

Parses shortcode arguments to determine the specified market via any of the following methods:

get_market_by_args(array<string|int, mixed> $atts) : WP_Post
  1. market_id attribute
  2. base_symbol and quote_symbol attributes
  3. market attribute (string of the form BASE_QUOTE )
Parameters
$atts : array<string|int, mixed>

The shortcode attributes, potentially containing one or more market specifiers.

Tags
throws
Exception

If a market could not be determined

Return values
WP_Post

The market post found.

get_the_market_id()

Gets the currently applicable market for shortcode UIs.

get_the_market_id(array<string|int, mixed> $atts) : int|null

The algorithm that selects a market uses the following priorities:

  1. Market specified by post_id, with the market_id attribute.
  2. Market specified by name, with the base_symbol and quote_symbol attributes.
  3. Market corresponding to the current post, if the current post displayed is of type wallets_market.
  4. Market specified by name using the legacy post meta value _wallets_default_market. For compatibility with wallets 5.x.
Parameters
$atts : array<string|int, mixed>

The attributes passed to the shortcode currently being displayed.

Tags
throws
Exception

If a market cannot be resolved from the available data.

Return values
int|null

The post_id for the market to display or null if it could not be determined.

get_market_name()

get_market_name(WP_Post $market_post) : string
Parameters
$market_post : WP_Post
Return values
string

get_existing_market_migration_hashes()

Retrieve migration hashes for existing market posts.

get_existing_market_migration_hashes() : array<string|int, mixed>

Before, markets were rows in an array. Now they are posts of a custom post type, wallets-market. Each market that was created via the migration task holds a meta key with the unique hash of the array inputs. This way the market can be migrated without deleting the original data, but can only be created once.

Return values
array<string|int, mixed>

check_market_order_amount_min_max()

Check if amount is within range allowed by market settings.

check_market_order_amount_min_max(int $base_currency_id, int $amount) : void

Checks if the amount is within the allowed range. If it is not, throws an exception. If the amount is in range, or if the exchange rate between BTC and the market's base currency is not known, then this function does nothing, therefore allowing the trade to proceed.

Parameters
$base_currency_id : int

The ticker symbol of the market's base currency

$amount : int

The value of the trade expressed in the market's base currency.

Tags
throws
Exception

If amount is not in range or the base currency id is not valid.

Return values
void

Search results