Quote
extends ResponseBase
in package
uses
FormatsForDisplay
Class Quote
Represents a stock quote and handles the response parsing for stock quote data.
Table of Contents
Properties
- $_saved_filename : string|null
- $ask : float|null
- The ask price of the stock.
- $ask_size : int|null
- The number of shares offered at the ask price.
- $bid : float|null
- The bid price.
- $bid_size : int|null
- The number of shares that may be sold at the bid price.
- $change : float|null
- The difference in price in dollars (or the security's currency if different from dollars) compared to the closing price of the previous day.
- $change_percent : float|null
- The difference in price in percent, expressed as a decimal, compared to the closing price of the previous day.
- $fifty_two_week_high : float|null
- The 52-week high for the stock. This parameter is omitted unless the optional 52week request parameter is set to true.
- $fifty_two_week_low : float|null
- The 52-week low for the stock. This parameter is omitted unless the optional 52week request parameter is set to true.
- $last : float|null
- The last price the stock traded at.
- $mid : float|null
- The midpoint price between the ask and the bid.
- $status : string
- The status of the response. Will always be "ok" when there is data for the symbol requested.
- $symbol : string
- The symbol of the stock.
- $updated : Carbon|null
- The date/time of the current stock quote.
- $volume : int|null
- The number of shares traded during the current session.
- $csv : string
- $html : string
Methods
- __construct() : mixed
- Constructs a new Quote object and parses the response data.
- __toString() : string
- Returns a string representation of the quote.
- 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.
- formatChange() : string
- Format a change value with sign and currency (e.g., "+$1.25" or "-$0.50").
- formatCurrency() : string
- Format a float as currency (e.g., "$150.25").
- formatDate() : string
- Format a Carbon date without time (e.g., "Jan 24, 2026").
- formatDateTime() : string
- Format a Carbon date with time (e.g., "Jan 24, 2026 3:45 PM").
- formatGreek() : string
- Format a Greek value (4 decimal places, e.g., "0.4520").
- formatNumber() : string
- Format a number with commas (e.g., "15,234").
- formatPercent() : string
- Format a percentage with sign (e.g., "+3.25%" or "-1.50%").
- formatPercentRaw() : string
- Format a percentage that is already in percent form (e.g., "32.50%").
- formatVolume() : string
- Format volume with K/M/B suffixes (e.g., "54.9M", "12.3K").
Properties
$_saved_filename
public
string|null
$_saved_filename
= null
The filename where the response was saved (if filename parameter was used).
$ask
The ask price of the stock.
public
float|null
$ask
= null
$ask_size
The number of shares offered at the ask price.
public
int|null
$ask_size
= null
$bid
The bid price.
public
float|null
$bid
= null
$bid_size
The number of shares that may be sold at the bid price.
public
int|null
$bid_size
= null
$change
The difference in price in dollars (or the security's currency if different from dollars) compared to the closing price of the previous day.
public
float|null
$change
= null
$change_percent
The difference in price in percent, expressed as a decimal, compared to the closing price of the previous day.
public
float|null
$change_percent
= null
For example, a 30% change will be represented as 0.30.
$fifty_two_week_high
The 52-week high for the stock. This parameter is omitted unless the optional 52week request parameter is set to true.
public
float|null
$fifty_two_week_high
= null
$fifty_two_week_low
The 52-week low for the stock. This parameter is omitted unless the optional 52week request parameter is set to true.
public
float|null
$fifty_two_week_low
= null
$last
The last price the stock traded at.
public
float|null
$last
= null
$mid
The midpoint price between the ask and the bid.
public
float|null
$mid
= null
$status
The status of the response. Will always be "ok" when there is data for the symbol requested.
public
string
$status
= 'no_data'
$symbol
The symbol of the stock.
public
string
$symbol
= ''
$updated
The date/time of the current stock quote.
public
Carbon|null
$updated
= null
$volume
The number of shares traded during the current session.
public
int|null
$volume
= null
$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 Quote object and parses the response data.
public
__construct(object $response) : mixed
Parameters
- $response : object
-
The raw response object to be parsed.
__toString()
Returns a string representation of the quote.
public
__toString() : string
Return values
string —Human-readable quote data.
getCsv()
Get the CSV content of the response.
public
getCsv() : string
Tags
Return values
string —The CSV content.
getHtml()
Get the HTML content of the response.
public
getHtml() : string
Tags
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
Return values
string —The absolute path of the saved file.
formatChange()
Format a change value with sign and currency (e.g., "+$1.25" or "-$0.50").
protected
formatChange(float|null $value) : string
Parameters
- $value : float|null
-
The change value to format.
Return values
string —Formatted change string or "N/A" if null.
formatCurrency()
Format a float as currency (e.g., "$150.25").
protected
formatCurrency(float|null $value) : string
Parameters
- $value : float|null
-
The value to format.
Return values
string —Formatted currency string or "N/A" if null.
formatDate()
Format a Carbon date without time (e.g., "Jan 24, 2026").
protected
formatDate(Carbon|null $date) : string
Parameters
- $date : Carbon|null
-
The date to format.
Return values
string —Formatted date string or "N/A" if null.
formatDateTime()
Format a Carbon date with time (e.g., "Jan 24, 2026 3:45 PM").
protected
formatDateTime(Carbon|null $date) : string
Parameters
- $date : Carbon|null
-
The date to format.
Return values
string —Formatted date string or "N/A" if null.
formatGreek()
Format a Greek value (4 decimal places, e.g., "0.4520").
protected
formatGreek(float|null $value) : string
Parameters
- $value : float|null
-
The Greek value to format.
Return values
string —Formatted Greek string or "N/A" if null.
formatNumber()
Format a number with commas (e.g., "15,234").
protected
formatNumber(int|null $value) : string
Parameters
- $value : int|null
-
The number to format.
Return values
string —Formatted number string or "N/A" if null.
formatPercent()
Format a percentage with sign (e.g., "+3.25%" or "-1.50%").
protected
formatPercent(float|null $value) : string
Assumes input is a decimal (0.30 = 30%).
Parameters
- $value : float|null
-
The decimal value to format as percentage.
Return values
string —Formatted percentage string or "N/A" if null.
formatPercentRaw()
Format a percentage that is already in percent form (e.g., "32.50%").
protected
formatPercentRaw(float|null $value) : string
Use this for values like implied volatility that are already percentages.
Parameters
- $value : float|null
-
The percentage value to format.
Return values
string —Formatted percentage string or "N/A" if null.
formatVolume()
Format volume with K/M/B suffixes (e.g., "54.9M", "12.3K").
protected
formatVolume(int|null $value) : string
Parameters
- $value : int|null
-
The volume to format.
Return values
string —Formatted volume string or "N/A" if null.