polygonws

package
v1.16.4 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 13 Imported by: 3

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 attempts 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 added in v0.7.0

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 or raw bytes. If BypassRawDataRouting is unset
	// then the data will be returned as raw JSON, otherwise it will be raw bytes.
	RawData bool

	// BypassRawDataRouting is a flag that interacts with the RawData flag. If RawData flag is unset then this flag is ignored.
	// If RawData is `true`, then this flag indicates whether the raw data should be parsed as json.RawMessage
	// and routed via the client's internal logic (`BypassRawDataRouting=false`), or returned to the application code as []byte (`BypassRawDataRouting=true`).
	// If this flag is `true`, it's up to the caller to handle all message types including auth and subscription responses.
	BypassRawDataRouting 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"
	StarterFeed                       Feed = "wss://starterfeed.polygon.io"
	LaunchpadFeed                     Feed = "wss://launchpad.polygon.io"
	BusinessFeed                      Feed = "wss://business.polygon.io"
	EdgxBusinessFeed                  Feed = "wss://edgx-business.polygon.io"
	DelayedBusinessFeed               Feed = "wss://delayed-business.polygon.io"
	DelayedEdgxBusinessFeed           Feed = "wss://delayed-edgx-business.polygon.io"
	DelayedNasdaqLastSaleBusinessFeed Feed = "wss://delayed-nasdaq-last-sale-business.polygon.io"
	DelayedNasdaqBasicFeed            Feed = "wss://delayed-nasdaq-basic-business.polygon.io"
	DelayedFullMarketBusinessFeed     Feed = "wss://delayed-fullmarket-business.polygon.io"
	FullMarketBusinessFeed            Feed = "wss://fullmarket-business.polygon.io"
	NasdaqLastSaleBusinessFeed        Feed = "wss://nasdaq-last-sale-business.polygon.io"
	NasdaqBasicBusinessFeed           Feed = "wss://nasdaq-basic-business.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"
	Indices Market = "indices"
)

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
	StocksLaunchpadMinAggs Topic = 17
	StocksLaunchpadValue   Topic = 18

	OptionsSecAggs          Topic = 31
	OptionsMinAggs          Topic = 32
	OptionsTrades           Topic = 33
	OptionsQuotes           Topic = 34
	OptionsLaunchpadMinAggs Topic = 35
	OptionsLaunchpadValue   Topic = 36

	ForexSecAggs          Topic = 51
	ForexMinAggs          Topic = 52
	ForexQuotes           Topic = 53
	ForexLaunchpadMinAggs Topic = 54
	ForexLaunchpadValue   Topic = 55

	CryptoSecAggs          Topic = 71
	CryptoMinAggs          Topic = 72
	CryptoTrades           Topic = 73
	CryptoQuotes           Topic = 74
	CryptoL2Book           Topic = 75
	CryptoLaunchpadMinAggs Topic = 76
	CryptoLaunchpadValue   Topic = 77

	IndexSecAggs Topic = 90
	IndexMinAggs Topic = 91
	IndexValue   Topic = 92

	BusinessFairMarketValue Topic = 100
)

The launchpad topics should be used for any asset class when connecting to the Launchpad feed

Directories

Path Synopsis
fmv

Jump to

Keyboard shortcuts

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