RateLimits
in package
uses
FormatsForDisplay
Represents rate limit information from API responses.
This value object holds rate limit data extracted from response headers. It will be reused by both the User response class and future automatic rate limit tracking.
Property names match the API header names (x-api-ratelimit-*):
- limit: Total credits allowed (from x-api-ratelimit-limit)
- remaining: Credits remaining (from x-api-ratelimit-remaining)
- reset: When rate limit resets (from x-api-ratelimit-reset)
- consumed: Credits consumed in current request (from x-api-ratelimit-consumed)
Table of Contents
Properties
- $consumed : int
- Number of credits consumed in the current request.
- $limit : int
- Total number of credits allowed in the current rate limit window.
- $remaining : int
- Number of credits remaining in the current rate limit window.
- $reset : Carbon
- Unix timestamp when the rate limit resets.
Methods
- __construct() : mixed
- RateLimits constructor.
- __toString() : string
- Returns a string representation of the rate limits.
- 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
$consumed
Number of credits consumed in the current request.
public
int
$consumed
Extracted from x-api-ratelimit-consumed header.
According to API documentation: "The quantity of credits that were consumed in the current request." This is NOT a cumulative count - it's the quantity consumed for the specific request that returned these headers.
Note: Most requests consume 1 credit, but bulk requests or options requests may consume multiple credits per request.
$limit
Total number of credits allowed in the current rate limit window.
public
int
$limit
Extracted from x-api-ratelimit-limit header.
$remaining
Number of credits remaining in the current rate limit window.
public
int
$remaining
Extracted from x-api-ratelimit-remaining header.
$reset
Unix timestamp when the rate limit resets.
public
Carbon
$reset
Extracted from x-api-ratelimit-reset header.
Methods
__construct()
RateLimits constructor.
public
__construct(int $limit, int $remaining, Carbon $reset, int $consumed) : mixed
Parameters
- $limit : int
-
Total number of credits allowed.
- $remaining : int
-
Number of credits remaining.
- $reset : Carbon
-
Timestamp when rate limit resets.
- $consumed : int
-
Number of credits consumed.
__toString()
Returns a string representation of the rate limits.
public
__toString() : string
Return values
string —Human-readable rate limit information.
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.