polygon

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2022 License: MIT Imports: 6 Imported by: 0

README

Polygon Go Client

Docs Build

The official Go client library for the Polygon REST and WebSocket API.

go get github.com/polygon-io/client-go

See the docs for more details on our API.

This client is still in pre-release. It only supports the REST API but WebSocket support is coming soon. The public interface is relatively stable at this point but is still liable to change slightly until we release v1.

REST API Client

To get started, you'll need to import two main packages.

import (
	polygon "github.com/polygon-io/client-go"
	"github.com/polygon-io/client-go/models"
)

Next, create a new client with your API key.

c := polygon.NewClient("YOUR_API_KEY")
Using the client

After creating the client, making calls to the Polygon API is simple.

params := models.GetAllTickersSnapshotParams{
    Locale:     "us",
    MarketType: "stocks",
}.WithTickers("AAPL,MSFT")

res, err := c.Snapshot.GetAllTickersSnapshot(context.Background(), params)
if err != nil {
    log.Fatal(err)
}
log.Print(res) // do something with the result
Pagination

Our list methods return iterators that handle pagination for you.

params := models.ListTradesParams{Ticker: "AAPL"}.
    WithTimestamp(models.GTE, models.Nanos(time.Date(2021, 7, 22, 0, 0, 0, 0, time.UTC))).
    WithOrder(models.Asc)

iter, err := c.Trades.ListTrades(context.Background(), params)
if err != nil {
    log.Fatal(err)
}

for iter.Next() { // iter.Next() advances the iterator to the next value in the list
    log.Print(iter.Trade()) // do something with the current value
}
if iter.Err() != nil {
    log.Fatal(err) // the loop will break if an error occurs while iterating
}
Request options

Advanced users may want to add additional headers or query params to a given request.

params := &models.GetGroupedDailyAggsParams{
    Locale:     models.US,
    MarketType: models.Stocks,
    Date:       models.Date(time.Date(2021, 7, 22, 0, 0, 0, 0, time.Local)),
}

res, err := c.Aggs.GetGroupedDailyAggs(context.Background(), params,
    models.APIKey("YOUR_OTHER_API_KEY"),
    models.Header("X-CUSTOM-HEADER", "VALUE"),
    models.QueryParam("adjusted", strconv.FormatBool(true)))
if err != nil {
    log.Fatal(err)
}
log.Print(res) // do something with the result

Contributing

For now, we're generally not accepting pull requests from outside contributors but we're open to bug reports and feature requests. Or if you have more general feedback, feel free to reach out on our Slack channel.


Documentation

Overview

Package polygon REST and WebSocket clients for the Polygon API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(apiKey string) *restClient

NewClient creates a client for the Polygon REST API.

Types

This section is empty.

Directories

Path Synopsis
rest

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL