Markets
in package
uses
UniversalParameters, ValidatesInputs
Markets class for handling market-related API endpoints.
Table of Contents
Constants
- BASE_URL = "v1/markets/"
Properties
Methods
- __construct() : mixed
- Markets constructor.
- status() : Statuses
- Get the market status for a specific country and date range.
- canParseAsDate() : bool
- Check if a string can be parsed as a date.
- execute() : object
- Execute a single API request with universal parameters.
- execute_in_parallel() : array<string|int, mixed>
- Execute multiple API requests in parallel with universal parameters.
- mergeParameters() : Parameters
- Merge method-level parameters with client default parameters.
- parseDateToTimestamp() : int|null
- Parse a date string to unix timestamp.
- validateCountryCode() : void
- Validate ISO 3166 two-letter country code.
- validateDateRange() : void
- Validate date range logic.
- validateNonEmptyArray() : void
- Validate that an array is non-empty.
- validateNonEmptyString() : void
- Validate that a string is non-empty.
- validateNumericRange() : void
- Validate that min < max when both are provided.
- validatePositiveInteger() : void
- Validate that an integer is positive if provided.
- validatePositiveNumber() : void
- Validate that a number (int or float) is positive if provided.
- validateResolution() : void
- Validate resolution format.
- validateSymbols() : void
- Validate symbols array (trim and ensure non-empty).
Constants
BASE_URL
public
string
BASE_URL
= "v1/markets/"
The base URL for market endpoints.
Properties
$client
private
Client
$client
The Market Data API client instance.
Methods
__construct()
Markets constructor.
public
__construct(Client $client) : mixed
Parameters
- $client : Client
-
The Market Data API client instance.
status()
Get the market status for a specific country and date range.
public
status([string $country = "US" ][, string|null $date = null ][, string|null $from = null ][, string|null $to = null ][, int|null $countback = null ][, Parameters|null $parameters = null ]) : Statuses
Get the past, present, or future status for a stock market. The endpoint will respond with "open" for trading days or "closed" for weekends or market holidays.
Parameters
- $country : string = "US"
-
The country. Use the two-digit ISO 3166 country code. If no country is specified, US will be assumed. Only countries that Market Data supports for stock price data are available (currently only the United States).
- $date : string|null = null
-
Consult whether the market was open or closed on the specified date. Accepted timestamp inputs: ISO 8601, unix, spreadsheet.
- $from : string|null = null
-
The earliest date (inclusive). If you use countback, from is not required. Accepted timestamp inputs: ISO 8601, unix, spreadsheet.
- $to : string|null = null
-
The last date (inclusive). Accepted timestamp inputs: ISO 8601, unix, spreadsheet.
- $countback : int|null = null
-
Countback will fetch a number of dates before to If you use from, countback is not required.
- $parameters : Parameters|null = null
-
Universal parameters for all methods (such as format).
Tags
Return values
StatusescanParseAsDate()
Check if a string can be parsed as a date.
protected
canParseAsDate(string|null $value) : bool
Similar to Python SDK's check_is_date() function. Returns true if the value contains "-" or "/" (indicating parseable date format) or is numeric (unix timestamp or spreadsheet format).
This allows relative dates ("today", "yesterday", "-5 days") and option expiration dates ("December expiration") to pass through without validation.
Parameters
- $value : string|null
-
The value to check
Return values
bool —True if the value can be parsed as a date
execute()
Execute a single API request with universal parameters.
protected
execute(string $method, array<string|int, mixed> $arguments, Parameters|null $parameters) : object
Parameters
- $method : string
-
The API method to call.
- $arguments : array<string|int, mixed>
-
The arguments for the API call.
- $parameters : Parameters|null
-
Optional Parameters object for additional settings.
Return values
object —The API response as an object.
execute_in_parallel()
Execute multiple API requests in parallel with universal parameters.
protected
execute_in_parallel(array<string|int, mixed> $calls[, Parameters|null $parameters = null ][, array<string|int, mixed>|null &$failedRequests = null ]) : array<string|int, mixed>
Parameters
- $calls : array<string|int, mixed>
-
An array of method calls, each containing the method name and arguments.
- $parameters : Parameters|null = null
-
Optional Parameters object for additional settings.
- $failedRequests : array<string|int, mixed>|null = null
-
Optional by-reference array to collect failed requests instead of throwing. When provided, exceptions are stored here keyed by their call index.
Tags
Return values
array<string|int, mixed> —An array of API responses. When $failedRequests is provided, results are keyed by original call index.
mergeParameters()
Merge method-level parameters with client default parameters.
protected
mergeParameters(Parameters|null $methodParams) : Parameters
Priority order (highest to lowest):
- Method-level parameters (if provided)
- Client default parameters ($this->client->default_params)
- Default Parameters() values
Parameters
- $methodParams : Parameters|null
-
Method-level parameters, or null to use only client defaults.
Return values
Parameters —Merged parameters instance.
parseDateToTimestamp()
Parse a date string to unix timestamp.
protected
parseDateToTimestamp(string|null $value) : int|null
Handles ISO 8601, unix timestamps, spreadsheet dates, and American format.
Parameters
- $value : string|null
-
The date string to parse
Return values
int|null —Unix timestamp or null if cannot be parsed
validateCountryCode()
Validate ISO 3166 two-letter country code.
protected
validateCountryCode(string $country) : void
Parameters
- $country : string
-
The country code to validate
Tags
validateDateRange()
Validate date range logic.
protected
validateDateRange(string|null $from, string|null $to[, int|null $countback = null ][, string $context = '' ]) : void
Rules:
- If
tois provided, it requires eitherfromORcountback(but not both) - If both
fromandtoare parseable dates, validates thatfrom<to - If
countbackis provided, it must be a positive integer
This allows relative dates and option expiration dates to pass through without strict format validation.
Parameters
- $from : string|null
-
The start date
- $to : string|null
-
The end date
- $countback : int|null = null
-
The countback value
- $context : string = ''
-
Optional context for error messages
Tags
validateNonEmptyArray()
Validate that an array is non-empty.
protected
validateNonEmptyArray(array<string|int, mixed> $value, string $fieldName) : void
Parameters
- $value : array<string|int, mixed>
-
The value to validate
- $fieldName : string
-
The field name for error messages
Tags
validateNonEmptyString()
Validate that a string is non-empty.
protected
validateNonEmptyString(string $value, string $fieldName) : void
Parameters
- $value : string
-
The value to validate
- $fieldName : string
-
The field name for error messages
Tags
validateNumericRange()
Validate that min < max when both are provided.
protected
validateNumericRange(float|null $min, float|null $max, string $minField, string $maxField) : void
Parameters
- $min : float|null
-
The minimum value
- $max : float|null
-
The maximum value
- $minField : string
-
The minimum field name for error messages
- $maxField : string
-
The maximum field name for error messages
Tags
validatePositiveInteger()
Validate that an integer is positive if provided.
protected
validatePositiveInteger(int|null $value, string $fieldName) : void
Parameters
- $value : int|null
-
The value to validate
- $fieldName : string
-
The field name for error messages
Tags
validatePositiveNumber()
Validate that a number (int or float) is positive if provided.
protected
validatePositiveNumber(int|float|null $value, string $fieldName) : void
Parameters
- $value : int|float|null
-
The value to validate
- $fieldName : string
-
The field name for error messages
Tags
validateResolution()
Validate resolution format.
protected
validateResolution(string $resolution) : void
Valid resolutions: minutely, hourly, daily, weekly, monthly, yearly, or numeric with optional suffix (1, 3, 5, 15, 30, 45, H, 1H, 2H, D, 1D, 2D, etc.)
Parameters
- $resolution : string
-
The resolution to validate
Tags
validateSymbols()
Validate symbols array (trim and ensure non-empty).
protected
validateSymbols(array<string|int, mixed> $symbols) : void
Parameters
- $symbols : array<string|int, mixed>
-
The symbols array to validate