SDKs overview
Polygon provides Software Development Kits (SDKs) and client libraries designed to streamline interaction with its market data APIs. These SDKs simplify common tasks such as authentication, making API requests, and parsing responses across various programming languages. The goal is to reduce boilerplate code and accelerate development for applications requiring real-time and historical financial data Polygon API getting started guide.
The SDKs are developed and maintained by Polygon, ensuring compatibility with the latest API versions and features. They typically handle rate limiting, error handling, and data serialization, allowing developers to focus on application logic rather than low-level API communication details. Polygon's API offers access to a range of financial instruments, including stocks, options, forex, cryptocurrencies, and indices Polygon documentation.
Official SDKs by language
Polygon offers official SDKs for several popular programming languages. These libraries are maintained by the Polygon team and are the recommended method for integrating with the Polygon API. Each SDK is tailored to the conventions and best practices of its respective language, providing an idiomatic development experience.
| Language | Package Name | Install Command | Maturity |
|---|---|---|---|
| Python | polygon-api-client |
pip install polygon-api-client |
Stable |
| Node.js | @polygon.io/client-js |
npm install @polygon.io/client-js |
Stable |
| Go | github.com/polygon-io/client-go |
go get github.com/polygon-io/client-go |
Stable |
| Java | io.polygon:polygon-java |
Maven/Gradle dependency | Stable |
| .NET | Polygon.Net |
dotnet add package Polygon.Net |
Beta |
| Rust | polygon-io-client |
cargo add polygon-io-client |
Beta |
| PHP | polygon-io/api-client |
composer require polygon-io/api-client |
Beta |
Installation
Installing Polygon SDKs typically involves using the standard package manager for each respective programming language. Below are detailed instructions for the most commonly used SDKs: Python and Node.js.
Python
To install the official Polygon Python client, use pip, the Python package installer. It is recommended to use a virtual environment to manage dependencies.
# Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
# Install the Polygon API client
pip install polygon-api-client
For more detailed instructions and dependency management, refer to the Polygon Python client documentation.
Node.js
For Node.js projects, the Polygon client library can be installed using npm or yarn.
# Using npm
npm install @polygon.io/client-js
# Using yarn
yarn add @polygon.io/client-js
Detailed installation and usage information for the JavaScript client is available in the Polygon Node.js client documentation.
Go
The Go client library is installed using the go get command.
go get github.com/polygon-io/client-go
Refer to the Polygon Go client documentation for further details.
Java
For Java, you typically add the dependency to your pom.xml (Maven) or build.gradle (Gradle) file.
# Maven (pom.xml)
<dependency>
<groupId>io.polygon</groupId>
<artifactId>polygon-java</artifactId>
<version>LATEST_VERSION</version> <!-- Replace with the latest version -->
</dependency>
# Gradle (build.gradle)
implementation 'io.polygon:polygon-java:LATEST_VERSION' // Replace with the latest version
Check the Polygon Java client documentation for the most recent version and setup.
Quickstart example
This quickstart example demonstrates how to fetch daily stock aggregates for a specific ticker using the Python SDK. This requires a Polygon API key, which can be obtained by signing up on the Polygon website.
Python Quickstart: Get Daily Stock Aggregates
First, ensure you have installed the polygon-api-client as described in the installation section.
from polygon import RESTClient
from datetime import date
# Replace 'YOUR_API_KEY' with your actual Polygon API key
API_KEY = "YOUR_API_KEY"
# Initialize the REST client
client = RESTClient(api_key=API_KEY)
def get_daily_aggregates(ticker: str, from_date: date, to_date: date):
try:
# Fetch daily aggregates for the specified ticker and date range
aggs = client.get_aggs(
ticker=ticker,
multiplier=1,
timespan="day",
from_=from_date,
to_=to_date,
limit=120
)
if aggs:
print(f"Daily Aggregates for {ticker} from {from_date} to {to_date}:")
for agg in aggs:
print(f" Date: {date.fromtimestamp(agg.timestamp / 1000)}, Open: {agg.open}, High: {agg.high}, Low: {agg.low}, Close: {agg.close}, Volume: {agg.volume}")
else:
print(f"No aggregates found for {ticker} in the specified range.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
# Example usage: Get daily aggregates for AAPL for the last 5 days
today = date.today()
five_days_ago = date.fromordinal(today.toordinal() - 5)
get_daily_aggregates("AAPL", five_days_ago, today)
This script initializes the RESTClient with your API key, then calls the get_aggs method to retrieve daily candlestick data for Apple (AAPL) over a five-day period. The results, including open, high, low, close prices, and volume, are then printed to the console. For more complex queries and other data types, consult the Polygon Python SDK documentation.
Community libraries
While Polygon maintains official SDKs, the broader developer community also contributes libraries and tools that interact with the Polygon API. These community-driven projects can offer alternative language support, specialized functionalities, or integrations with other platforms. Developers often create these libraries to fill gaps, provide different architectural approaches, or cater to specific use cases not directly addressed by the official SDKs.
Examples of community contributions might include:
- Unofficial clients in less common languages: Developers might create clients for languages like R, Scala, or Dart.
- Specialized data analysis tools: Libraries that integrate Polygon data directly into financial modeling tools or statistical packages.
- Web framework integrations: Components that simplify using Polygon data within popular web frameworks (e.g., Django, Flask, Express.js).
- Trading bot frameworks: Libraries designed to facilitate the creation of algorithmic trading strategies using Polygon's real-time data feeds.
When using community libraries, it is important to verify their maintenance status, documentation quality, and active support from the community. While they can be valuable, they might not offer the same level of official support or guaranteed compatibility as Polygon's first-party SDKs. Developers can often find these projects on platforms like GitHub or through community forums. For example, GitHub hosts numerous open-source libraries, a common practice for open-source software development.
For specific recommendations or to discover community projects, it is advisable to consult the Polygon developer community forums, Discord channels, or search GitHub for repositories tagged with "polygon.io" or "polygon-api".