All Projects → polygon-io → Client Python

polygon-io / Client Python

Licence: mit
A python client library for accessing Polygon's APIs

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Client Python

Javaquarkbbs
基于Spring Boot实现的一个简易的Java社区
Stars: ✭ 755 (+494.49%)
Mutual labels:  swagger, websocket
Spring Boot Leaning
Spring Boot 2.X 最全课程代码
Stars: ✭ 2,008 (+1481.1%)
Mutual labels:  swagger, websocket
Mapdrawingtools
this library Drawing polygon, polyline and points in Google Map and return coordinates to your App
Stars: ✭ 122 (-3.94%)
Mutual labels:  polygon
Covid 19 Api
API Service for tracking the COVID-19
Stars: ✭ 126 (-0.79%)
Mutual labels:  swagger
Go Chat Api
Chat in Golang with Websockets and Redis
Stars: ✭ 125 (-1.57%)
Mutual labels:  websocket
Faygo
Faygo is a fast and concise Go Web framework that can be used to develop high-performance web app(especially API) with fewer codes. Just define a struct handler, faygo will automatically bind/verify the request parameters and generate the online API doc.
Stars: ✭ 1,557 (+1125.98%)
Mutual labels:  swagger
Http Router
🎉 Release 2.0 is released! Very fast HTTP router for PHP 7.1+ (incl. PHP8 with attributes) based on PSR-7 and PSR-15 with support for annotations and OpenApi (Swagger)
Stars: ✭ 124 (-2.36%)
Mutual labels:  swagger
Harmonic
A high performance and scalable RTMP live streaming application framework
Stars: ✭ 121 (-4.72%)
Mutual labels:  websocket
Vs Swagger Viewer
Swagger Viewer lets you preview and validate Swagger 2.0 and OpenAPI files as you type in Visual Studio Code.
Stars: ✭ 126 (-0.79%)
Mutual labels:  swagger
Joynr
A transport protocol agnostic (MQTT, HTTP, WebSockets etc.) Franca IDL based communication framework supporting multiple communication paradigms (RPC, Pub-Sub, broadcast etc.)
Stars: ✭ 124 (-2.36%)
Mutual labels:  websocket
Grpc Gateway
The gRPC-Gateway is a plugin of the Google protocol buffers compiler protoc. It reads protobuf service definitions and generates a reverse-proxy server which translates a RESTful HTTP API into gRPC. This server is generated according to the google.api.http annotations in your service definitions.
Stars: ✭ 12,223 (+9524.41%)
Mutual labels:  swagger
Round Anything
A set of OpenSCAD utilities for adding radii and fillets, that embodies a robust approach to developing OpenSCAD parts.
Stars: ✭ 122 (-3.94%)
Mutual labels:  polygon
X Admin
致力于快速开发中小型后台管理系统项目模板(更新中......)
Stars: ✭ 123 (-3.15%)
Mutual labels:  websocket
Charroom
PHP + Swoole 聊天室
Stars: ✭ 125 (-1.57%)
Mutual labels:  websocket
Wizard
Wizard是一款开源的文档管理工具,支持Markdown/Swagger/Table类型的文档。
Stars: ✭ 1,733 (+1264.57%)
Mutual labels:  swagger
Tardis Node
Convenient access to tick-level real-time and historical cryptocurrency market data via Node.js
Stars: ✭ 126 (-0.79%)
Mutual labels:  websocket
Swaggerwcf
Swagger for WCF
Stars: ✭ 121 (-4.72%)
Mutual labels:  swagger
Gin Swagger
gin middleware to automatically generate RESTful API documentation with Swagger 2.0.
Stars: ✭ 2,001 (+1475.59%)
Mutual labels:  swagger
Godotphoenixchannels
GDScript and Godot client for real-time Phoenix Framework Channels
Stars: ✭ 125 (-1.57%)
Mutual labels:  websocket
Tsed
📐 Ts.ED is a Node.js and TypeScript framework on top of Express to write your application with TypeScript (or ES6). It provides a lot of decorators and guideline to make your code more readable and less error-prone.
Stars: ✭ 1,941 (+1428.35%)
Mutual labels:  swagger

Build Status PyPI version

Polygon Python Client - WebSocket & RESTful APIs

Python client for the Polygon.io Stocks API

Getting Started

For a basic product overview, check out our setup and use documentation

Install

pip install polygon-api-client

polygon-api-client supports python version >= 3.6

Simple WebSocket Demo

import time

from polygon import WebSocketClient, STOCKS_CLUSTER


def my_custom_process_message(message):
    print("this is my custom message processing", message)


def my_custom_error_handler(ws, error):
    print("this is my custom error handler", error)


def my_custom_close_handler(ws):
    print("this is my custom close handler")


def main():
    key = 'your api key'
    my_client = WebSocketClient(STOCKS_CLUSTER, key, my_custom_process_message)
    my_client.run_async()

    my_client.subscribe("T.MSFT", "T.AAPL", "T.AMD", "T.NVDA")
    time.sleep(1)

    my_client.close_connection()


if __name__ == "__main__":
    main()

Simple REST Demo

from polygon import RESTClient


def main():
    key = "your api key"

    # RESTClient can be used as a context manager to facilitate closing the underlying http session
    # https://requests.readthedocs.io/en/master/user/advanced/#session-objects
    with RESTClient(key) as client:
        resp = client.stocks_equities_daily_open_close("AAPL", "2018-03-02")
        print(f"On: {resp.from_} Apple opened at {resp.open} and closed at {resp.close}")


if __name__ == '__main__':
    main()

Query parameters for REST calls

Every function call under our RESTClient has the query_params kwargs. These kwargs are passed along and mapped 1:1 as query parameters to the underling HTTP call. For more information on the different query parameters please reference our API Docs.

Example with query parameters

import datetime

from polygon import RESTClient


def ts_to_datetime(ts) -> str:
    return datetime.datetime.fromtimestamp(ts / 1000.0).strftime('%Y-%m-%d %H:%M')


def main():
    key = "your api key"

    # RESTClient can be used as a context manager to facilitate closing the underlying http session
    # https://requests.readthedocs.io/en/master/user/advanced/#session-objects
    with RESTClient(key) as client:
        from_ = "2019-01-01"
        to = "2019-02-01"
        resp = client.stocks_equities_aggregates("AAPL", 1, "minute", from_, to, unadjusted=False)

        print(f"Minute aggregates for {resp.ticker} between {from_} and {to}.")

        for result in resp.results:
            dt = ts_to_datetime(result["t"])
            print(f"{dt}\n\tO: {result['o']}\n\tH: {result['h']}\n\tL: {result['l']}\n\tC: {result['c']} ")


if __name__ == '__main__':
    main()

Notes about the REST Client

We use swagger as our API spec and we used this swagger to generate most of the code that defines the REST client. We made this decision due to the size of our API, many endpoints and object definitions, and to accommodate future changes.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].