# `polygon`: A Complete Polygon.io API Wrapper
[](https://discord.gg/jPkARduU6N) [](https://pepy.tech/project/polygon) [](https://polygon.readthedocs.io/en/latest/Getting-Started.html) [](https://pypi.org/project/polygon/) [](https://www.codefactor.io/repository/github/pssolanki111/polygon/overview/main) [](https://github.com/pssolanki111/polygon/issues) [](https://github.com/pssolanki111/polygon/graphs/contributors) [](https://github.com/pssolanki111/polygon/blob/main/LICENSE) [](https://github.com/pssolanki111)                                                          
## what is `polygon`
`polygon` is a Complete Python Wrapper for [Polygon.io APIs](https://polygon.io/). 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](https://polygon.readthedocs.io/en/latest/Getting-Started.html) 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](https://github.com/pssolanki111/polygon/tree/main/EXAMPLES)
- For an advanced use case example code involving redis queue and postgresql database, check out 
- [MarketMakerLite/polygon](https://github.com/MarketMakerLite/polygon) 
- The lib is also officially supported by the popular TA library [pandas-ta](https://github.com/twopirllc/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](https://github.com/MarketMakerLite/polygon/blob/main/historical_data/advanced.py) by [MML](https://github.com/MarketMakerLite).
- The [documentation](https://polygon.readthedocs.io/en/latest/Getting-Started.html) 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](https://polygon.io/dashboard/api-keys) to get yours.
Next, you'd need to install `polygon`
```shell
pip install polygon
```
**and You're good to Go!** 
Here are a few quick usage examples.
### Getting a Stock's Previous Day OCHLV
```python
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
```python
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)
```python
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
```python
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](https://polygon.readthedocs.io/) to start using the library with its full functionalities.**
Latest development source code of the library can be found on the 
[development branch](https://github.com/pssolanki111/polygon/tree/dev)
## What if I need help?
We have a helpful & vibrant community in our [Discord Server](https://discord.gg/jPkARduU6N). 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](https://polygon.readthedocs.io/en/latest/getting_help.html) or you can also [start a quick discussion](https://github.com/pssolanki111/polygon/discussions)
## Quick Links for `Speed Runners`
- [Getting Started](https://polygon.readthedocs.io/en/latest/Getting-Started.html) - a must-read for almost everyone
- [Async support for HTTP endpoints](https://polygon.readthedocs.io/en/latest/Getting-Started.html#async-support-for-rest-endpoints)
- [Bulk Data Download Functions](https://polygon.readthedocs.io/en/latest/bulk_data_download_functions.html)
- [Pagination Support](https://polygon.readthedocs.io/en/latest/Getting-Started.html#pagination-support) || [Option Symbology](https://polygon.readthedocs.io/en/latest/Options.html#working-with-option-symbols)
- [Stocks](https://polygon.readthedocs.io/en/latest/Stocks.html) || [Indices](https://polygon.readthedocs.io/en/latest/Indices.html) || [Options](https://polygon.readthedocs.io/en/latest/Options.html) || [Reference APIs](https://polygon.readthedocs.io/en/latest/References.html)
- [Forex & Crypto](https://polygon.readthedocs.io/en/latest/Forex_Crypto.html)
- [Callback Streaming](https://polygon.readthedocs.io/en/latest/Callback-Streaming.html) || [Async Streaming](https://polygon.readthedocs.io/en/latest/Async-Streaming.html)
- [Easy guide to enums](https://polygon.readthedocs.io/en/latest/using_enums.html) || [Library Interface Docs](https://polygon.readthedocs.io/en/latest/Library-Interface-Documentation.html)
- [bugs, discussions, wikis and FAQs](https://polygon.readthedocs.io/en/latest/bugs_discussions_wikis_faqs.html)
## What else?
- Bug reports, suggestions and pull requests are always welcome.
- See [Contributing](https://polygon.readthedocs.io/en/latest/contrib_and_license.html) if you wish to contribute.
- Read [This](https://polygon.readthedocs.io/en/latest/bugs_discussions_wikis_faqs.html) before raising a bug.
- [CHANGELOG](https://github.com/pssolanki111/polygon/blob/main/CHANGELOG.md) for the project is available within the same repository
- `polygon` is released under the [MIT License](https://github.com/pssolanki111/polygon/blob/main/LICENSE)
---
#### Made with Passion & Python by [P S Solanki](https://github.com/pssolanki111)
            
         
        Raw data
        
            {
    "_id": null,
    "home_page": "https://github.com/pssolanki111/polygon",
    "name": "polygon",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "finance trading equities bonds options research data markets",
    "author": "Pankaj Singh Solanki",
    "author_email": "nice_try@fbi.com",
    "download_url": null,
    "platform": null,
    "description": "# `polygon`: A Complete Polygon.io API Wrapper\r\n\r\n[](https://discord.gg/jPkARduU6N) [](https://pepy.tech/project/polygon) [](https://polygon.readthedocs.io/en/latest/Getting-Started.html) [](https://pypi.org/project/polygon/) [](https://www.codefactor.io/repository/github/pssolanki111/polygon/overview/main) [](https://github.com/pssolanki111/polygon/issues) [](https://github.com/pssolanki111/polygon/graphs/contributors) [](https://github.com/pssolanki111/polygon/blob/main/LICENSE) [](https://github.com/pssolanki111)                                                          \r\n\r\n## what is `polygon`\r\n`polygon` is a Complete Python Wrapper for [Polygon.io APIs](https://polygon.io/). It offers \r\nsimple and elegant programmatic access over each endpoint. Functionalities include but not limited to:\r\n\r\n- Stocks, Index and Options data\r\n- Forex and Crypto data\r\n- Real time Websocket streaming (both callback and async based)\r\n- Technical Indicators (SMA, EMA, RSI, MACD)\r\n- Market Info, News, Holidays, Schedules, Tickers, Conditions, Dividends, Splits\r\n- Async support for REST endpoints\r\n- Built In stream reconnection functionality (Experimental, async streamer only)\r\n- Full builtin Pagination support (with internal merging of responses)\r\n- **Bulk** data download functions: bulk OCHLV aggregates bars, bulk ticker details etc.\r\n- Extensive Option Symbology supporting 6 option symbol formats \r\n\r\nand a lot more...\r\n\r\n## How Do I Use `polygon`\r\n\r\nThe complete description of everything you need to know is available in the [Documentation](https://polygon.readthedocs.io/en/latest/Getting-Started.html) which has answers to \r\nany question you might have with example uses included wherever needed. Docs are a must-read for most people.\r\n\r\n- For examples to get started with, see the [examples](https://github.com/pssolanki111/polygon/tree/main/EXAMPLES)\r\n- For an advanced use case example code involving redis queue and postgresql database, check out \r\n- [MarketMakerLite/polygon](https://github.com/MarketMakerLite/polygon) \r\n- The lib is also officially supported by the popular TA library [pandas-ta](https://github.com/twopirllc/pandas-ta) \r\n  as an underlying data source instead of the default `yfinance`. See relevant docs to know how to use\r\n- To see an advanced use case of downloading ALL OCHLV data for ALL tickers for 20+ years and write it to a \r\n  timescale enabled postgresql database efficiently, see [This Script](https://github.com/MarketMakerLite/polygon/blob/main/historical_data/advanced.py) by [MML](https://github.com/MarketMakerLite).\r\n- The [documentation](https://polygon.readthedocs.io/en/latest/Getting-Started.html) also contain TONS of sample \r\n  code snippets wherever necessary.\r\n\r\n### Quick Setup Guide With Examples\r\n\r\nBefore you do anything, you'll need to have a polygon account and get your API key. \r\nVisit [Your Dashboard](https://polygon.io/dashboard/api-keys) to get yours.\r\n\r\nNext, you'd need to install `polygon`\r\n\r\n```shell\r\npip install polygon\r\n```\r\n\r\n**and You're good to Go!** \r\n\r\nHere are a few quick usage examples.\r\n\r\n### Getting a Stock's Previous Day OCHLV\r\n\r\n```python\r\nimport polygon\r\n\r\napi_key = 'YOUR_KEY'\r\n\r\nstocks_client = polygon.StocksClient(api_key)\r\n\r\nprevious_close = stocks_client.get_previous_close('AMD')\r\n\r\nprint(previous_close)\r\n```\r\n\r\n### An Async Example for REST endpoints - Previous Close\r\n\r\n```python\r\nimport polygon\r\nimport asyncio\r\n\r\nasync def main():\r\n    api_key = 'YOUR_KEY'\r\n    \r\n    stocks_client = polygon.StocksClient(api_key, True)\r\n    \r\n    previous_close = await stocks_client.get_previous_close('AMD')\r\n    await stocks_client.close()  # Recommended to close the httpx session when it's not needed. \r\n    print(previous_close)\r\n\r\nif __name__ == '__main__':\r\n    asyncio.run(main())\r\n```\r\n\r\n### A Streaming Example (Callback Based)\r\n\r\n```python\r\nimport polygon\r\nfrom polygon.enums import StreamCluster\r\n\r\ndef my_own_message_handler(ws, msg):\r\n    print(f'msg received: {msg}')\r\n\r\ndef main():\r\n    api_key = 'YOUR_KEY'\r\n\r\n    stream_client = polygon.StreamClient(api_key, StreamCluster.STOCKS, on_message=my_own_message_handler)\r\n    stream_client.start_stream_thread()\r\n    stream_client.subscribe_stock_trades(['AMD', 'NVDA'])\r\n\r\nif __name__ == '__main__':\r\n    main()\r\n```\r\n### An Async Streaming Example\r\n\r\n```python\r\nimport asyncio\r\nimport polygon\r\nfrom polygon.enums import StreamCluster\r\n\r\nasync def stock_trades_handler(msg):   # it is possible to create one common message handler for different services.\r\n    print(f'msg received: {msg}')\r\n    \r\nasync def main():\r\n    api_key = 'YOUR_KEY'\r\n    \r\n    stream_client = polygon.AsyncStreamClient(api_key, StreamCluster.STOCKS)\r\n    \r\n    await stream_client.subscribe_stock_trades(['AMD', 'NVDA'], stock_trades_handler)\r\n    \r\n    while 1:\r\n        await stream_client.handle_messages()  # the lib provides auto reconnect functionality. See docs for info\r\nif __name__ == '__main__':\r\n    asyncio.run(main())\r\n\r\n```\r\nThis only scratches the surface of the library.\r\n\r\n**See the [Documentation](https://polygon.readthedocs.io/) to start using the library with its full functionalities.**\r\n\r\nLatest development source code of the library can be found on the \r\n[development branch](https://github.com/pssolanki111/polygon/tree/dev)\r\n\r\n## What if I need help?\r\n\r\nWe have a helpful & vibrant community in our [Discord Server](https://discord.gg/jPkARduU6N). Join in to ask a \r\nquestion, share your ideas or observations or to just chat with interesting people, or maybe just for lurking :eyes:\r\n\r\nSee [Getting Help](https://polygon.readthedocs.io/en/latest/getting_help.html) or you can also [start a quick discussion](https://github.com/pssolanki111/polygon/discussions)\r\n\r\n## Quick Links for `Speed Runners`\r\n\r\n- [Getting Started](https://polygon.readthedocs.io/en/latest/Getting-Started.html) - a must-read for almost everyone\r\n- [Async support for HTTP endpoints](https://polygon.readthedocs.io/en/latest/Getting-Started.html#async-support-for-rest-endpoints)\r\n- [Bulk Data Download Functions](https://polygon.readthedocs.io/en/latest/bulk_data_download_functions.html)\r\n- [Pagination Support](https://polygon.readthedocs.io/en/latest/Getting-Started.html#pagination-support) || [Option Symbology](https://polygon.readthedocs.io/en/latest/Options.html#working-with-option-symbols)\r\n- [Stocks](https://polygon.readthedocs.io/en/latest/Stocks.html) || [Indices](https://polygon.readthedocs.io/en/latest/Indices.html) || [Options](https://polygon.readthedocs.io/en/latest/Options.html) || [Reference APIs](https://polygon.readthedocs.io/en/latest/References.html)\r\n- [Forex & Crypto](https://polygon.readthedocs.io/en/latest/Forex_Crypto.html)\r\n- [Callback Streaming](https://polygon.readthedocs.io/en/latest/Callback-Streaming.html) || [Async Streaming](https://polygon.readthedocs.io/en/latest/Async-Streaming.html)\r\n- [Easy guide to enums](https://polygon.readthedocs.io/en/latest/using_enums.html) || [Library Interface Docs](https://polygon.readthedocs.io/en/latest/Library-Interface-Documentation.html)\r\n- [bugs, discussions, wikis and FAQs](https://polygon.readthedocs.io/en/latest/bugs_discussions_wikis_faqs.html)\r\n\r\n## What else?\r\n\r\n- Bug reports, suggestions and pull requests are always welcome.\r\n- See [Contributing](https://polygon.readthedocs.io/en/latest/contrib_and_license.html) if you wish to contribute.\r\n- Read [This](https://polygon.readthedocs.io/en/latest/bugs_discussions_wikis_faqs.html) before raising a bug.\r\n- [CHANGELOG](https://github.com/pssolanki111/polygon/blob/main/CHANGELOG.md) for the project is available within the same repository\r\n- `polygon` is released under the [MIT License](https://github.com/pssolanki111/polygon/blob/main/LICENSE)\r\n\r\n---\r\n#### Made with Passion & Python by [P S Solanki](https://github.com/pssolanki111)\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Complete Python Wrapper for Polygon.io APIs.",
    "version": "1.2.8",
    "project_urls": {
        "Discussions": "https://github.com/pssolanki111/polygon/discussions",
        "Homepage": "https://github.com/pssolanki111/polygon",
        "Issue Tracker": "https://github.com/pssolanki111/polygon/issues",
        "Support": "https://www.patreon.com/pssolanki"
    },
    "split_keywords": [
        "finance",
        "trading",
        "equities",
        "bonds",
        "options",
        "research",
        "data",
        "markets"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "03ba07ca7cb1568c5d1fa4c66c01ce639a107633095a851a8719f1e356ab1ba1",
                "md5": "6657a185e6505310600f00755fb1a928",
                "sha256": "aa4d339f0d4c201970ef46c9d4c9199640c28abf6d0c37547e77f9870896d942"
            },
            "downloads": -1,
            "filename": "polygon-1.2.8-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6657a185e6505310600f00755fb1a928",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.6",
            "size": 112484,
            "upload_time": "2025-08-28T18:32:58",
            "upload_time_iso_8601": "2025-08-28T18:32:58.720275Z",
            "url": "https://files.pythonhosted.org/packages/03/ba/07ca7cb1568c5d1fa4c66c01ce639a107633095a851a8719f1e356ab1ba1/polygon-1.2.8-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-28 18:32:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pssolanki111",
    "github_project": "polygon",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "polygon"
}