stream

package
v3.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 19 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConnectCalledMultipleTimes is returned when Connect has been called multiple times on a single client
	ErrConnectCalledMultipleTimes = errors.New("tried to call Connect multiple times")
	// ErrNoConnected is returned when the client did not receive the welcome
	// message from the server
	ErrNoConnected = errors.New("did not receive connected message")
	// ErrBadAuthResponse is returned when the client could not successfully authenticate
	ErrBadAuthResponse = errors.New("did not receive authenticated message")
	// ErrSubResponse is returned when the client's subscription request was not
	// acknowledged
	ErrSubResponse = errors.New("did not receive subscribed message")
	// ErrSubscriptionChangeBeforeConnect is returned when the client attempts to change subscriptions before
	// calling Connect
	ErrSubscriptionChangeBeforeConnect = errors.New("subscription change attempted before calling Connect")
	// ErrSubscriptionChangeAfterTerminated is returned when client attempts to change subscriptions after
	// the client has been terminated
	ErrSubscriptionChangeAfterTerminated = errors.New("subscription change after client termination")
	// ErrSubscriptionChangeAlreadyInProgress is returned when a subscription change is called concurrently
	// with another
	ErrSubscriptionChangeAlreadyInProgress = errors.New("subscription change already in progress")
	// ErrSubscriptionChangeInterrupted is returned when a subscription change was in progress when the client
	// has terminated
	ErrSubscriptionChangeInterrupted = errors.New("subscription change interrupted by client termination")
	// ErrSubscriptionChangeTimeout is returned when the server does not return a proper
	// subscription response after a subscription change request.
	ErrSubscriptionChangeTimeout = errors.New("subscription change timeout")
)
View Source
var (
	// ErrInvalidCredentials is returned when invalid credentials have been sent by the user.
	ErrInvalidCredentials error = errorMessage{/* contains filtered or unexported fields */}
	// ErrSymbolLimitExceeded is returned when the client has subscribed to too many symbols
	ErrSymbolLimitExceeded error = errorMessage{/* contains filtered or unexported fields */}
	// ErrConnectionLimitExceeded is returned when the client has exceeded their connection limit
	ErrConnectionLimitExceeded error = errorMessage{/* contains filtered or unexported fields */}
	// ErrSlowClient is returned when the server has detected a slow client. In this case there's no guarantee
	// that all prior messages are sent to the server so a subscription acknowledgement may not arrive
	ErrSlowClient error = errorMessage{/* contains filtered or unexported fields */}
	// ErrInsufficientSubscription is returned when the user does not have proper
	// subscription for the requested feed (e.g. SIP)
	ErrInsufficientSubscription error = errorMessage{/* contains filtered or unexported fields */}
	// ErrSubscriptionChangeInvalidForFeed is returned when a subscription change is invalid for the feed.
	ErrSubscriptionChangeInvalidForFeed error = errorMessage{/* contains filtered or unexported fields */}
	// ErrInsufficientScope is returned when the token used by the user doesn't have proper scopes
	// for data stream
	ErrInsufficientScope error = errorMessage{/* contains filtered or unexported fields */}
)

Functions

This section is empty.

Types

type Bar

type Bar struct {
	Symbol     string
	Open       float64
	High       float64
	Low        float64
	Close      float64
	Volume     uint64
	Timestamp  time.Time
	TradeCount uint64
	VWAP       float64
}

Bar is an aggregate of trades

func (Bar) MarshalEasyJSON added in v3.2.1

func (v Bar) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Bar) MarshalJSON added in v3.2.1

func (v Bar) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Bar) UnmarshalEasyJSON added in v3.2.1

func (v *Bar) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Bar) UnmarshalJSON added in v3.2.1

func (v *Bar) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type CryptoBar

type CryptoBar struct {
	Symbol     string
	Exchange   string
	Open       float64
	High       float64
	Low        float64
	Close      float64
	Volume     float64
	Timestamp  time.Time
	TradeCount uint64
	VWAP       float64
}

func (CryptoBar) MarshalEasyJSON added in v3.2.1

func (v CryptoBar) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (CryptoBar) MarshalJSON added in v3.2.1

func (v CryptoBar) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*CryptoBar) UnmarshalEasyJSON added in v3.2.1

func (v *CryptoBar) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*CryptoBar) UnmarshalJSON added in v3.2.1

func (v *CryptoBar) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type CryptoClient

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

CryptoClient is a client that connects to an Alpaca stream server and handles communication both ways.

After constructing, Connect() must be called before any subscription changes are called. Connect keeps the connection alive and reestablishes it until a configured number of retries has not been exceeded.

Terminated() returns a channel that the client sends an error to when it has terminated. A client can not be reused once it has terminated!

SubscribeTo... and UnsubscribeFrom... can be used to modify subscriptions and the handler used to process incoming trades/quotes/bars. These block until an irrecoverable error occurs or if they succeed.

Note that subscription changes can not be called concurrently.

func NewCryptoClient

func NewCryptoClient(feed marketdata.CryptoFeed, opts ...CryptoOption) *CryptoClient

NewCryptoClient returns a new CryptoClient that will connect to the crypto feed and whose default configurations are modified by opts.

func (*CryptoClient) Connect

func (cc *CryptoClient) Connect(ctx context.Context) error

Connect establishes a connection and **reestablishes it when errors occur** as long as the configured number of retries has not been exceeded.

It blocks until the connection has been established for the first time (or it failed to do so).

**Should only be called once!**

func (*CryptoClient) SubscribeToBars

func (cc *CryptoClient) SubscribeToBars(handler func(CryptoBar), symbols ...string) error

func (*CryptoClient) SubscribeToDailyBars

func (cc *CryptoClient) SubscribeToDailyBars(handler func(CryptoBar), symbols ...string) error

func (*CryptoClient) SubscribeToOrderbooks

func (cc *CryptoClient) SubscribeToOrderbooks(handler func(CryptoOrderbook), symbols ...string) error

func (*CryptoClient) SubscribeToQuotes

func (cc *CryptoClient) SubscribeToQuotes(handler func(CryptoQuote), symbols ...string) error

func (*CryptoClient) SubscribeToTrades

func (cc *CryptoClient) SubscribeToTrades(handler func(CryptoTrade), symbols ...string) error

func (*CryptoClient) SubscribeToUpdatedBars

func (cc *CryptoClient) SubscribeToUpdatedBars(handler func(CryptoBar), symbols ...string) error

func (CryptoClient) Terminated

func (c CryptoClient) Terminated() <-chan error

Terminated returns a channel that the client sends an error to when it has terminated. The channel is also closed upon termination.

func (*CryptoClient) UnsubscribeFromBars

func (cc *CryptoClient) UnsubscribeFromBars(symbols ...string) error

func (*CryptoClient) UnsubscribeFromDailyBars

func (cc *CryptoClient) UnsubscribeFromDailyBars(symbols ...string) error

func (*CryptoClient) UnsubscribeFromOrderbooks

func (cc *CryptoClient) UnsubscribeFromOrderbooks(symbols ...string) error

func (*CryptoClient) UnsubscribeFromQuotes

func (cc *CryptoClient) UnsubscribeFromQuotes(symbols ...string) error

func (*CryptoClient) UnsubscribeFromTrades

func (cc *CryptoClient) UnsubscribeFromTrades(symbols ...string) error

func (*CryptoClient) UnsubscribeFromUpdatedBars

func (cc *CryptoClient) UnsubscribeFromUpdatedBars(symbols ...string) error

type CryptoOption

type CryptoOption interface {
	// contains filtered or unexported methods
}

CryptoOption is a configuration option for the CryptoClient

func WithCryptoBars

func WithCryptoBars(handler func(CryptoBar), symbols ...string) CryptoOption

WithCryptoBars configures initial bar symbols to subscribe to and the handler

func WithCryptoDailyBars

func WithCryptoDailyBars(handler func(CryptoBar), symbols ...string) CryptoOption

WithCryptoDailyBars configures initial daily bar symbols to subscribe to and the handler

func WithCryptoOrderbooks

func WithCryptoOrderbooks(handler func(CryptoOrderbook), symbols ...string) CryptoOption

WithCryptoOrderbooks configures initial orderbook symbols to subscribe to and the handler

func WithCryptoQuotes

func WithCryptoQuotes(handler func(CryptoQuote), symbols ...string) CryptoOption

WithCryptoQuotes configures initial quote symbols to subscribe to and the handler

func WithCryptoTrades

func WithCryptoTrades(handler func(CryptoTrade), symbols ...string) CryptoOption

WithCryptoTrades configures initial trade symbols to subscribe to and the handler

func WithCryptoUpdatedBars

func WithCryptoUpdatedBars(handler func(CryptoBar), symbols ...string) CryptoOption

WithCryptoUpdatedBars configures initial updated bar symbols to subscribe to and the handler

type CryptoOrderbook

type CryptoOrderbook struct {
	Symbol    string
	Exchange  string
	Timestamp time.Time
	Bids      []CryptoOrderbookEntry
	Asks      []CryptoOrderbookEntry
	Reset     bool
}

func (CryptoOrderbook) MarshalEasyJSON added in v3.2.1

func (v CryptoOrderbook) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (CryptoOrderbook) MarshalJSON added in v3.2.1

func (v CryptoOrderbook) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*CryptoOrderbook) UnmarshalEasyJSON added in v3.2.1

func (v *CryptoOrderbook) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*CryptoOrderbook) UnmarshalJSON added in v3.2.1

func (v *CryptoOrderbook) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type CryptoOrderbookEntry

type CryptoOrderbookEntry struct {
	Price float64
	Size  float64
}

func (CryptoOrderbookEntry) MarshalEasyJSON added in v3.2.1

func (v CryptoOrderbookEntry) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (CryptoOrderbookEntry) MarshalJSON added in v3.2.1

func (v CryptoOrderbookEntry) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*CryptoOrderbookEntry) UnmarshalEasyJSON added in v3.2.1

func (v *CryptoOrderbookEntry) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*CryptoOrderbookEntry) UnmarshalJSON added in v3.2.1

func (v *CryptoOrderbookEntry) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type CryptoQuote

type CryptoQuote struct {
	Symbol    string
	Exchange  string
	BidPrice  float64
	BidSize   float64
	AskPrice  float64
	AskSize   float64
	Timestamp time.Time
}

func (CryptoQuote) MarshalEasyJSON added in v3.2.1

func (v CryptoQuote) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (CryptoQuote) MarshalJSON added in v3.2.1

func (v CryptoQuote) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*CryptoQuote) UnmarshalEasyJSON added in v3.2.1

func (v *CryptoQuote) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*CryptoQuote) UnmarshalJSON added in v3.2.1

func (v *CryptoQuote) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type CryptoTrade

type CryptoTrade struct {
	ID        int64
	Symbol    string
	Exchange  string
	Price     float64
	Size      float64
	Timestamp time.Time
	TakerSide marketdata.TakerSide
}

func (CryptoTrade) MarshalEasyJSON added in v3.2.1

func (v CryptoTrade) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (CryptoTrade) MarshalJSON added in v3.2.1

func (v CryptoTrade) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*CryptoTrade) UnmarshalEasyJSON added in v3.2.1

func (v *CryptoTrade) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*CryptoTrade) UnmarshalJSON added in v3.2.1

func (v *CryptoTrade) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type LULD

type LULD struct {
	Symbol         string
	LimitUpPrice   float64
	LimitDownPrice float64
	Indicator      string
	Timestamp      time.Time
	Tape           string
}

LULD is a Limit Up Limit Down message

func (LULD) MarshalEasyJSON added in v3.2.1

func (v LULD) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (LULD) MarshalJSON added in v3.2.1

func (v LULD) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*LULD) UnmarshalEasyJSON added in v3.2.1

func (v *LULD) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*LULD) UnmarshalJSON added in v3.2.1

func (v *LULD) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Logger

type Logger interface {
	Infof(format string, v ...interface{})
	Warnf(format string, v ...interface{})
	Errorf(format string, v ...interface{})
}

Logger wraps methods for leveled, formatted logging.

func DefaultLogger

func DefaultLogger() Logger

DefaultLogger returns a Logger that uses the standard go log package to print leveled logs to the standard error.

func ErrorOnlyLogger

func ErrorOnlyLogger() Logger

ErrorOnlyLogger returns a Logger that only logs errors to the standard error.

type News

type News struct {
	ID        int
	Author    string
	CreatedAt time.Time
	UpdatedAt time.Time
	Headline  string
	Summary   string
	Content   string
	URL       string
	Symbols   []string
}

func (News) MarshalEasyJSON added in v3.2.1

func (v News) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (News) MarshalJSON added in v3.2.1

func (v News) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*News) UnmarshalEasyJSON added in v3.2.1

func (v *News) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*News) UnmarshalJSON added in v3.2.1

func (v *News) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type NewsClient

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

func NewNewsClient

func NewNewsClient(opts ...NewsOption) *NewsClient

NewNewsClient returns a new NewsClient that will connect the news stream.

func (*NewsClient) Connect

func (nc *NewsClient) Connect(ctx context.Context) error

Connect establishes a connection and **reestablishes it when errors occur** as long as the configured number of retries has not been exceeded.

It blocks until the connection has been established for the first time (or it failed to do so).

**Should only be called once!**

func (*NewsClient) SubscribeToNews

func (nc *NewsClient) SubscribeToNews(handler func(News), symbols ...string) error

func (NewsClient) Terminated

func (c NewsClient) Terminated() <-chan error

Terminated returns a channel that the client sends an error to when it has terminated. The channel is also closed upon termination.

func (*NewsClient) UnsubscribeFromNews

func (nc *NewsClient) UnsubscribeFromNews(symbols ...string) error

type NewsOption

type NewsOption interface {
	// contains filtered or unexported methods
}

func WithNews

func WithNews(handler func(News), symbols ...string) NewsOption

WithNew configures initial symbols to subscribe to and the handler

type Option

type Option interface {
	StockOption
	CryptoOption
	OptionOption
	NewsOption
}

Option is a configuration option that can be used for both StockClient and CryptoClient

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL configures the base URL

func WithBufferSize

func WithBufferSize(size int) Option

WithBufferSize sets the size for the buffer that is used for messages received from the server

func WithConnectCallback

func WithConnectCallback(callback func()) Option

WithConnectCallback runs the callback function after the streaming connection is setup. If the stream terminates and can't reconnect, the connect callback will timeout one second after reaching the end of the stream's maintenance (if it is still running). This is to avoid the callback blocking the parent thread.

func WithCredentials

func WithCredentials(key, secret string) Option

WithCredentials configures the key and secret to use

func WithDisconnectCallback

func WithDisconnectCallback(callback func()) Option

WithDisconnectCallback runs the callback function after the streaming connection disconnects. If the stream is terminated and can't reconnect, the disconnect callback will timeout one second after reaching the end of the stream's maintenance (if it is still running). This is to avoid the callback blocking the parent thread.

func WithLogger

func WithLogger(logger Logger) Option

WithLogger configures the logger

func WithProcessors

func WithProcessors(count int) Option

WithProcessors configures how many goroutines should process incoming messages. Increasing this past 1 means that the order of processing is not necessarily the same as the order of arrival the from server.

func WithReconnectSettings

func WithReconnectSettings(limit int, delay time.Duration) Option

WithReconnectSettings configures how many consecutive connection errors should be accepted and the delay (that is multiplied by the number of consecutive errors) between retries. limit = 0 means the client will try restarting indefinitely unless it runs into an irrecoverable error (such as invalid credentials).

type OptionClient added in v3.3.0

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

OptionClient is a client that connects to an Alpaca stream server and handles communication both ways.

After constructing, Connect() must be called before any subscription changes are called. Connect keeps the connection alive and reestablishes it until a configured number of retries has not been exceeded.

Terminated() returns a channel that the client sends an error to when it has terminated. A client can not be reused once it has terminated!

SubscribeTo... and UnsubscribeFrom... can be used to modify subscriptions and the handler used to process incoming trades/quotes/bars. These block until an irrecoverable error occurs or if they succeed.

Note that subscription changes can not be called concurrently.

func NewOptionClient added in v3.3.0

func NewOptionClient(feed marketdata.OptionFeed, opts ...OptionOption) *OptionClient

NewOptionClient returns a new OptionClient that will connect to the option feed and whose default configurations are modified by opts.

func (*OptionClient) Connect added in v3.3.0

func (cc *OptionClient) Connect(ctx context.Context) error

Connect establishes a connection and **reestablishes it when errors occur** as long as the configured number of retries has not been exceeded.

It blocks until the connection has been established for the first time (or it failed to do so).

**Should only be called once!**

func (*OptionClient) SubscribeToQuotes added in v3.3.0

func (cc *OptionClient) SubscribeToQuotes(handler func(OptionQuote), symbols ...string) error

func (*OptionClient) SubscribeToTrades added in v3.3.0

func (cc *OptionClient) SubscribeToTrades(handler func(OptionTrade), symbols ...string) error

func (OptionClient) Terminated added in v3.3.0

func (c OptionClient) Terminated() <-chan error

Terminated returns a channel that the client sends an error to when it has terminated. The channel is also closed upon termination.

func (*OptionClient) UnsubscribeFromQuotes added in v3.3.0

func (cc *OptionClient) UnsubscribeFromQuotes(symbols ...string) error

func (*OptionClient) UnsubscribeFromTrades added in v3.3.0

func (cc *OptionClient) UnsubscribeFromTrades(symbols ...string) error

type OptionOption added in v3.3.0

type OptionOption interface {
	// contains filtered or unexported methods
}

func WithOptionQuotes added in v3.3.0

func WithOptionQuotes(handler func(OptionQuote), symbols ...string) OptionOption

WithOptionQuotes configures initial quote symbols to subscribe to and the handler

func WithOptionTrades added in v3.3.0

func WithOptionTrades(handler func(OptionTrade), symbols ...string) OptionOption

WithOptionTrades configures initial trade symbols to subscribe to and the handler

type OptionQuote added in v3.3.0

type OptionQuote struct {
	Symbol      string
	BidExchange string
	BidPrice    float64
	BidSize     uint32
	AskExchange string
	AskPrice    float64
	AskSize     uint32
	Timestamp   time.Time
	Condition   string
}

OptionQuote is an option quote from the market

func (OptionQuote) MarshalEasyJSON added in v3.3.0

func (v OptionQuote) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (OptionQuote) MarshalJSON added in v3.3.0

func (v OptionQuote) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*OptionQuote) UnmarshalEasyJSON added in v3.3.0

func (v *OptionQuote) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*OptionQuote) UnmarshalJSON added in v3.3.0

func (v *OptionQuote) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type OptionTrade added in v3.3.0

type OptionTrade struct {
	Symbol    string
	Exchange  string
	Price     float64
	Size      uint32
	Timestamp time.Time
	Condition string
}

OptionTrade is an option trade that happened on the market

func (OptionTrade) MarshalEasyJSON added in v3.3.0

func (v OptionTrade) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (OptionTrade) MarshalJSON added in v3.3.0

func (v OptionTrade) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*OptionTrade) UnmarshalEasyJSON added in v3.3.0

func (v *OptionTrade) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*OptionTrade) UnmarshalJSON added in v3.3.0

func (v *OptionTrade) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Quote

type Quote struct {
	Symbol      string
	BidExchange string
	BidPrice    float64
	BidSize     uint32
	AskExchange string
	AskPrice    float64
	AskSize     uint32
	Timestamp   time.Time
	Conditions  []string
	Tape        string
	// contains filtered or unexported fields
}

Quote is a stock quote from the market

func (Quote) Internal

func (q Quote) Internal() quoteInternal

Internal contains internal fields. There aren't any behavioural or backward compatibility promises for them: they can be empty or removed in the future. You should not use them at all.

func (Quote) MarshalEasyJSON added in v3.2.1

func (v Quote) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Quote) MarshalJSON added in v3.2.1

func (v Quote) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Quote) UnmarshalEasyJSON added in v3.2.1

func (v *Quote) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Quote) UnmarshalJSON added in v3.2.1

func (v *Quote) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type StockOption

type StockOption interface {
	// contains filtered or unexported methods
}

StockOption is a configuration option for the StockClient

func WithBars

func WithBars(handler func(Bar), symbols ...string) StockOption

WithBars configures initial bar symbols to subscribe to and the handler

func WithCancelErrors

func WithCancelErrors(handler func(TradeCancelError)) StockOption

WithCancelErrors configures initial trade cancel errors handler. This does not create any new subscriptions because cancel errors are subscribed automatically together with trades. No need to pass in symbols.

func WithCorrections

func WithCorrections(handler func(TradeCorrection)) StockOption

WithCorrections configures initial trade corrections handler. This does not create any new subscriptions because corrections are subscribed automatically together with trades. No need to pass in symbols.

func WithDailyBars

func WithDailyBars(handler func(Bar), symbols ...string) StockOption

WithDailyBars configures initial daily bar symbols to subscribe to and the handler

func WithLULDs

func WithLULDs(handler func(LULD), symbols ...string) StockOption

WithLULDs configures initial LULD symbols to subscribe to and the handler

func WithQuotes

func WithQuotes(handler func(Quote), symbols ...string) StockOption

WithQuotes configures initial quote symbols to subscribe to and the handler

func WithStatuses

func WithStatuses(handler func(TradingStatus), symbols ...string) StockOption

WithStatuses configures initial trading status symbols to subscribe to and the handler

func WithTrades

func WithTrades(handler func(Trade), symbols ...string) StockOption

WithTrades configures initial trade symbols to subscribe to and the handler

func WithUpdatedBars

func WithUpdatedBars(handler func(Bar), symbols ...string) StockOption

WithUpdatedBars configures initial updated bar symbols to subscribe to and the handler

type StocksClient

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

StocksClient is a client that connects to the Alpaca stream server and handles communication both ways.

After constructing, Connect() must be called before any subscription changes are called. Connect keeps the connection alive and reestablishes it until a configured number of retries has not been exceeded.

Terminated() returns a channel that the client sends an error to when it has terminated. A client can not be reused once it has terminated!

SubscribeTo... and UnsubscribeFrom... can be used to modify subscriptions and the handler used to process incoming trades/quotes/bars/etc. These block until an irrecoverable error occurs or if they succeed.

Note that subscription changes can not be called concurrently.

func NewStocksClient

func NewStocksClient(feed marketdata.Feed, opts ...StockOption) *StocksClient

NewStocksClient returns a new StocksClient that will connect to feed data feed and whose default configurations are modified by opts.

func (*StocksClient) Connect

func (sc *StocksClient) Connect(ctx context.Context) error

Connect establishes a connection and **reestablishes it when errors occur** as long as the configured number of retries has not been exceeded.

It blocks until the connection has been established for the first time (or it failed to do so).

**Should only be called once!**

func (*StocksClient) RegisterCancelErrors

func (sc *StocksClient) RegisterCancelErrors(handler func(TradeCancelError))

func (*StocksClient) RegisterCorrections

func (sc *StocksClient) RegisterCorrections(handler func(TradeCorrection))

func (*StocksClient) SubscribeToBars

func (sc *StocksClient) SubscribeToBars(handler func(Bar), symbols ...string) error

func (*StocksClient) SubscribeToDailyBars

func (sc *StocksClient) SubscribeToDailyBars(handler func(Bar), symbols ...string) error

func (*StocksClient) SubscribeToLULDs

func (sc *StocksClient) SubscribeToLULDs(handler func(LULD), symbols ...string) error

func (*StocksClient) SubscribeToQuotes

func (sc *StocksClient) SubscribeToQuotes(handler func(Quote), symbols ...string) error

func (*StocksClient) SubscribeToStatuses

func (sc *StocksClient) SubscribeToStatuses(handler func(TradingStatus), symbols ...string) error

func (*StocksClient) SubscribeToTrades

func (sc *StocksClient) SubscribeToTrades(handler func(Trade), symbols ...string) error

func (*StocksClient) SubscribeToUpdatedBars

func (sc *StocksClient) SubscribeToUpdatedBars(handler func(Bar), symbols ...string) error

func (StocksClient) Terminated

func (c StocksClient) Terminated() <-chan error

Terminated returns a channel that the client sends an error to when it has terminated. The channel is also closed upon termination.

func (*StocksClient) UnregisterCancelErrors

func (sc *StocksClient) UnregisterCancelErrors()

func (*StocksClient) UnregisterCorrections

func (sc *StocksClient) UnregisterCorrections()

func (*StocksClient) UnsubscribeFromBars

func (sc *StocksClient) UnsubscribeFromBars(symbols ...string) error

func (*StocksClient) UnsubscribeFromDailyBars

func (sc *StocksClient) UnsubscribeFromDailyBars(symbols ...string) error

func (*StocksClient) UnsubscribeFromLULDs

func (sc *StocksClient) UnsubscribeFromLULDs(symbols ...string) error

func (*StocksClient) UnsubscribeFromQuotes

func (sc *StocksClient) UnsubscribeFromQuotes(symbols ...string) error

func (*StocksClient) UnsubscribeFromStatuses

func (sc *StocksClient) UnsubscribeFromStatuses(symbols ...string) error

func (*StocksClient) UnsubscribeFromTrades

func (sc *StocksClient) UnsubscribeFromTrades(symbols ...string) error

func (*StocksClient) UnsubscribeFromUpdatedBars

func (sc *StocksClient) UnsubscribeFromUpdatedBars(symbols ...string) error

type Trade

type Trade struct {
	ID         int64
	Symbol     string
	Exchange   string
	Price      float64
	Size       uint32
	Timestamp  time.Time
	Conditions []string
	Tape       string
	// contains filtered or unexported fields
}

Trade is a stock trade that happened on the market

func (Trade) Internal

func (t Trade) Internal() tradeInternal

Internal contains internal fields. There aren't any behavioural or backward compatibility promises for them: they can be empty or removed in the future. You should not use them at all.

func (Trade) MarshalEasyJSON added in v3.2.1

func (v Trade) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Trade) MarshalJSON added in v3.2.1

func (v Trade) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Trade) UnmarshalEasyJSON added in v3.2.1

func (v *Trade) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Trade) UnmarshalJSON added in v3.2.1

func (v *Trade) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type TradeCancelError

type TradeCancelError struct {
	Symbol            string
	ID                int64
	Exchange          string
	Price             float64
	Size              uint32
	CancelErrorAction string
	Tape              string
	Timestamp         time.Time
}

func (TradeCancelError) MarshalEasyJSON added in v3.2.1

func (v TradeCancelError) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (TradeCancelError) MarshalJSON added in v3.2.1

func (v TradeCancelError) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*TradeCancelError) UnmarshalEasyJSON added in v3.2.1

func (v *TradeCancelError) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*TradeCancelError) UnmarshalJSON added in v3.2.1

func (v *TradeCancelError) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type TradeCorrection

type TradeCorrection struct {
	Symbol              string
	Exchange            string
	OriginalID          int64
	OriginalPrice       float64
	OriginalSize        uint32
	OriginalConditions  []string
	CorrectedID         int64
	CorrectedPrice      float64
	CorrectedSize       uint32
	CorrectedConditions []string
	Tape                string
	Timestamp           time.Time
}

func (TradeCorrection) MarshalEasyJSON added in v3.2.1

func (v TradeCorrection) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (TradeCorrection) MarshalJSON added in v3.2.1

func (v TradeCorrection) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*TradeCorrection) UnmarshalEasyJSON added in v3.2.1

func (v *TradeCorrection) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*TradeCorrection) UnmarshalJSON added in v3.2.1

func (v *TradeCorrection) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type TradingStatus

type TradingStatus struct {
	Symbol     string
	StatusCode string
	StatusMsg  string
	ReasonCode string
	ReasonMsg  string
	Timestamp  time.Time
	Tape       string
}

TradingStatus is a halt or resume status for a security

func (TradingStatus) MarshalEasyJSON added in v3.2.1

func (v TradingStatus) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (TradingStatus) MarshalJSON added in v3.2.1

func (v TradingStatus) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*TradingStatus) UnmarshalEasyJSON added in v3.2.1

func (v *TradingStatus) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*TradingStatus) UnmarshalJSON added in v3.2.1

func (v *TradingStatus) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

Jump to

Keyboard shortcuts

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