A Complete Python Wrapper for Polygon.io APIs. First Public Beta Release
Project description
polygon
: A 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 and Options data
- Forex and Crypto data
- Websocket streaming (both callback and async based)
- Market Info, News, Holidays, Schedules
- Async support for REST endpoints
- Built In stream reconnection functionality (only async stream, callback stream in progress)
and more...
How do I use polygon
The complete description of everything you need to know is available in the Documentation
Before you do anything, you'll need to have a polygon account and get your API key. Visit your dashboard to get your API key.
Next, you'd need to install polygon
pip install polygon
and You're good to Go! A few quick examples.
Getting a stock's current market price
import polygon
api_key = 'YOUR_KEY'
stocks_client = polygon.StocksClient(api_key)
current_price = stocks_client.get_current_price('AMD')
print(current_price)
An Async example for REST endpoints - current price
import polygon
import asyncio
async def main():
api_key = 'YOUR_KEY'
stocks_client = polygon.StocksClient(api_key, True)
current_price = await stocks_client.async_get_current_price('AMD')
await stocks_client.async_close() # Recommended to close the httpx session when it's not needed.
print(current_price)
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'Look at me! I\'m the Handler now...: {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'Look at me! I am the new handler. {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 scratched the surface of the library.
See the Documentation to start using the library with its full functionalities.
what if I need help?
See Getting Help
Quick Links for Speed Runners
- Getting Started - a must-read for almost everyone
- Async support for REST endpoints
- Documentation for all Stocks APIs || Options APIs || Reference APIs
- Documentation for all Forex APIs || Crypto APIs
- Documentation for Callback Streaming || Async Streaming
- Easy guide to enums || Library Interface Docs
- Docs on bugs, discussions, wikis and FAQs
- Contribution and License
Anything else?
Bug reports, suggestions and pull requests are always welcome.
See Contributing if you wish to contribute.
Read This before raising a bug.
polygon
is released under the MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for polygon-0.7.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42842f8bb136e95167d8b13ad5926bca30a50a93dfc64a639757a27448b3a1e9 |
|
MD5 | b6343746cc39130c86bf752f9427b177 |
|
BLAKE2b-256 | 11f959a7669ce9c93650c5c901293dc70093765122841eea235a15953b238568 |