Skip to content

Repository files navigation

Polygon PHP Client - RESTful APIs

Welcome to the official PHP client library for the Polygon REST and WebSocket API. To get started, please see the Getting Started section in our documentation, view the API documentation directory for code snippets, or see the Model documentation to learn more about the data structures.

This version is an experimental release and is under active development. We are working to add more features and improve its stability and performance. Please be aware that this version might undergo significant changes, and some functionality may be incomplete or subject to modification.

Roadmap Features

  • Pagination over next_url and combine result sets: We plan to introduce enhanced pagination capabilities that will allow users to easily navigate through API responses using the next_url provided and seamlessly combine result sets for comprehensive data analysis.
  • Adding Tracing: To aid in debugging and enhance transparency, we aim to implement tracing features that will allow users to log detailed information about their API requests. This includes the requested URL, parameters, and full request and response headers.
  • WebSocket Support: In our effort to provide real-time data access, we will be integrating WebSocket support into the client library. This will enable users to establish persistent connections for live data feeds with minimal latency.

Installation & Usage

Prerequisites

Before installing the Polygon PHP client, ensure your environment has PHP 7.4 or higher, compatible with PHP 8.0.

Composer

To install the bindings via Composer, add the following to composer.json:

{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/polygon-io/client-php.git"
}
],
"require": {
"GIT_USER_ID/GIT_REPO_ID": "*@dev"
}
}

Then run composer install

Manual Installation

Download the files and include autoload.php:

<?phprequire_once('/path/to/PolygonClient/vendor/autoload.php');

Getting Started

To get started, please follow the installation procedure and then explore the API documentation directory for code snippets, or see the Model documentation to learn more about the data structures.

The free tier of our API comes with usage limitations, which might lead to rate limit errors if these limits are exceeded. For uninterrupted access and to support larger data requirements, we recommend reviewing our subscription plans, which are tailored for a wide range of needs from development to high-demand enterprise applications. Visit our pricing page for detailed information on limits and features to ensure a seamless experience, especially for real-time data processing.

REST API Client

Import and configure the OpenAPI Client.

<?phprequire_once(__DIR__ . '/vendor/autoload.php');
// Load API key from environment variable$apiKey = getenv('POLYGON_API_KEY');
// Check if the API key is not emptyif (!$apiKey) {
die('API key is not set in environment variables.');
}
// Configure API key authorization: apiKey$config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setApiKey('apiKey', $apiKey);

Using the Client

Request data using client methods.

// https://polygon.io/docs/stocks/get_v2_last_trade__stocksticker$apiInstance = newOpenAPI\Client\Api\StockslasttradeApi(
newGuzzleHttp\Client(),
$config
);
$stocks_ticker = "TSLA";
try {
$result = $apiInstance->lastTrade($stocks_ticker);
print_r($result);
} catch (Exception$e) {
echo'Exception when calling StockslasttradeApi->lastTrade: ', $e->getMessage(), PHP_EOL;
}

API Endpoints

All URIs are relative to api.polygon.io:

ClassMethodHTTP requestDescription
CrpytoaggregatesApicryptoEMAGET /v1/indicators/ema/{cryptoTicker}Exponential Moving Average (EMA)
CrpytoaggregatesApicryptoRSIGET /v1/indicators/rsi/{cryptoTicker}Relative Strength Index (RSI)
CrpytoaggregatesApicryptoSMAGET /v1/indicators/sma/{cryptoTicker}Simple Moving Average (SMA)
CryptoaggregatesApicryptoMACDGET /v1/indicators/macd/{cryptoTicker}Moving Average Convergence/Divergence (MACD)
CryptoaggregatesApiv2AggsGroupedLocaleGlobalMarketCryptoDateGetGET /v2/aggs/grouped/locale/global/market/crypto/{date}Grouped Daily (Bars)
CryptoaggregatesApiv2AggsTickerCryptoTickerPrevGetGET /v2/aggs/ticker/{cryptoTicker}/prevPrevious Close
CryptoaggregatesApiv2AggsTickerCryptoTickerRangeMultiplierTimespanFromToGetGET /v2/aggs/ticker/{cryptoTicker}/range/{multiplier}/{timespan}/{from}/{to}Aggregates (Bars)
CryptolasttradeApilastTradeCryptoGET /v1/last/crypto/{from}/{to}Last Trade for a Crypto Pair
CryptoopenCloseApiv1OpenCloseCryptoFromToDateGetGET /v1/open-close/crypto/{from}/{to}/{date}Daily Open/Close
CryptosnapshotApiv2SnapshotLocaleGlobalMarketsCryptoDirectionGetGET /v2/snapshot/locale/global/markets/crypto/{direction}Gainers/Losers
CryptosnapshotApiv2SnapshotLocaleGlobalMarketsCryptoTickersGetGET /v2/snapshot/locale/global/markets/crypto/tickersAll Tickers
CryptosnapshotApiv2SnapshotLocaleGlobalMarketsCryptoTickersTickerBookGetGET /v2/snapshot/locale/global/markets/crypto/tickers/{ticker}/bookTicker Full Book (L2)
CryptosnapshotApiv2SnapshotLocaleGlobalMarketsCryptoTickersTickerGetGET /v2/snapshot/locale/global/markets/crypto/tickers/{ticker}Ticker
CryptotradesApitradesCryptoGET /v3/trades/{cryptoTicker}Trades
CryptotradesApiv1HistoricCryptoFromToDateGetGET /v1/historic/crypto/{from}/{to}/{date}Historic Crypto Trades
DefaultApisnapshotSummaryGET /v1/summariesSummaries
DefaultApisnapshotsGET /v3/snapshotUniversal Snapshot
FxaggregatesApiforexEMAGET /v1/indicators/ema/{fxTicker}Exponential Moving Average (EMA)
FxaggregatesApiforexMACDGET /v1/indicators/macd/{fxTicker}Moving Average Convergence/Divergence (MACD)
FxaggregatesApiforexRSIGET /v1/indicators/rsi/{fxTicker}Relative Strength Index (RSI)
FxaggregatesApiforexSMAGET /v1/indicators/sma/{fxTicker}Simple Moving Average (SMA)
FxaggregatesApiv2AggsGroupedLocaleGlobalMarketFxDateGetGET /v2/aggs/grouped/locale/global/market/fx/{date}Grouped Daily (Bars)
FxaggregatesApiv2AggsTickerForexTickerPrevGetGET /v2/aggs/ticker/{forexTicker}/prevPrevious Close
FxaggregatesApiv2AggsTickerForexTickerRangeMultiplierTimespanFromToGetGET /v2/aggs/ticker/{forexTicker}/range/{multiplier}/{timespan}/{from}/{to}Aggregates (Bars)
FxconversionApirealTimeCurrencyConversionGET /v1/conversion/{from}/{to}Real-time Currency Conversion
FxlastquoteApilastQuoteCurrenciesGET /v1/last_quote/currencies/{from}/{to}Last Quote for a Currency Pair
FxquotesApiquotesFxGET /v3/quotes/{fxTicker}Quotes (BBO)
FxsnapshotApiv2SnapshotLocaleGlobalMarketsForexDirectionGetGET /v2/snapshot/locale/global/markets/forex/{direction}Gainers/Losers
FxsnapshotApiv2SnapshotLocaleGlobalMarketsForexTickersGetGET /v2/snapshot/locale/global/markets/forex/tickersAll Tickers
FxsnapshotApiv2SnapshotLocaleGlobalMarketsForexTickersTickerGetGET /v2/snapshot/locale/global/markets/forex/tickers/{ticker}Ticker
FxtradesApiv1HistoricForexFromToDateGetGET /v1/historic/forex/{from}/{to}/{date}Historic Forex Ticks
IndicesaggregatesApiindicesEMAGET /v1/indicators/ema/{indicesTicker}Exponential Moving Average (EMA)
IndicesaggregatesApiindicesMACDGET /v1/indicators/macd/{indicesTicker}Moving Average Convergence/Divergence (MACD)
IndicesaggregatesApiindicesRSIGET /v1/indicators/rsi/{indicesTicker}Relative Strength Index (RSI)
IndicesaggregatesApiindicesSMAGET /v1/indicators/sma/{indicesTicker}Simple Moving Average (SMA)
IndicesaggregatesApiv2AggsTickerIndicesTickerPrevGetGET /v2/aggs/ticker/{indicesTicker}/prevPrevious Close
IndicesaggregatesApiv2AggsTickerIndicesTickerRangeMultiplierTimespanFromToGetGET /v2/aggs/ticker/{indicesTicker}/range/{multiplier}/{timespan}/{from}/{to}Aggregates (Bars)
IndicessnapshotApiindicesSnapshotGET /v3/snapshot/indicesIndices Snapshot
InternalApilistTickerTaxonomyClassificationsGET /vX/reference/tickers/taxonomiesTicker Taxonomies
OptionsaggregatesApioptionsEMAGET /v1/indicators/ema/{optionsTicker}Exponential Moving Average (EMA)
OptionsaggregatesApioptionsMACDGET /v1/indicators/macd/{optionsTicker}Moving Average Convergence/Divergence (MACD)
OptionsaggregatesApioptionsRSIGET /v1/indicators/rsi/{optionsTicker}Relative Strength Index (RSI)
OptionsaggregatesApioptionsSMAGET /v1/indicators/sma/{optionsTicker}Simple Moving Average (SMA)
OptionsaggregatesApiv2AggsTickerOptionsTickerPrevGetGET /v2/aggs/ticker/{optionsTicker}/prevPrevious Close
OptionsaggregatesApiv2AggsTickerOptionsTickerRangeMultiplierTimespanFromToGetGET /v2/aggs/ticker/{optionsTicker}/range/{multiplier}/{timespan}/{from}/{to}Aggregates (Bars)
OptionslasttradeApilastTradeOptionsGET /v2/last/trade/{optionsTicker}Last Trade
OptionsopenCloseApiv1OpenCloseOptionsTickerDateGetGET /v1/open-close/{optionsTicker}/{date}Daily Open/Close
OptionsquotesApiquotesOptionsGET /v3/quotes/{optionsTicker}Quotes
OptionssnapshotApioptionContractGET /v3/snapshot/options/{underlyingAsset}/{optionContract}Option Contract
OptionssnapshotApioptionsChainGET /v3/snapshot/options/{underlyingAsset}Options Chain
OptionstradesApitradesOptionsGET /v3/trades/{optionsTicker}Trades
PublicApilistTickerTaxonomyClassificationsGET /vX/reference/tickers/taxonomiesTicker Taxonomies
ReferenceconditionsApilistConditionsGET /v3/reference/conditionsConditions
ReferencedividendsApilistDividendsGET /v3/reference/dividendsDividends v3
ReferenceexchangesApilistExchangesGET /v3/reference/exchangesExchanges
ReferencenewsApilistNewsGET /v2/reference/newsTicker News
ReferenceoptionscontractApigetOptionsContractGET /v3/reference/options/contracts/{options_ticker}Options Contract
ReferenceoptionscontractslistApilistOptionsContractsGET /v3/reference/options/contractsOptions Contracts
ReferencesecfilingApigetFilingGET /v1/reference/sec/filings/{filing_id}SEC Filing
ReferencesecfilingfileApigetFilingFileGET /v1/reference/sec/filings/{filing_id}/files/{file_id}SEC Filing File
ReferencesecfilingfilesApilistFilingFilesGET /v1/reference/sec/filings/{filing_id}/filesSEC Filing Files
ReferencesecfilingsApilistFilingsGET /v1/reference/sec/filingsSEC Filings
ReferencestocksApilistFinancialsGET /vX/reference/financialsStock Financials vX
ReferencestocksApilistStockSplitsGET /v3/reference/splitsStock Splits v3
ReferencestocksmarketApigetMarketHolidaysGET /v1/marketstatus/upcomingMarket Holidays
ReferencestocksmarketApigetMarketStatusGET /v1/marketstatus/nowMarket Status
ReferencetickersgetApigetEventsGET /vX/reference/tickers/{id}/eventsTicker Events
ReferencetickersgetApigetTickerGET /v3/reference/tickers/{ticker}Ticker Details v3
ReferencetickerslistApilistTickersGET /v3/reference/tickersTickers
ReferencetickerstypesApilistTickerTypesGET /v3/reference/tickers/typesTicker Types
StocksaggregatesApieMAGET /v1/indicators/ema/{stockTicker}Exponential Moving Average (EMA)
StocksaggregatesApimACDGET /v1/indicators/macd/{stockTicker}Moving Average Convergence/Divergence (MACD)
StocksaggregatesApirSIGET /v1/indicators/rsi/{stockTicker}Relative Strength Index (RSI)
StocksaggregatesApisMAGET /v1/indicators/sma/{stockTicker}Simple Moving Average (SMA)
StocksaggregatesApiv2AggsGroupedLocaleUsMarketStocksDateGetGET /v2/aggs/grouped/locale/us/market/stocks/{date}Grouped Daily (Bars)
StocksaggregatesApiv2AggsTickerStocksTickerPrevGetGET /v2/aggs/ticker/{stocksTicker}/prevPrevious Close
StocksaggregatesApiv2AggsTickerStocksTickerRangeMultiplierTimespanFromToGetGET /v2/aggs/ticker/{stocksTicker}/range/{multiplier}/{timespan}/{from}/{to}Aggregates (Bars)
StockslastquoteApilastQuoteGET /v2/last/nbbo/{stocksTicker}Last Quote
StockslasttradeApilastTradeGET /v2/last/trade/{stocksTicker}Last Trade
StocksopenCloseApiv1OpenCloseIndicesTickerDateGetGET /v1/open-close/{indicesTicker}/{date}Daily Open/Close
StocksopenCloseApiv1OpenCloseStocksTickerDateGetGET /v1/open-close/{stocksTicker}/{date}Daily Open/Close
StocksquotesApiquotesGET /v3/quotes/{stockTicker}Quotes (NBBO)
StocksquotesApiv2TicksStocksNbboTickerDateGetGET /v2/ticks/stocks/nbbo/{ticker}/{date}Quotes (NBBO)
StockssnapshotApiv2SnapshotLocaleUsMarketsStocksDirectionGetGET /v2/snapshot/locale/us/markets/stocks/{direction}Gainers/Losers
StockssnapshotApiv2SnapshotLocaleUsMarketsStocksTickersGetGET /v2/snapshot/locale/us/markets/stocks/tickersAll Tickers
StockssnapshotApiv2SnapshotLocaleUsMarketsStocksTickersStocksTickerGetGET /v2/snapshot/locale/us/markets/stocks/tickers/{stocksTicker}Ticker
StockstradesApitradesGET /v3/trades/{stockTicker}Trades
StockstradesApiv2TicksStocksTradesTickerDateGetGET /v2/ticks/stocks/trades/{ticker}/{date}Trades

Contributing

If you found a bug or have an idea for a new feature, please first discuss it with us by submitting a new issue. We are also open to volunteers willing to submit PRs for any open issues but please discuss it with us beforehand.

Development

For developing new features or fixing bugs, you will need to manage dependencies using Composer.

composer install

To run tests, use:

vendor/bin/phpunit

This PHP client follows the same release cadence as our API, ensuring it remains compatible with new and deprecated features.

About

The official PHP client library for the Polygon REST APIs.

Topics

Resources

Stars

34 stars

Watchers

16 watching

Forks

Releases

Packages

Used by

Contributors

Languages