Skip to content

[WIP] Adds Futures support (alpha) #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

justinpolygon
Copy link
Contributor

Added futures REST and WebSocket support (alpha). Includes new REST endpoints for futures data (e.g., aggregates, contracts, market statuses, etc) and WebSocket event parsing (e.g. trades, quotes, and aggregates).

REST examples:

package main

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

func main() {
	client := polygon.New("your_api_key")
	params := &models.ListFuturesAggsParams{
		Ticker:     "ESZ4",
		Multiplier: 1,
		Timespan:   "day",
		From:       models.Millis(time.Now().AddDate(0, 0, -7)),
		To:         models.Millis(time.Now()),
	}
	aggs := client.ListFuturesAggs(context.Background(), params)
	for aggs.Next() {
		fmt.Println(aggs.Item())
	}
	if aggs.Err() != nil {
		fmt.Println("Error:", aggs.Err())
	}
}

Websocket examples:

package main

import (
	"fmt"
	"log"
	polygonws "github.com/polygon-io/client-go/websocket"
)

func main() {
	config := polygonws.Config{
		APIKey: "your_api_key",
		Feed:   polygonws.RealTime,
		Market: polygonws.Futures,
	}
	client, err := polygonws.New(config)
	if err != nil {
		log.Fatal(err)
	}
	defer client.Close()

	err = client.Subscribe(polygonws.FuturesTrades, "ESZ4")
	if err != nil {
		log.Fatal(err)
	}

	err = client.Connect()
	if err != nil {
		log.Fatal(err)
	}

	for msg := range client.Output() {
		fmt.Println(msg)
	}
}

This is a work in progress PR and will get updates as things evolve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant