MarketData SDK

Candles extends ResponseBase
in package

Class Candles

Represents a collection of stock candles data and handles the response parsing.

Table of Contents

Properties

$_saved_filename  : string|null
$candles  : array<string|int, Candle>
Array of Candle objects representing individual candle data.
$next_time  : int|null
Unix time of the next quote if there is no data in the requested period, but there is data in a subsequent period.
$status  : string
The status of the response. Will always be "ok" when there is data for the candles requested.
$csv  : string
$html  : string

Methods

__construct()  : mixed
Constructs a new Candles object and parses the response data.
__toString()  : string
Returns a string representation of the candles collection.
createMerged()  : self
Create a Candles object from pre-merged data.
getCsv()  : string
Get the CSV content of the response.
getHtml()  : string
Get the HTML content of the response.
isCsv()  : bool
Check if the response is in CSV format.
isHtml()  : bool
Check if the response is in HTML format.
isJson()  : bool
Check if the response is in JSON format.
saveToFile()  : string
Save CSV/HTML content to a file.

Properties

$_saved_filename

public string|null $_saved_filename = null

The filename where the response was saved (if filename parameter was used).

$candles

Array of Candle objects representing individual candle data.

public array<string|int, Candle> $candles = []

$next_time

Unix time of the next quote if there is no data in the requested period, but there is data in a subsequent period.

public int|null $next_time = null

$status

The status of the response. Will always be "ok" when there is data for the candles requested.

public string $status = 'no_data'

$csv

protected string $csv

The CSV content of the response.

$html

protected string $html

The HTML content of the response.

Methods

__construct()

Constructs a new Candles object and parses the response data.

public __construct(object $response[, string|null $symbol = null ]) : mixed
Parameters
$response : object

The raw response object to be parsed.

$symbol : string|null = null

Optional symbol to associate with each candle. Used when the caller knows the symbol (e.g., single-symbol candles() requests).

__toString()

Returns a string representation of the candles collection.

public __toString() : string
Return values
string

Human-readable candles summary.

createMerged()

Create a Candles object from pre-merged data.

public static createMerged(string $status, array<string|int, Candle$candles[, int|null $nextTime = null ]) : self

This static factory method is used by the automatic concurrent request feature to create a Candles object from multiple merged responses.

Parameters
$status : string

The overall status ('ok' or 'no_data').

$candles : array<string|int, Candle>

Array of Candle objects.

$nextTime : int|null = null

Unix timestamp of next available data (for no_data status).

Return values
self

A new Candles instance with the merged data.

getCsv()

Get the CSV content of the response.

public getCsv() : string
Tags
throws
InvalidArgumentException

If the response is not in CSV format.

Return values
string

The CSV content.

getHtml()

Get the HTML content of the response.

public getHtml() : string
Tags
throws
InvalidArgumentException

If the response is not in HTML format.

Return values
string

The HTML content.

isCsv()

Check if the response is in CSV format.

public isCsv() : bool
Return values
bool

True if the response is in CSV format, false otherwise.

isHtml()

Check if the response is in HTML format.

public isHtml() : bool
Return values
bool

True if the response is in HTML format, false otherwise.

isJson()

Check if the response is in JSON format.

public isJson() : bool
Return values
bool

True if the response is in JSON format, false otherwise.

saveToFile()

Save CSV/HTML content to a file.

public saveToFile(string $filename) : string
Parameters
$filename : string

The file path to save to.

Tags
throws
InvalidArgumentException

If filename is invalid (wrong extension, etc.).

throws
RuntimeException

If file writing fails.

Return values
string

The absolute path of the saved file.


        
On this page

Search results