MarketData SDK

Settings
in package

Settings class for MarketDataApp SDK.

Handles configuration loading from environment variables and .env files. Provides automatic token resolution with proper precedence order.

Table of Contents

Constants

API_STATUS_CACHE_VALIDITY  = 300
Cache validity period for API status.
MAX_CONCURRENT_REQUESTS  = 50
Maximum number of concurrent requests allowed for the entire API.
REFRESH_API_STATUS_INTERVAL  = 270
Refresh interval for API status cache.

Properties

$dotenvLoaded  : bool

Methods

getDefaultParameters()  : Parameters
Get default universal parameters from environment variables and .env file.
getLogLevel()  : string
Get the logging level from environment variable MARKETDATA_LOGGING_LEVEL.
getToken()  : string
Get the API token with automatic resolution from multiple sources.
getDotenvToken()  : string|null
Get token from .env file.
getEnvBool()  : bool|null
Get boolean value from environment variable.
getEnvColumns()  : array<string|int, mixed>|null
Get columns array from environment variable MARKETDATA_COLUMNS.
getEnvDateFormat()  : DateFormat|null
Get date format from environment variable MARKETDATA_DATE_FORMAT.
getEnvFormat()  : Format
Get format from environment variable MARKETDATA_OUTPUT_FORMAT.
getEnvMode()  : Mode|null
Get mode from environment variable MARKETDATA_MODE.
getEnvToken()  : string|null
Get token from environment variables.
getEnvValue()  : string|null
Get environment variable value from multiple sources.
loadDotenv()  : void
Load .env file if it exists.

Constants

API_STATUS_CACHE_VALIDITY

Cache validity period for API status.

public int API_STATUS_CACHE_VALIDITY = 300

Cache is considered valid for this duration (5 minutes). After this time, cache is stale and blocking refresh is required.

Cache validity in seconds.

MAX_CONCURRENT_REQUESTS

Maximum number of concurrent requests allowed for the entire API.

public int MAX_CONCURRENT_REQUESTS = 50

This is a hard limit enforced across all parallel request operations, not just specific endpoints. The SDK uses Guzzle's EachPromise to maintain a sliding window of this many concurrent requests - as soon as one completes, the next one starts, maintaining optimal throughput.

This limit applies to:

  • Direct calls to execute_in_parallel()
  • Automatic date range splitting for intraday candles
  • Bulk quote requests via stocks->quotes()
  • Any other parallel request operations

Maximum concurrent requests.

REFRESH_API_STATUS_INTERVAL

Refresh interval for API status cache.

public int REFRESH_API_STATUS_INTERVAL = 270

Cache should be refreshed when this interval has elapsed (4 minutes 30 seconds). This is the window before cache expiration where we trigger async refresh.

Refresh interval in seconds.

Properties

$dotenvLoaded

private static bool $dotenvLoaded = false

Flag to track if .env file has been loaded

Methods

getDefaultParameters()

Get default universal parameters from environment variables and .env file.

public static getDefaultParameters() : Parameters

Reads universal parameters from environment variables with the following precedence:

  1. Environment variables (getenv, $_ENV, $_SERVER)
  2. .env file (loaded via Dotenv)
  3. Default values (null or Format::JSON for format)
Return values
Parameters

Parameters instance with values from environment, or defaults if not set.

getLogLevel()

Get the logging level from environment variable MARKETDATA_LOGGING_LEVEL.

public static getLogLevel() : string
Return values
string

Log level (DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICAL, ALERT, EMERGENCY, or NONE). Defaults to INFO if not set.

getToken()

Get the API token with automatic resolution from multiple sources.

public static getToken([string|null $explicitToken = null ]) : string

Token resolution order (highest to lowest priority):

  1. Explicit token (passed as parameter)
  2. Environment variable (MARKETDATA_TOKEN)
  3. .env file (MARKETDATA_TOKEN)
  4. Empty string (fallback for free symbols)
Parameters
$explicitToken : string|null = null

The token explicitly passed to the constructor, if any.

Return values
string

The resolved token.

getDotenvToken()

Get token from .env file.

private static getDotenvToken() : string|null

Searches for .env file starting from current working directory, then searches up the directory tree (max 5 levels).

Return values
string|null

The token from .env file, or null if not found.

getEnvBool()

Get boolean value from environment variable.

private static getEnvBool(string $varName) : bool|null

Accepts: "true", "false", "1", "0" (case-insensitive)

Parameters
$varName : string

Environment variable name.

Return values
bool|null

Boolean value, or null if not set or invalid.

getEnvColumns()

Get columns array from environment variable MARKETDATA_COLUMNS.

private static getEnvColumns() : array<string|int, mixed>|null

Expects comma-separated string, e.g., "symbol,ask,bid"

Return values
array<string|int, mixed>|null

Array of column names, or null if not set or empty.

getEnvDateFormat()

Get date format from environment variable MARKETDATA_DATE_FORMAT.

private static getEnvDateFormat() : DateFormat|null
Return values
DateFormat|null

DateFormat enum value, or null if not set or invalid.

getEnvFormat()

Get format from environment variable MARKETDATA_OUTPUT_FORMAT.

private static getEnvFormat() : Format
Return values
Format

Format enum value, or Format::JSON if not set or invalid.

getEnvMode()

Get mode from environment variable MARKETDATA_MODE.

private static getEnvMode() : Mode|null
Return values
Mode|null

Mode enum value, or null if not set or invalid.

getEnvToken()

Get token from environment variables.

private static getEnvToken() : string|null
Return values
string|null

The token from environment, or null if not found.

getEnvValue()

Get environment variable value from multiple sources.

private static getEnvValue(string $varName) : string|null

Checks in order:

  1. getenv()
  2. $_ENV
  3. $_SERVER
  4. .env file (via Dotenv, which populates $_ENV/$_SERVER)
Parameters
$varName : string

Environment variable name.

Return values
string|null

Environment variable value, or null if not found.

loadDotenv()

Load .env file if it exists.

private static loadDotenv() : void

Searches for .env file starting from current working directory, then searches up the directory tree (max 5 levels).


        
On this page

Search results