Skip to main content

A Complete Python Wrapper for Polygon.io APIs. First Public Alpha Release

Project description

polygon: A Polygon.io API Wrapper

Documentation Status pypi ff fd Licensess gh

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)
  • Pagination support (next/previous pages)

and 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 is a must-read for most people.

More examples will be added to this repository in a folder examples as they are ready.

Here is a quick setup guide with a few examples

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.get_current_price('AMD')
    await stocks_client.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'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.

what if I need help?

See Getting Help or start a quick discussion

Quick Links for Speed Runners

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polygon-0.9.0.tar.gz (43.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polygon-0.9.0-py2.py3-none-any.whl (50.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file polygon-0.9.0.tar.gz.

File metadata

  • Download URL: polygon-0.9.0.tar.gz
  • Upload date:
  • Size: 43.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.10

File hashes

Hashes for polygon-0.9.0.tar.gz
Algorithm Hash digest
SHA256 59235f19d8c7d52b593d33322e4dd0b2fa63bcc58481a2cd7835537fe1d6d2e4
MD5 a5725ce71fe9f024b121561f5101bf98
BLAKE2b-256 722ab25c49cd0ed1c6b1c8e055abe0e68017f6e7bb2db737e556b6326401acbc

See more details on using hashes here.

File details

Details for the file polygon-0.9.0-py2.py3-none-any.whl.

File metadata

  • Download URL: polygon-0.9.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 50.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.10

File hashes

Hashes for polygon-0.9.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cb51817d1de96380d63f7d269371fc42a9ab0592cb81971409da31fd75676365
MD5 57781a838fe488afa5c2f489b4927bec
BLAKE2b-256 71108a0480cd3ce1d141c435fd882836f73b1fa461a7a215a530359ee9e60116

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page