DSWallets
Table of Contents
Classes
Constants
- CHART_TIMEFRAMES_ALLOWED = array('1m' => 60, '3m' => 180, '5m' => 300, '15m' => 900, '30m' => 1800, '1h' => 3600, '4h' => 14400, '1d' => 86400, '1w' => 604800)
- DEFAULT_EXCHANGE_FEE_MAKER = 0.15
- DEFAULT_EXCHANGE_FEE_TAKER = 0.25
- DEFAULT_EXCHANGE_MARKET_NOTATION = 'Q_B'
- DEFAULT_EXCHANGE_MARKET_POST_CONTENT = <<<CONTENT <table style="width: 100%; table-layout: fixed"> \t<thead> \t\t<tr> \t\t\t<th style="width: 50%;"></th><th style="width: 50%;"></th> \t\t</tr> \t</thead> \t<tbody> \t\t<tr> \t\t\t<td colspan="2">[wallets_exchange_market]</td> \t\t</tr> \t\t<tr> \t\t\t<td colspan="2">[wallets_exchange_chart]</td> \t\t</tr> \t\t<tr> \t\t\t<td style="vertical-align: top;"> \t\t\t\t<h2>Bids</h2> \t\t\t\t[wallets_exchange_bids] \t\t\t</td> \t\t\t<td style="vertical-align: top;"> \t\t\t\t<h2>Asks</h2> \t\t\t\t[wallets_exchange_asks] \t\t\t</td> \t\t</tr> \t\t<tr> \t\t\t<td style="vertical-align: top;">[wallets_exchange_market_buy]</td> \t\t\t<td style="vertical-align: top;">[wallets_exchange_market_sell]</td> \t\t</tr> \t\t<tr> \t\t\t<td style="vertical-align: top;">[wallets_exchange_limit_buy]</td> \t\t\t<td style="vertical-align: top;">[wallets_exchange_limit_sell]</td> \t\t</tr> \t\t<tr> \t\t\t<td colspan="2"> \t\t\t\t<h2>Market history</h2> \t\t\t\t[wallets_exchange_market_history] \t\t\t</td> \t\t</tr> \t\t<tr> \t\t\t<td colspan="2"> \t\t\t\t<h2>User orders</h2> \t\t\t\t[wallets_exchange_user_orders] \t\t\t</td> \t\t</tr> \t\t<tr> \t\t\t<td colspan="2"> \t\t\t\t<h2>User history</h2> \t\t\t\t[wallets_exchange_user_history] \t\t\t</td> \t\t</tr> \t</tbody> </table> CONTENT
- DEFAULT_EXCHANGE_MAX_RESULTS = 250
- DEFAULT_EXCHANGE_MEMOIZE_SECONDS = 5
- DEFAULT_EXCHANGE_RATE_LIMIT_DOS = 60
- DEFAULT_EXCHANGE_RATE_LIMIT_GETS = 0
- MARKET_META = ['quote_currency_id' => 'Quote currency. Bid orders buy this quote currency against the base currency.', 'base_currency_id' => 'Base currency. Ask orders sell the base currency against this base currency.', 'quote_amount_min' => 'The minimum size of an allowed trade in this market. Expressed in units of the quote currency.', 'quote_amount_max' => 'The maximum size of an allowed trade in this market. Expressed in units of the quote currency.', 'bid_disabled' => 'Whether to disallow bidding (i.e. buying the quote currency).', 'ask_disabled' => 'Whether to disallow asking (i.e. selling the quote currency).', 'cancel_disabled' => 'Whether to disallow cancelling orders.', 'rates_enabled' => 'Use price data from this market in the plugin.']
- MARKETS_MAX_SYMBOL_LENGTH = 10
- WALLETS_EXCHANGE_AXIS_BORDER_COLOR = '#2b2b43'
- WALLETS_EXCHANGE_COLOR_GREEN = '#00897b'
- WALLETS_EXCHANGE_COLOR_RED = '#fc4b6c'
- WALLETS_EXCHANGE_CROSSHAIR_COLOR = '#758696'
- WALLETS_EXCHANGE_CROSSHAIR_STYLE = 0
- WALLETS_EXCHANGE_CROSSHAIR_WIDTH = 1
- WALLETS_EXCHANGE_GRID_COLOR = '#d6dcde'
- WALLETS_EXCHANGE_LAYOUT_BACKGROUND_COLOR = '#ffffff'
- WALLETS_EXCHANGE_LAYOUT_FONT_SIZE = 11
- WALLETS_EXCHANGE_LAYOUT_TEXT_COLOR = '#191919'
- WALLETS_EXCHANGE_VOLUME_COLOR = '#888888'
Functions
- tab_exchange_exchange_cb() : mixed
- tab_exchange_api_cb() : mixed
- json_api_exchange_query_vars() : mixed
- json_api_parse_exchange_request() : mixed
- rate_limit() : mixed
- get_effective_exchange_user_id() : mixed
- Gets the effective user id, based on current login or API key.
- warn_if_not_zlib() : mixed
- verify_exchange_args_exist() : mixed
- cache_response() : mixed
- do_not_cache_response() : mixed
- superpwa_exclude_wallets_from_cache() : string
- Exclude JSON API from being cached by SuperPWA
- refresh_superpwa_exclusion_list() : mixed
- Forces SuperPWA to re-generate the service worker code once.
- api_market_order_filter() : mixed
- Inserts a new market order.
- api_limit_order_filter() : mixed
- Inserts a new limit order.
- api_cancel_order_action() : mixed
- Cancels an order.
- api_market_summary_filter() : mixed
- Returns market summaries.
- api_orders_filter() : mixed
- Returns orders.
- api_market_order_book_filter() : mixed
- Returns market order book.
- api_prices_filter() : mixed
- Returns historical market prices.
- api_trades_filter() : mixed
- Returns trades. Due to partially filled orders, one order can correspond to many trades.
- api_available_balance_exchange_filter() : array<string|int, mixed>
- Subtracts any amounts locked in open orders from the available balances of a user.
- guard_exchange_user_shortcodes() : mixed
- 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.
- check_order_amount_min_max() : mixed
- Checks if the amount to be traded is within admin limits.
- ensure_market_filled_orders() : mixed
- Ensure that no orders that are filled are stuck in "open" status
- save_exchange_trade_transactions() : mixed
- Saves all the transactions resulting from a trade.
- send_trade_notification_emails() : mixed
- Emails the two users about their trade
- wallets_market_meta_box_currencies() : mixed
- wallets_market_meta_box_orders() : mixed
- wallets_market_meta_box_rates() : mixed
Constants
CHART_TIMEFRAMES_ALLOWED
public
mixed
CHART_TIMEFRAMES_ALLOWED
= array('1m' => 60, '3m' => 180, '5m' => 300, '15m' => 900, '30m' => 1800, '1h' => 3600, '4h' => 14400, '1d' => 86400, '1w' => 604800)
DEFAULT_EXCHANGE_FEE_MAKER
public
mixed
DEFAULT_EXCHANGE_FEE_MAKER
= 0.15
DEFAULT_EXCHANGE_FEE_TAKER
public
mixed
DEFAULT_EXCHANGE_FEE_TAKER
= 0.25
DEFAULT_EXCHANGE_MARKET_NOTATION
public
mixed
DEFAULT_EXCHANGE_MARKET_NOTATION
= 'Q_B'
DEFAULT_EXCHANGE_MARKET_POST_CONTENT
public
mixed
DEFAULT_EXCHANGE_MARKET_POST_CONTENT
= <<<CONTENT
<table style="width: 100%; table-layout: fixed">
\t<thead>
\t\t<tr>
\t\t\t<th style="width: 50%;"></th><th style="width: 50%;"></th>
\t\t</tr>
\t</thead>
\t<tbody>
\t\t<tr>
\t\t\t<td colspan="2">[wallets_exchange_market]</td>
\t\t</tr>
\t\t<tr>
\t\t\t<td colspan="2">[wallets_exchange_chart]</td>
\t\t</tr>
\t\t<tr>
\t\t\t<td style="vertical-align: top;">
\t\t\t\t<h2>Bids</h2>
\t\t\t\t[wallets_exchange_bids]
\t\t\t</td>
\t\t\t<td style="vertical-align: top;">
\t\t\t\t<h2>Asks</h2>
\t\t\t\t[wallets_exchange_asks]
\t\t\t</td>
\t\t</tr>
\t\t<tr>
\t\t\t<td style="vertical-align: top;">[wallets_exchange_market_buy]</td>
\t\t\t<td style="vertical-align: top;">[wallets_exchange_market_sell]</td>
\t\t</tr>
\t\t<tr>
\t\t\t<td style="vertical-align: top;">[wallets_exchange_limit_buy]</td>
\t\t\t<td style="vertical-align: top;">[wallets_exchange_limit_sell]</td>
\t\t</tr>
\t\t<tr>
\t\t\t<td colspan="2">
\t\t\t\t<h2>Market history</h2>
\t\t\t\t[wallets_exchange_market_history]
\t\t\t</td>
\t\t</tr>
\t\t<tr>
\t\t\t<td colspan="2">
\t\t\t\t<h2>User orders</h2>
\t\t\t\t[wallets_exchange_user_orders]
\t\t\t</td>
\t\t</tr>
\t\t<tr>
\t\t\t<td colspan="2">
\t\t\t\t<h2>User history</h2>
\t\t\t\t[wallets_exchange_user_history]
\t\t\t</td>
\t\t</tr>
\t</tbody>
</table>
CONTENT
DEFAULT_EXCHANGE_MAX_RESULTS
public
mixed
DEFAULT_EXCHANGE_MAX_RESULTS
= 250
DEFAULT_EXCHANGE_MEMOIZE_SECONDS
public
mixed
DEFAULT_EXCHANGE_MEMOIZE_SECONDS
= 5
DEFAULT_EXCHANGE_RATE_LIMIT_DOS
public
mixed
DEFAULT_EXCHANGE_RATE_LIMIT_DOS
= 60
DEFAULT_EXCHANGE_RATE_LIMIT_GETS
public
mixed
DEFAULT_EXCHANGE_RATE_LIMIT_GETS
= 0
MARKET_META
public
mixed
MARKET_META
= ['quote_currency_id' => 'Quote currency. Bid orders buy this quote currency against the base currency.', 'base_currency_id' => 'Base currency. Ask orders sell the base currency against this base currency.', 'quote_amount_min' => 'The minimum size of an allowed trade in this market. Expressed in units of the quote currency.', 'quote_amount_max' => 'The maximum size of an allowed trade in this market. Expressed in units of the quote currency.', 'bid_disabled' => 'Whether to disallow bidding (i.e. buying the quote currency).', 'ask_disabled' => 'Whether to disallow asking (i.e. selling the quote currency).', 'cancel_disabled' => 'Whether to disallow cancelling orders.', 'rates_enabled' => 'Use price data from this market in the plugin.']
MARKETS_MAX_SYMBOL_LENGTH
public
mixed
MARKETS_MAX_SYMBOL_LENGTH
= 10
WALLETS_EXCHANGE_AXIS_BORDER_COLOR
public
mixed
WALLETS_EXCHANGE_AXIS_BORDER_COLOR
= '#2b2b43'
WALLETS_EXCHANGE_COLOR_GREEN
public
mixed
WALLETS_EXCHANGE_COLOR_GREEN
= '#00897b'
WALLETS_EXCHANGE_COLOR_RED
public
mixed
WALLETS_EXCHANGE_COLOR_RED
= '#fc4b6c'
WALLETS_EXCHANGE_CROSSHAIR_COLOR
public
mixed
WALLETS_EXCHANGE_CROSSHAIR_COLOR
= '#758696'
WALLETS_EXCHANGE_CROSSHAIR_STYLE
public
mixed
WALLETS_EXCHANGE_CROSSHAIR_STYLE
= 0
WALLETS_EXCHANGE_CROSSHAIR_WIDTH
public
mixed
WALLETS_EXCHANGE_CROSSHAIR_WIDTH
= 1
WALLETS_EXCHANGE_GRID_COLOR
public
mixed
WALLETS_EXCHANGE_GRID_COLOR
= '#d6dcde'
WALLETS_EXCHANGE_LAYOUT_BACKGROUND_COLOR
public
mixed
WALLETS_EXCHANGE_LAYOUT_BACKGROUND_COLOR
= '#ffffff'
WALLETS_EXCHANGE_LAYOUT_FONT_SIZE
public
mixed
WALLETS_EXCHANGE_LAYOUT_FONT_SIZE
= 11
WALLETS_EXCHANGE_LAYOUT_TEXT_COLOR
public
mixed
WALLETS_EXCHANGE_LAYOUT_TEXT_COLOR
= '#191919'
WALLETS_EXCHANGE_VOLUME_COLOR
public
mixed
WALLETS_EXCHANGE_VOLUME_COLOR
= '#888888'
Functions
tab_exchange_exchange_cb()
tab_exchange_exchange_cb(mixed $arg) : mixed
Parameters
- $arg : mixed
tab_exchange_api_cb()
tab_exchange_api_cb() : mixed
json_api_exchange_query_vars()
json_api_exchange_query_vars(mixed $vars) : mixed
Parameters
- $vars : mixed
json_api_parse_exchange_request()
json_api_parse_exchange_request(mixed $query) : mixed
Parameters
- $query : mixed
rate_limit()
rate_limit(mixed $action, mixed $user_id) : mixed
Parameters
- $action : mixed
- $user_id : mixed
get_effective_exchange_user_id()
Gets the effective user id, based on current login or API key.
get_effective_exchange_user_id() : mixed
In case of programmatic access, checks that the specified user_id matches with the API key passed. Checks the the wallets_api_key GET parameter, the Bearer HTTP_AUTHORIZATION header, and the Authorization header.
Tags
warn_if_not_zlib()
warn_if_not_zlib() : mixed
verify_exchange_args_exist()
verify_exchange_args_exist(mixed $arg_names) : mixed
Parameters
- $arg_names : mixed
cache_response()
cache_response(mixed $seconds_to_cache) : mixed
Parameters
- $seconds_to_cache : mixed
do_not_cache_response()
do_not_cache_response() : mixed
superpwa_exclude_wallets_from_cache()
Exclude JSON API from being cached by SuperPWA
superpwa_exclude_wallets_from_cache(string $superpwa_sw_never_cache_urls) : string
Parameters
- $superpwa_sw_never_cache_urls : string
-
Comma separated list of regex patterns that match against request URL.
Tags
Return values
string —The modified list of regex patterns.
refresh_superpwa_exclusion_list()
Forces SuperPWA to re-generate the service worker code once.
refresh_superpwa_exclusion_list() : mixed
Newly generated code takes into account the URL exclusion list (superpwa_sw_never_cache_urls
filter)
that allows this plugin's JSON API to pass through.
api_market_order_filter()
Inserts a new market order.
api_market_order_filter([int $order_id = null ][, array<string|int, mixed> $args = [] ]) : mixed
Triggers the FIFO matching engine. The order is executed at current market rates.
Example: User 3
wants to buy 100000
Dogecoins with Bitcoin at current market rate.
$order_id = apply_filters(
'wallets_api_market_order',
null,
array(
'user_id' => 3,
'market_id' => 123, // here 123 is the post_id of the BTC_DOGE market
'amount' => 100000,
'direction' => 'bid',
)
);
Example: The following code hooks after order execution (priority > 10). Use this to notify users, send emails, notifications, etc.
add_filter(
'wallets_api_market_order',
function( $order_id, $args ) {
if ( is_null( $oder_id ) ) {
error_log(
sprintf(
'It was not possible for user %d to place a market %s order for %f on the %d market',
$args['user_id'],
$args['direction'],
$args['amount'],
$args['market_id']
)
);
} else {
error_log(
sprintf(
'User %d placed a market %s order for %f on the %d market',
$args['user_id'],
$args['direction'],
$args['amount'],
$args['market_id']
)
);
}
},
11,
2
);
Parameters
- $order_id : int = null
-
If order is placed successfully, order id will go here.
- $args : array<string|int, mixed> = []
-
Array of arguments to this filter:
- integer
user_id
→ (Optional) ID of the user who places the order. Default is current user. - float
amount
→ The amount to trade with this order. Expressed in units of the quote symbol. - int
market_id
→ Uniquely specifies a market via its post_id. Either specify this, or base/quote symbols. - string
base_symbol
→ The base symbol of the market where this order is to be placed. - string
quote_symbol
→ The quote symbol of the market where this order is to be placed. - string
direction
→ Must be one ofbid
orask
. - boolean 'check_capabilities' → (Optional) Whether to check for the appropriate user capabilities. Default is
true
.
- integer
Tags
api_limit_order_filter()
Inserts a new limit order.
api_limit_order_filter([int $order_id = null ][, array<string|int, mixed> $args = [] ]) : mixed
Triggers the FIFO matching engine. The new limit order is matched against the current orderbook, and either gets filled, or remains partially filled.
Example: User 3
wants to buy 100000
Dogecoins with Bitcoin at a rate of 40
Satoshi.
$order_id = apply_filters(
'wallets_api_limit_order',
null,
array(
'user_id' => 3,
'market_id' => 123, // here 123 is the post_id of the BTC_DOGE market
'amount' => 100000,
'rate' => 0.00000040,
'direction' => 'bid',
)
);
Example: The following code hooks after order execution (priority > 10). Use this to notify users, send emails, notifications, etc.
add_filter(
'wallets_api_limit_order',
function( $order_id, $args ) {
if ( is_null( $oder_id ) ) {
error_log(
sprintf(
'It was not possible for user %d to place a limit %s order for %f on the %d market',
$args['user_id'],
$args['direction'],
$args['amount'],
$args['market_id']
)
);
} else {
error_log(
sprintf(
'User %d placed a limit %s order for %f on the %d market',
$args['user_id'],
$args['direction'],
$args['amount'],
$args['market_id']
)
);
}
},
11,
2
);
Parameters
- $order_id : int = null
-
If order is placed successfully, order id will go here.
- $args : array<string|int, mixed> = []
-
Array of arguments to this filter:
- integer
user_id
→ (Optional) ID of the user who places the order. Default is current user. - float
amount
→ The amount to trade with this order. Expressed in units of the quote symbol. - int
market_id
→ Uniquely specifies a market via its post_id. Either specify this, or base/quote symbols. - string
base_symbol
→ The base symbol of the market where this order is to be placed. - string
quote_symbol
→ The quote symbol of the market where this order is to be placed. - float
rate
The exchange rate for this limit order. - string
direction
→ Must be one ofbid
orask
. - boolean 'check_capabilities' → (Optional) Whether to check for the appropriate user capabilities. Default is
true
.
- integer
Tags
api_cancel_order_action()
Cancels an order.
api_cancel_order_action([array<string|int, mixed> $args = [] ]) : mixed
If the order has already been partially filled, then its status is set to filled
.
If the order has NOT yet been partially filled, then its status is set to cancelled
.
Example: Cancel order with ID O5b041284d64cb
placed by user 3
.
do_action(
'wallets_api_cancel_order',
array(
'user_id' => 3,
'order_id' => 'O5b041284d64cb',
)
);
Parameters
- $args : array<string|int, mixed> = []
-
Array of arguments to this action:
- integer 'order_id' → The ID of the order to cancel. This is the ID that starts with the letter "O".
- integer 'user_id' $rarr; (Optional) The ID of the user who placed this order. Default is the current user ID.
- boolean 'check_capabilities' → (Optional) Whether to check for the appropriate user capabilities. Default is
true
.
Tags
api_market_summary_filter()
Returns market summaries.
api_market_summary_filter([array<string|int, mixed> $market = [] ][, array<string|int, mixed> $args = [] ]) : mixed
Example: Retrieve the market summaries for the BTC_DOGE market.
$market_summary = apply_filters( 'wallets_api_market_summary', null, array( 'market_id' => 123, // here 123 is the post_id of the BTC_DOGE market ) );
Parameters
- $market : array<string|int, mixed> = []
-
Market summary will go here
- $args : array<string|int, mixed> = []
-
Array of arguments to this filter:
- int
market_id
→ Uniquely specifies a market via its post_id. Either specify this, or base/quote symbols. - string
base_symbol
→ The base symbol of the market whose summary is to be retrieved. - string
quote_symbol
→ The quote symbol of the market whose summary is to be retrieved.
- int
Tags
api_orders_filter()
Returns orders.
api_orders_filter([array<string|int, mixed> $orders = [] ][, array<string|int, mixed> $args = [] ]) : mixed
Example: User 3
wants to view their open orders on all markets.
$order_history = apply_filters(
'wallets_api_orders',
null,
array(
'user_id' => 3,
'open' => true,
)
);
Example: User 3
wants to view their order history on the DOGE_BTC market.
$order_history = apply_filters(
'wallets_api_orders',
null,
array(
'user_id' => 3,
'market_id' => 123, // here 123 is the post_id of the BTC_DOGE market
'filled' => true,
'cancelled' => true,
)
);
Example: Current user wants to view their currently cancelled orders that were created in the last 24 hours.
$order_history = apply_filters(
'wallets_api_orders',
null,
array(
'cancelled' => true,
'from_timestamp' => time() - DAY_IN_SECONDS
)
);
Parameters
- $orders : array<string|int, mixed> = []
-
Order data will go here
- $args : array<string|int, mixed> = []
-
Array of arguments to this filter:
- integer|string
user_id
→ (Optional) ID of the user who places the order. Default is current user. If set to the stringall
, orders for all users are returned. - int
market_id
→ (Optional) Uniquely specifies a market via its post_id. Either specify this, or base/quote symbols. - string
base_symbol
→ (Optional) The base symbol of the market whose orders are to be retrieved. If defined,quote_symbol
must also be defined. - string
quote_symbol
→ (Optional) The quote symbol of the market whose orders are to be retrieved. If defined,base_symbol
must also be defined. - bool
open
→ (Optional) Whether to retrieved open orders. - bool
filled
→ (Optional) Whether to retrieved filled orders. - bool
cancelled
(Optional) → Whether to retrieved cancelled orders. - integer
from_timestamp
(Optional) → Retrieve orders that have been created after this UNIX epoch timestamp (seconds). Default is 0. - integer
to_timestamp
(Optional) → Retrieve orders that have been created before this UNIX epoch timestamp (seconds). Default is current timestamp. - boolean 'check_capabilities' → (Optional) Whether to check for the appropriate user capabilities. Default is
true
. - integer
max_results
→ (Optional) Retrieve up to this many rows. Default is admin setting "Max Results".
- integer|string
Tags
api_market_order_book_filter()
Returns market order book.
api_market_order_book_filter([array<string|int, mixed> $book = [] ][, array<string|int, mixed> $args = [] ]) : mixed
Example: Retrieve the market orderbook for the DOGE_BTC market.
$market_order_book = apply_filters( 'wallets_api_market_order_book', null, array( 'market_id' => 123, // here 123 is the post_id of the BTC_DOGE market ) );
Parameters
- $book : array<string|int, mixed> = []
-
Orderbook data will be returned here
- $args : array<string|int, mixed> = []
-
Array of arguments to this filter:
- int
market_id
→ Uniquely specifies a market via its post_id. Either specify this, or base/quote symbols. - string
base_symbol
→ The base symbol of the market whose orderbook is to be retrieved. - string
quote_symbol
→ The quote symbol of the market whose orderbook is to be retrieved.
- int
Tags
api_prices_filter()
Returns historical market prices.
api_prices_filter([array<string|int, mixed> $prices = [] ][, array<string|int, mixed> $args = [] ]) : mixed
Example: Retrieve last 24 hours of OHLC historical price data for the DOGE_BTC market at a 5 minute timeframe.
$market_prices = apply_filters( 'wallets_api_prices', null, array( 'market_id' => 123, // here 123 is the post_id of the BTC_DOGE market 'timeframe' => '5m', 'from_timestamp' => time() - DAY_IN_SECONDS, ) );
Parameters
- $prices : array<string|int, mixed> = []
-
Price data will be returned here.
- $args : array<string|int, mixed> = []
-
Array of arguments to this filter:
- int
market_id
→ Uniquely specifies a market via its post_id. Either specify this, or base/quote symbols. - string
base_symbol
→ The base symbol of the market whose price history is to be retrieved. - string
quote_symbol
→ The quote symbol of the market whose price history is to be retrieved. - string
timeframe
→ One of1m
,3m
,5m
,15m
,30m
,1h
,4h
,1d
,1w
. - integer
from_timestamp
(Optional) → Retrieve prices from trades that occurred after this UNIX epoch timestamp (seconds). Default is 0. - integer
to_timestamp
(Optional) → Retrieve prices from trades that occurred before this UNIX epoch timestamp (seconds). Default is current timestamp.
- int
Tags
api_trades_filter()
Returns trades. Due to partially filled orders, one order can correspond to many trades.
api_trades_filter([array<string|int, mixed> $trades = [] ][, array<string|int, mixed> $args = [] ]) : mixed
Example: User 3
wants to view their trade history on all markets.
$trade_history = apply_filters(
'wallets_api_trades',
null,
array(
'user_id' => 3,
)
);
Example: User 3
wants to view their trade history on the DOGE_BTC market.
$trade_history = apply_filters(
'wallets_api_trades',
null,
array(
'user_id' => 3,
'market_id' => 123, // here 123 is the post_id of the BTC_DOGE market
)
);
Example: Current user wants to view their trades over the last 24 hours.
$trade_history = apply_filters(
'wallets_api_trades',
null,
array(
'from_timestamp' => time() - DAY_IN_SECONDS
)
);
Example: A user wants to view the market history on the DOGE_BTC_market.
$trade_history = apply_filters(
'wallets_api_trades',
null,
array(
'market_id' => 123, // here 123 is the post_id of the BTC_DOGE market
)
);
Parameters
- $trades : array<string|int, mixed> = []
-
Trades data will be returned here.
- $args : array<string|int, mixed> = []
-
Array of arguments to this filter:
- integer|string
user_id
→ (Optional) ID of the user whose trades to return. Default is current user. If set to the stringall
, trades for all users are returned. - int
market_id
→ (Optional) Uniquely specifies a market via its post_id. Either specify this, or base/quote symbols. - string
base_symbol
→ (Optional) The base symbol of the market whose trades are to be retrieved. If defined,quote_symbol
must also be defined. - string
quote_symbol
→ (Optional) The quote symbol of the market whose trades are to be retrieved. If defined,base_symbol
must also be defined. - integer
from_timestamp
(Optional) → Retrieve trades that have been created after this UNIX epoch timestamp (seconds). Default is 0. - integer
to_timestamp
(Optional) → Retrieve trades that have been created before this UNIX epoch timestamp (seconds). Default is current timestamp. - boolean 'check_capabilities' → (Optional) Whether to check for the appropriate user capabilities. Default is
true
. - integer
max_results
→ (Optional) Retrieve up to this many rows. Default is admin setting "Max Results".
- integer|string
Tags
api_available_balance_exchange_filter()
Subtracts any amounts locked in open orders from the available balances of a user.
api_available_balance_exchange_filter(array<string|int, mixed> $balances, int $user_id) : array<string|int, mixed>
Retrieves the sum of amounts locked in open orders.
Parameters
- $balances : array<string|int, mixed>
-
Assoc array of currency_ids to user's available balances. We'll subtract from these amounts.
- $user_id : int
-
The user whose balances we are modifying.
Tags
Return values
array<string|int, mixed> —The available balances assoc array, after the amounts locked in orders are subtracted.
guard_exchange_user_shortcodes()
guard_exchange_user_shortcodes([mixed $caps = ['has_wallets', 'trade_funds_in_wallet'] ]) : mixed
Parameters
- $caps : mixed = ['has_wallets', 'trade_funds_in_wallet']
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
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
-
market_id
attribute -
base_symbol
andquote_symbol
attributes -
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
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:
- Market specified by post_id, with the
market_id
attribute. - Market specified by name, with the
base_symbol
andquote_symbol
attributes. - Market corresponding to the current post, if the current post displayed is of type
wallets_market
. - 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
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
stringget_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
check_order_amount_min_max()
Checks if the amount to be traded is within admin limits.
check_order_amount_min_max(int $currency_id, float $amount) : mixed
If the exchange rate is not known, it will succeed silently.
Parameters
- $currency_id : int
-
The currency transacted
- $amount : float
-
The amount transacted.
Tags
ensure_market_filled_orders()
Ensure that no orders that are filled are stuck in "open" status
ensure_market_filled_orders(mixed $table_name_orders) : mixed
Parameters
- $table_name_orders : mixed
save_exchange_trade_transactions()
Saves all the transactions resulting from a trade.
save_exchange_trade_transactions(array<string|int, mixed> $txs_and_tags_to_save) : mixed
Transactions are ordered and come in quadruplets. Every second tx must have the previous one as parent.
Parameters
- $txs_and_tags_to_save : array<string|int, mixed>
-
Array of array tuples, consisting of: 'tx' => Transaction object 'tags' => array of tag slugs (strings).
send_trade_notification_emails()
Emails the two users about their trade
send_trade_notification_emails(array<string|int, mixed> $txns_and_tags_to_email) : mixed
The transactions must correspond to the same trade. The function parses the transactions, summarizes the data, renders the data using the email template and enqueues the emails.
Parameters
- $txns_and_tags_to_email : array<string|int, mixed>
wallets_market_meta_box_currencies()
wallets_market_meta_box_currencies(mixed $post, mixed $meta_box) : mixed
Parameters
- $post : mixed
- $meta_box : mixed
wallets_market_meta_box_orders()
wallets_market_meta_box_orders(mixed $post, mixed $meta_box) : mixed
Parameters
- $post : mixed
- $meta_box : mixed
wallets_market_meta_box_rates()
wallets_market_meta_box_rates(mixed $post, mixed $meta_box) : mixed
Parameters
- $post : mixed
- $meta_box : mixed