MarketData SDK

Stocks
in package
uses UniversalParameters

Stocks class for handling stock-related API endpoints.

Table of Contents

Constants

BASE_URL  = "v1/stocks/"

Properties

$client  : Client

Methods

__construct()  : mixed
Stocks constructor.
bulkCandles()  : BulkCandles
Get bulk candle data for stocks.
bulkQuotes()  : BulkQuotes
Get real-time price quotes for multiple stocks in a single API request.
candles()  : Candles
Get historical price candles for an index.
earnings()  : Earnings
Get historical earnings per share data or a future earnings calendar for a stock.
news()  : News
Retrieve news articles for a given stock symbol within a specified date range.
quote()  : Quote
Get a real-time price quote for a stock.
quotes()  : Quotes
Get real-time price quotes for multiple stocks by doing parallel requests.
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.

Constants

BASE_URL

public string BASE_URL = "v1/stocks/"

The base URL for stock endpoints.

Properties

$client

private Client $client

The Market Data API client instance.

Methods

__construct()

Stocks constructor.

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

The Market Data API client instance.

bulkCandles()

Get bulk candle data for stocks.

public bulkCandles([array<string|int, mixed> $symbols = [] ][, string $resolution = 'D' ][, bool $snapshot = false ][, string|null $date = null ][, bool $adjust_splits = false ][, Parameters|null $parameters = null ]) : BulkCandles

Get bulk candle data for stocks. This endpoint returns bulk daily candle data for multiple stocks. Unlike the standard candles endpoint, this endpoint returns a single daily for each symbol provided. The typical use-case for this endpoint is to get a complete market snapshot during trading hours, though it can also be used for bulk snapshots of historical daily candles.

Parameters
$symbols : array<string|int, mixed> = []

The ticker symbols to return in the response, separated by commas. The symbols parameter may be omitted if the snapshot parameter is set to true.

$resolution : string = 'D'

The duration of each candle. Only daily candles are supported at this time. Daily Resolutions: (daily, D, 1D, 2D, ...)

$snapshot : bool = false

Returns candles for all available symbols for the date indicated. The symbols parameter can be omitted if snapshot is set to true.

$date : string|null = null

The date of the candles to be returned. If no date is specified, during market hours the candles returned will be from the current session. If the market is closed the candles will be from the most recent session. Accepted timestamp inputs: ISO 8601, unix, spreadsheet.

$adjust_splits : bool = false

Adjust historical data for historical splits and reverse splits. Market Data uses the CRSP methodology for adjustment. Daily candles default: true.

$parameters : Parameters|null = null

Universal parameters for all methods (such as format).

Tags
throws
ApiException
throws
GuzzleException
Return values
BulkCandles

bulkQuotes()

Get real-time price quotes for multiple stocks in a single API request.

public bulkQuotes([array<string|int, mixed> $symbols = [] ][, bool $snapshot = false ][, Parameters|null $parameters = null ]) : BulkQuotes

The bulkQuotes endpoint is designed to return hundreds of symbols at once or full market snapshots. Response times for less than 50 symbols will be quicker using the standard quotes endpoint and sending your requests in parallel.

Parameters
$symbols : array<string|int, mixed> = []

The ticker symbols to return in the response, separated by commas. The symbols parameter may be omitted if the snapshot parameter is set to true.

$snapshot : bool = false

Returns a full market snapshot with quotes for all symbols when set to true. The symbols parameter may be omitted if the snapshot parameter is set.

$parameters : Parameters|null = null

Universal parameters for all methods (such as format).

Tags
throws
GuzzleException
throws
Exception
Return values
BulkQuotes

candles()

Get historical price candles for an index.

public candles(string $symbol, string $from[, string|null $to = null ][, string $resolution = 'D' ][, int|null $countback = null ][, string|null $exchange = null ][, bool $extended = false ][, string|null $country = null ][, bool $adjust_splits = false ][, bool $adjust_dividends = false ][, Parameters|null $parameters = null ]) : Candles
Parameters
$symbol : string

The company'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.

$exchange : string|null = null

Use to specify the exchange of the ticker. This is useful when you need to specify a stock that quotes on several exchanges with the same symbol. You may specify the exchange using the EXCHANGE ACRONYM, MIC CODE, or two digit YAHOO FINANCE EXCHANGE CODE. If no exchange is specified symbols will be matched to US exchanges first.

$extended : bool = false

Include extended hours trading sessions when returning intraday candles. Daily resolutions never return extended hours candles. The default is false.

$country : string|null = null

Use to specify the country of the exchange (not the country of the company) in conjunction with the symbol argument. This argument is useful when you know the ticker symbol and the country of the exchange, but not the exchange code. Use the two digit ISO 3166 country code. If no country is specified, US exchanges will be assumed.

$adjust_splits : bool = false

Adjust historical data for for historical splits and reverse splits. Market Data uses the CRSP methodology for adjustment. Daily candles default: true. Intraday candles default: false.

$adjust_dividends : bool = false

CAUTION: Adjusted dividend data is planned for the future, but not yet implemented. All data is currently returned unadjusted for dividends. Market Data uses the CRSP methodology for adjustment. Daily candles default: true. Intraday candles default: false.

$parameters : Parameters|null = null

Universal parameters for all methods (such as format).

Tags
throws
GuzzleException|ApiException
Return values
Candles

earnings()

Get historical earnings per share data or a future earnings calendar for a stock.

public earnings(string $symbol[, string|null $from = null ][, string|null $to = null ][, int|null $countback = null ][, string|null $date = null ][, string|null $datekey = null ][, Parameters|null $parameters = null ]) : Earnings

Premium subscription required.

Parameters
$symbol : string

The company's ticker symbol.

$from : string|null = null

The earliest earnings report to include in the output. If you use countback, from is not required.

$to : string|null = null

The latest earnings report to include in the output.

$countback : int|null = null

Countback will fetch a specific number of earnings reports before to. If you use from, countback is not required.

$date : string|null = null

Retrieve a specific earnings report by date.

$datekey : string|null = null

Retrieve a specific earnings report by date and quarter. Example: 2023-Q4. This allows you to retrieve a 4th quarter value without knowing the company's specific fiscal year.

$parameters : Parameters|null = null

Universal parameters for all methods (such as format).

Tags
throws
ApiException
throws
GuzzleException
Return values
Earnings

news()

Retrieve news articles for a given stock symbol within a specified date range.

public news(string $symbol[, string|null $from = null ][, string|null $to = null ][, int|null $countback = null ][, string|null $date = null ][, Parameters|null $parameters = null ]) : News

CAUTION: This endpoint is in beta.

Parameters
$symbol : string

The ticker symbol of the stock.

$from : string|null = null

The earliest news to include in the output. If you use countback, from is not required.

$to : string|null = null

The latest news to include in the output.

$countback : int|null = null

Countback will fetch a specific number of news before to. If you use from, countback is not required.

$date : string|null = null

Retrieve news for a specific day.

$parameters : Parameters|null = null

Universal parameters for all methods (such as format).

Tags
throws
InvalidArgumentException
Return values
News

quote()

Get a real-time price quote for a stock.

public quote(string $symbol[, bool $fifty_two_week = false ][, Parameters|null $parameters = null ]) : Quote
Parameters
$symbol : string

The company's ticker symbol.

$fifty_two_week : bool = false

Enable the output of 52-week high and 52-week low data in the quote output. By default this parameter is false if omitted.

$parameters : Parameters|null = null

Universal parameters for all methods (such as format).

Tags
throws
GuzzleException|ApiException
Return values
Quote

quotes()

Get real-time price quotes for multiple stocks by doing parallel requests.

public quotes(array<string|int, mixed> $symbols[, bool $fifty_two_week = false ][, Parameters|null $parameters = null ]) : Quotes
Parameters
$symbols : array<string|int, mixed>

The ticker symbols to return in the response.

$fifty_two_week : bool = false

Enable the output of 52-week high and 52-week low data in the quote output.

$parameters : Parameters|null = null

Universal parameters for all methods (such as format).

Tags
throws
Throwable
Return values
Quotes

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>
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.

Tags
throws
Throwable
Return values
array<string|int, mixed>

An array of API responses.


        
On this page

Search results