MarketData SDK

MutualFunds
in package
uses UniversalParameters, ValidatesInputs

MutualFunds class for handling mutual fund-related API endpoints.

Table of Contents

Constants

BASE_URL  = "v1/funds/"

Properties

$client  : Client

Methods

__construct()  : mixed
MutualFunds constructor.
candles()  : Candles
Get historical price candles for a mutual fund.
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/funds/"

The base URL for mutual fund endpoints.

Properties

Methods

__construct()

MutualFunds constructor.

public __construct(Client $client) : mixed
Parameters
$client : Client

The Market Data API client instance.

candles()

Get historical price candles for a mutual fund.

public candles(string $symbol, string $from[, string|null $to = null ][, string $resolution = 'D' ][, int|null $countback = null ][, Parameters|null $parameters = null ]) : Candles
APIYes
Parameters
$symbol : string

The mutual fund's ticker symbol.

$from : string

The leftmost candle on a chart (inclusive). If you use countback, to is not required. Accepted timestamp inputs: ISO 8601, unix, spreadsheet.

$to : string|null = null

The rightmost candle on a chart (inclusive). Accepted timestamp inputs: ISO 8601, unix, spreadsheet.

$resolution : string = 'D'

The duration of each candle.

  • Minutely Resolutions: (minutely, 1, 3, 5, 15, 30, 45, ...)
  • Hourly Resolutions: (hourly, H, 1H, 2H, ...)
  • Daily Resolutions: (daily, D, 1D, 2D, ...)
  • Weekly Resolutions: (weekly, W, 1W, 2W, ...)
  • Monthly Resolutions: (monthly, M, 1M, 2M, ...)
  • Yearly Resolutions:(yearly, Y, 1Y, 2Y, ...)
$countback : int|null = null

Will fetch a number of candles before (to the left of) 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

see
Stocks::candles()

For stock candles

example

// Get daily candles for a mutual fund $candles = $client->mutual_funds->candles('VFINX', '2024-01-01', '2024-01-31');

// Get weekly candles $candles = $client->mutual_funds->candles('VFINX', '2023-01-01', '2023-12-31', 'W');

throws
GuzzleException|ApiException
Return values
Candles

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