polygon

package
v1.6.22 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinuteAggs = "AM"
	SecondAggs = "A"
	Trades     = "T"
	Quotes     = "Q"
)
View Source
const (
	MaxConnectionAttempts = 3
)

Variables

View Source
var (
	// DefaultClient is the default Polygon client using the
	// environment variable set credentials
	DefaultClient = NewClient(common.Credentials())
)

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

APIError wraps the detailed code and message supplied by Polygon's API for debugging purposes

func (*APIError) Error

func (e *APIError) Error() string

type AggTick

type AggTick struct {
	Open              float64 `json:"o"`
	High              float64 `json:"h"`
	Low               float64 `json:"l"`
	Close             float64 `json:"c"`
	Volume            float64 `json:"v"`
	EpochMilliseconds int64   `json:"t"`
	Items             int64   `json:"n"` // v2 response only
}

AggTick is the structure that contains the actual tick data included in a HistoricAggregates response

type AggType

type AggType string

AggType used in the HistoricAggregates response

const (
	// Minute timeframe aggregates
	Minute AggType = "minute"
	// Day timeframe aggregates
	Day AggType = "day"
)

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a Polygon REST API client

func NewClient

func NewClient(credentials *common.APIKey) *Client

NewClient creates a new Polygon client with specified credentials

func (*Client) GetHistoricAggregates

func (c *Client) GetHistoricAggregates(
	symbol string,
	resolution AggType,
	from, to *time.Time,
	limit *int) (*HistoricAggregates, error)

GetHistoricAggregates requests Polygon's v1 REST API for historic aggregates for the provided resolution based on the provided query parameters.

func (*Client) GetHistoricAggregatesV2

func (c *Client) GetHistoricAggregatesV2(
	symbol string,
	multiplier int,
	resolution AggType,
	from, to *time.Time,
	unadjusted *bool) (*HistoricAggregatesV2, error)

GetHistoricAggregates requests Polygon's v2 REST API for historic aggregates for the provided resolution based on the provided query parameters.

func (*Client) GetHistoricQuotes deprecated

func (c *Client) GetHistoricQuotes(symbol, date string) (totalQuotes *HistoricQuotes, err error)

GetHistoricQuotes requests polygon's REST API for historic quotes on the provided date.

Deprecated: This v1 endpoint should no longer be used, as it will be removed from the Polygon API in the future. Please use GetHistoricQuotesV2 instead.

func (*Client) GetHistoricQuotesV2

func (c *Client) GetHistoricQuotesV2(ticker string, date string, opts *HistoricTicksV2Params) (*HistoricQuotesV2, error)

GetHistoricQuotesV2 requests polygon's REST API for historic trades on the provided date.

func (*Client) GetHistoricTrades deprecated

func (c *Client) GetHistoricTrades(
	symbol string,
	date string,
	opts *GetHistoricTradesParams) (totalTrades *HistoricTrades, err error)

GetHistoricTrades requests polygon's REST API for historic trades on the provided date.

Deprecated: This v1 endpoint should no longer be used, as it will be removed from the Polygon API in the future. Please use GetHistoricTradesV2 instead.

func (*Client) GetHistoricTradesV2

func (c *Client) GetHistoricTradesV2(ticker string, date string, opts *HistoricTicksV2Params) (*HistoricTradesV2, error)

GetHistoricTradesV2 requests polygon's REST API for historic trades on the provided date.

func (*Client) GetStockExchanges

func (c *Client) GetStockExchanges() ([]StockExchange, error)

GetStockExchanges requests available stock and equity exchanges on polygon.io

type GetHistoricTradesParams

type GetHistoricTradesParams struct {
	Offset int64 `json:"offset"`
	Limit  int64 `json:"limit"`
}

type HistoricAggregates

type HistoricAggregates struct {
	Symbol        string  `json:"symbol"`
	AggregateType AggType `json:"aggType"`
	Map           struct {
		O string `json:"o"`
		C string `json:"c"`
		H string `json:"h"`
		L string `json:"l"`
		V string `json:"v"`
		D string `json:"d"`
	} `json:"map"`
	Ticks []AggTick `json:"ticks"`
}

HistoricAggregates is the structure that defines aggregate data served through Polygon's v1 REST API.

func GetHistoricAggregates

func GetHistoricAggregates(
	symbol string,
	resolution AggType,
	from, to *time.Time,
	limit *int) (*HistoricAggregates, error)

GetHistoricAggregates requests polygon's REST API for historic aggregates for the provided resolution based on the provided query parameters using the default Polygon client.

type HistoricAggregatesV2

type HistoricAggregatesV2 struct {
	Symbol       string    `json:"ticker"`
	Adjusted     bool      `json:"adjusted"`
	QueryCount   int       `json:"queryCount"`
	ResultsCount int       `json:"resultsCount"`
	Ticks        []AggTick `json:"results"`
}

HistoricAggregatesV2 is the structure that defines aggregate data served through Polygon's v2 REST API.

type HistoricQuotes

type HistoricQuotes struct {
	Day string `json:"day"`
	Map struct {
		AE string `json:"aE"`
		AP string `json:"aP"`
		AS string `json:"aS"`
		BE string `json:"bE"`
		BP string `json:"bP"`
		BS string `json:"bS"`
		C  string `json:"c"`
		T  string `json:"t"`
	} `json:"map"`
	MsLatency int         `json:"msLatency"`
	Status    string      `json:"status"`
	Symbol    string      `json:"symbol"`
	Ticks     []QuoteTick `json:"ticks"`
	Type      string      `json:"type"`
}

HistoricQuotes is the structure that defines quote data served through polygon's REST API.

func GetHistoricQuotes

func GetHistoricQuotes(symbol, date string) (totalQuotes *HistoricQuotes, err error)

GetHistoricQuotes requests polygon's REST API for historic quotes on the provided date using the default Polygon client.

type HistoricQuotesV2

type HistoricQuotesV2 struct {
	ResultsCount int64              `json:"results_count"`
	Ticker       string             `json:"ticker"`
	Results      []QuoteTickV2      `json:"results"`
	Map          map[string]MapItem `json:"map"`
}

HistoricQuotesV2 is the structure that defines trade data served through polygon's REST API.

type HistoricTicksV2Params

type HistoricTicksV2Params struct {
	Timestamp      int64 `json:"timestamp"`
	TimestampLimit int64 `json:"timestamp_limit"`
	Reverse        bool  `json:"reverse"`
	Limit          int64 `json:"limit"`
}

type HistoricTrades

type HistoricTrades struct {
	Day string `json:"day"`
	Map struct {
		C1 string `json:"c1"`
		C2 string `json:"c2"`
		C3 string `json:"c3"`
		C4 string `json:"c4"`
		E  string `json:"e"`
		P  string `json:"p"`
		S  string `json:"s"`
		T  string `json:"t"`
	} `json:"map"`
	MsLatency int         `json:"msLatency"`
	Status    string      `json:"status"`
	Symbol    string      `json:"symbol"`
	Ticks     []TradeTick `json:"ticks"`
	Type      string      `json:"type"`
}

HistoricTrades is the structure that defines trade data served through polygon's REST API.

func GetHistoricTrades

func GetHistoricTrades(
	symbol string,
	date string,
	opts *GetHistoricTradesParams) (totalTrades *HistoricTrades, err error)

GetHistoricTrades requests polygon's REST API for historic trades on the provided date using the default Polygon client.

type HistoricTradesV2

type HistoricTradesV2 struct {
	ResultsCount int64              `json:"results_count"`
	Ticker       string             `json:"ticker"`
	Results      []TradeTickV2      `json:"results"`
	Map          map[string]MapItem `json:"map"`
}

HistoricTradesV2 is the structure that defines trade data served through polygon's REST API.

type MapItem

type MapItem struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

type PolgyonServerMsg

type PolgyonServerMsg struct {
	Event string `json:"ev"`
}

PolygonServerMsg contains the field that is present in all responses to identify their type

type PolygonAuthMsg

type PolygonAuthMsg struct {
	Event   string `json:"ev"`
	Status  string `json:"status"`
	Message string `json:"message"`
}

type PolygonClientMsg

type PolygonClientMsg struct {
	Action string `json:"action"`
	Params string `json:"params"`
}

PolygonClientMsg is the standard message sent by clients of the stream interface

type QuoteTick

type QuoteTick struct {
	Timestamp   int64   `json:"t"`
	BidExchange string  `json:"bE"`
	AskExchange string  `json:"aE"`
	BidPrice    float64 `json:"bP"`
	AskPrice    float64 `json:"aP"`
	BidSize     int     `json:"bS"`
	AskSize     int     `json:"aS"`
	Condition   int     `json:"c"`
}

QuoteTick is the structure that contains the actual tick data included in a HistoricQuotes response

type QuoteTickV2

type QuoteTickV2 struct {
	SIPTimestamp         *int64   `json:"t"`
	ParticipantTimestamp *int64   `json:"y"`
	TRFTimestamp         *int64   `json:"f"`
	SequenceNumber       *int     `json:"q"`
	Indicators           *[]int   `json:"i"`
	BidExchange          *int     `json:"x"`
	AskExchange          *int     `json:"X"`
	TRFID                *int     `json:"r"`
	Size                 *int     `json:"s"`
	Conditions           *[]int   `json:"c"`
	BidPrice             *float64 `json:"p"`
	AskPrice             *float64 `json:"P"`
	BidSize              *int     `json:"s"`
	AskSize              *int     `json:"S"`
	Tape                 *int     `json:"z"`
}

QuoteTickV2 is the structure that contains the actual tick data included in a HistoricQuotesV2 response

type StockExchange

type StockExchange struct {
	Id     int64  `json:"id"`
	Type   string `json:"type"`
	Market string `json:"market"`
	Mic    string `json:"mic"`
	Name   string `json:"name"`
	Tape   string `json:"tape"`
}

Exchange defines the Stocks / Equities "Exchange" endpoint response

func GetStockExchanges

func GetStockExchanges() ([]StockExchange, error)

GetStockExchanges queries Polygon.io REST API for information on available stock and equities exchanges

type Stream

type Stream struct {
	sync.Mutex
	sync.Once

	Credentials *common.APIKey
	// contains filtered or unexported fields
}

func GetStream

func GetStream() *Stream

GetStream returns the singleton Polygon stream structure.

func (*Stream) Close

func (s *Stream) Close() error

Close gracefully closes the Polygon stream.

func (*Stream) Subscribe

func (s *Stream) Subscribe(channel string, handler func(msg interface{})) (err error)

Subscribe to the specified Polygon stream channel.

type StreamAggregate

type StreamAggregate struct {
	Event             string  `json:"ev"`
	Symbol            string  `json:"sym"`
	Volume            int     `json:"v"`
	AccumulatedVolume int     `json:"av"`
	OpeningPrice      float64 `json:"op"`
	VWAP              float64 `json:"vw"`
	OpenPrice         float64 `json:"o"`
	ClosePrice        float64 `json:"c"`
	HighPrice         float64 `json:"h"`
	LowPrice          float64 `json:"l"`
	Average           float64 `json:"a"`
	StartTimestamp    int64   `json:"s"`
	EndTimestamp      int64   `json:"e"`
}

StreamAggregate is the structure that defines an aggregate that polygon transmits via websocket protocol.

type StreamQuote

type StreamQuote struct {
	Symbol      string  `json:"sym"`
	Condition   int     `json:"c"`
	BidExchange int     `json:"bx"`
	AskExchange int     `json:"ax"`
	BidPrice    float64 `json:"bp"`
	AskPrice    float64 `json:"ap"`
	BidSize     int64   `json:"bs"`
	AskSize     int64   `json:"as"`
	Timestamp   int64   `json:"t"`
}

StreamQuote is the structure that defines a quote that polygon transmits via websocket protocol.

type StreamTrade

type StreamTrade struct {
	Symbol     string  `json:"sym"`
	Exchange   int     `json:"x"`
	TradeID    string  `json:"i"`
	Price      float64 `json:"p"`
	Size       int64   `json:"s"`
	Timestamp  int64   `json:"t"`
	Conditions []int   `json:"c"`
}

StreamTrade is the structure that defines a trade that polygon transmits via websocket protocol.

type SymbolsMetadata

type SymbolsMetadata struct {
	Symbols []struct {
		Symbol  string    `json:"symbol"`
		Name    string    `json:"name"`
		Type    string    `json:"type"`
		Updated time.Time `json:"updated"`
		IsOTC   bool      `json:"isOTC"`
		URL     string    `json:"url"`
	} `json:"symbols"`
}

SymbolsMetadata is the structure that defines symbol metadata served through polygon's REST API.

type TradeTick

type TradeTick struct {
	Timestamp  int64   `json:"t"`
	Price      float64 `json:"p"`
	Size       int     `json:"s"`
	Exchange   string  `json:"e"`
	Condition1 int     `json:"c1"`
	Condition2 int     `json:"c2"`
	Condition3 int     `json:"c3"`
	Condition4 int     `json:"c4"`
}

TradeTick is the structure that contains the actual tick data included in a HistoricTrades response

type TradeTickV2

type TradeTickV2 struct {
	SIPTimestamp         *int64   `json:"t"`
	ParticipantTimestamp *int64   `json:"y"`
	TRFTimestamp         *int64   `json:"f"`
	SequenceNumber       *int     `json:"q"`
	ID                   *string  `json:"i"`
	OrigID               *string  `json:"I"`
	Exchange             *int     `json:"x"`
	TRFID                *int     `json:"r"`
	Size                 *int     `json:"s"`
	Conditions           *[]int   `json:"c"`
	Price                *float64 `json:"p"`
	Tape                 *int     `json:"z"`
	Correction           *int     `json:"e"`
}

TradeTickV2 is the structure that contains the actual tick data included in a HistoricTradesV2 response

Jump to

Keyboard shortcuts

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