Polygon
A Complete Python Wrapper for Polygon.io APIs. Including Stocks, Options, Streaming, Forex & Crypto, References API and more...
Install / Use
/learn @pssolanki111/PolygonREADME
polygon: A Complete Polygon.io API Wrapper
what is polygon
polygon is a Complete Python Wrapper for Polygon.io APIs. It offers
simple and elegant programmatic access over each endpoint. Functionalities include but not limited to:
- Stocks, Index and Options data
- Forex and Crypto data
- Real time Websocket streaming (both callback and async based)
- Technical Indicators (SMA, EMA, RSI, MACD)
- Market Info, News, Holidays, Schedules, Tickers, Conditions, Dividends, Splits
- Async support for REST endpoints
- Built In stream reconnection functionality (Experimental, async streamer only)
- Full builtin Pagination support (with internal merging of responses)
- Bulk data download functions: bulk OCHLV aggregates bars, bulk ticker details etc.
- Extensive Option Symbology supporting 6 option symbol formats
and a lot more...
How Do I Use polygon
The complete description of everything you need to know is available in the Documentation which has answers to any question you might have with example uses included wherever needed. Docs are a must-read for most people.
- For examples to get started with, see the examples
- For an advanced use case example code involving redis queue and postgresql database, check out
- MarketMakerLite/polygon
- The lib is also officially supported by the popular TA library pandas-ta
as an underlying data source instead of the default
yfinance. See relevant docs to know how to use - To see an advanced use case of downloading ALL OCHLV data for ALL tickers for 20+ years and write it to a timescale enabled postgresql database efficiently, see This Script by MML.
- The documentation also contain TONS of sample code snippets wherever necessary.
Quick Setup Guide With Examples
Before you do anything, you'll need to have a polygon account and get your API key. Visit Your Dashboard to get yours.
Next, you'd need to install polygon
pip install polygon
and You're good to Go!
Here are a few quick usage examples.
Getting a Stock's Previous Day OCHLV
import polygon
api_key = 'YOUR_KEY'
stocks_client = polygon.StocksClient(api_key)
previous_close = stocks_client.get_previous_close('AMD')
print(previous_close)
An Async Example for REST endpoints - Previous Close
import polygon
import asyncio
async def main():
api_key = 'YOUR_KEY'
stocks_client = polygon.StocksClient(api_key, True)
previous_close = await stocks_client.get_previous_close('AMD')
await stocks_client.close() # Recommended to close the httpx session when it's not needed.
print(previous_close)
if __name__ == '__main__':
asyncio.run(main())
A Streaming Example (Callback Based)
import polygon
from polygon.enums import StreamCluster
def my_own_message_handler(ws, msg):
print(f'msg received: {msg}')
def main():
api_key = 'YOUR_KEY'
stream_client = polygon.StreamClient(api_key, StreamCluster.STOCKS, on_message=my_own_message_handler)
stream_client.start_stream_thread()
stream_client.subscribe_stock_trades(['AMD', 'NVDA'])
if __name__ == '__main__':
main()
An Async Streaming Example
import asyncio
import polygon
from polygon.enums import StreamCluster
async def stock_trades_handler(msg): # it is possible to create one common message handler for different services.
print(f'msg received: {msg}')
async def main():
api_key = 'YOUR_KEY'
stream_client = polygon.AsyncStreamClient(api_key, StreamCluster.STOCKS)
await stream_client.subscribe_stock_trades(['AMD', 'NVDA'], stock_trades_handler)
while 1:
await stream_client.handle_messages() # the lib provides auto reconnect functionality. See docs for info
if __name__ == '__main__':
asyncio.run(main())
This only scratches the surface of the library.
See the Documentation to start using the library with its full functionalities.
Latest development source code of the library can be found on the development branch
What if I need help?
We have a helpful & vibrant community in our Discord Server. Join in to ask a question, share your ideas or observations or to just chat with interesting people, or maybe just for lurking :eyes:
See Getting Help or you can also start a quick discussion
Quick Links for Speed Runners
- Getting Started - a must-read for almost everyone
- Async support for HTTP endpoints
- Bulk Data Download Functions
- Pagination Support || Option Symbology
- Stocks || Indices || Options || Reference APIs
- Forex & Crypto
- Callback Streaming || Async Streaming
- Easy guide to enums || Library Interface Docs
- bugs, discussions, wikis and FAQs
What else?
- Bug reports, suggestions and pull requests are always welcome.
- See Contributing if you wish to contribute.
- Read This before raising a bug.
- CHANGELOG for the project is available within the same repository
polygonis released under the MIT License
Made with Passion & Python by P S Solanki
Related Skills
claude-opus-4-5-migration
104.6kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
model-usage
345.4kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
TrendRadar
50.6k⭐AI-driven public opinion & trend monitor with multi-platform aggregation, RSS, and smart alerts.🎯 告别信息过载,你的 AI 舆情监控助手与热点筛选工具!聚合多平台热点 + RSS 订阅,支持关键词精准筛选。AI 智能筛选新闻 + AI 翻译 + AI 分析简报直推手机,也支持接入 MCP 架构,赋能 AI 自然语言对话分析、情感洞察与趋势预测等。支持 Docker ,数据本地/云端自持。集成微信/飞书/钉钉/Telegram/邮件/ntfy/bark/slack 等渠道智能推送。
mcp-for-beginners
15.8kThis open-source curriculum introduces the fundamentals of Model Context Protocol (MCP) through real-world, cross-language examples in .NET, Java, TypeScript, JavaScript, Rust and Python. Designed for developers, it focuses on practical techniques for building modular, scalable, and secure AI workflows from session setup to service orchestration.
