polygonws

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client defines a client to the Polygon WebSocket API.

func New

func New(config Config) (*Client, error)

New creates a client for the Polygon WebSocket API.

func (*Client) Close

func (c *Client) Close()

Close attempt to gracefully close the connection to the server.

func (*Client) Connect

func (c *Client) Connect() error

Connect dials the WebSocket server and starts the read/write and process threads. If any subscription messages are pushed before connecting, it will also send those to the server.

func (*Client) Error

func (c *Client) Error() <-chan error

Error returns an error channel. If the client hits a fatal error (e.g. auth failed), it will push an error to this channel and close the connection.

func (*Client) Output

func (c *Client) Output() <-chan any

Output returns the output queue.

func (*Client) Subscribe

func (c *Client) Subscribe(topic Topic, tickers ...string) error

Subscribe sends a subscription message for a topic and set of tickers. If no tickers are passed, it will subscribe to all tickers for a given topic.

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(topic Topic, tickers ...string) error

Unsubscribe sends a message to unsubscribe from a topic and set of tickers. If no tickers are passed, it will unsubscribe from all tickers for a given topic.

type Config

type Config struct {
	// APIKey is the API key used to authenticate against the server.
	APIKey string

	// Feed is the data feed (e.g. Delayed, RealTime) which represents the server host.
	Feed Feed

	// Market is the type of market (e.g. Stocks, Crypto) used to connect to the server.
	Market Market

	// MaxRetries is the maximum number of retry attempts that will occur. If the maximum
	// is reached, the client will close the connection. Omitting this will cause the
	// client to reconnect indefinitely until the user closes it.
	MaxRetries *uint64

	// RawData is a flag indicating whether data should be returned as a raw JSON.
	RawData bool

	// Log is an optional logger. Any logger implementation can be used as long as it
	// implements the basic Logger interface. Omitting this will disable client logging.
	Log Logger
}

Config is a set of WebSocket client options.

type Feed

type Feed string

Feed is the data feed (e.g. Delayed, RealTime) which represents the server host.

const (
	Delayed      Feed = "wss://delayed.polygon.io"
	RealTime     Feed = "wss://socket.polygon.io"
	Nasdaq       Feed = "wss://nasdaqfeed.polygon.io"
	PolyFeed     Feed = "wss://polyfeed.polygon.io"
	PolyFeedPlus Feed = "wss://polyfeedplus.polygon.io"
)

type Logger

type Logger interface {
	Debugf(template string, args ...any)
	Infof(template string, args ...any)
	Errorf(template string, args ...any)
}

Logger is a basic logger interface used for logging within the client.

type Market

type Market string

Market is the type of market (e.g. Stocks, Crypto) used to connect to the server.

const (
	Stocks  Market = "stocks"
	Options Market = "options"
	Forex   Market = "forex"
	Crypto  Market = "crypto"
)

type Topic

type Topic uint8

Topic is the data type used to subscribe and retrieve data from the server.

const (
	StocksSecAggs    Topic = 11
	StocksMinAggs    Topic = 12
	StocksTrades     Topic = 13
	StocksQuotes     Topic = 14
	StocksImbalances Topic = 15
	StocksLULD       Topic = 16

	OptionsSecAggs Topic = 31
	OptionsMinAggs Topic = 32
	OptionsTrades  Topic = 33
	OptionsQuotes  Topic = 34

	ForexMinAggs Topic = 51
	ForexQuotes  Topic = 52

	CryptoMinAggs Topic = 71
	CryptoTrades  Topic = 72
	CryptoQuotes  Topic = 73
	CryptoL2Book  Topic = 74
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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