MarketData SDK

Markets
in package
uses UniversalParameters, ValidatesInputs

Markets class for handling market-related API endpoints.

Table of Contents

Constants

BASE_URL  = "v1/markets/"

Properties

$client  : Client

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
APIYes

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
link

API Documentation

example

// Get current market status $status = $client->markets->status();

// Check if market was open on a specific date $status = $client->markets->status(date: '2024-01-01');

// Get market calendar for a date range $status = $client->markets->status(from: '2024-01-01', to: '2024-01-31');

throws
GuzzleException|ApiException
Return values
Statuses

canParseAsDate()

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
throws
Throwable

When $failedRequests is not provided and any request fails.

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):

  1. Method-level parameters (if provided)
  2. Client default parameters ($this->client->default_params)
  3. 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
throws
InvalidArgumentException

If country code is invalid

validateDateRange()

Validate date range logic.

protected validateDateRange(string|null $from, string|null $to[, int|null $countback = null ][, string $context = '' ]) : void

Rules:

  • If to is provided, it requires either from OR countback (but not both)
  • If both from and to are parseable dates, validates that from < to
  • If countback is 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
throws
InvalidArgumentException

If validation fails

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
throws
InvalidArgumentException

If array is empty

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
throws
InvalidArgumentException

If value is empty

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
throws
InvalidArgumentException

If min >= max

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
throws
InvalidArgumentException

If value is not positive

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
throws
InvalidArgumentException

If value is not positive

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
throws
InvalidArgumentException

If resolution is invalid

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

Tags
throws
InvalidArgumentException

If symbols array is invalid


        
On this page

Search results