Documentation ¶
Index ¶
- Variables
- type Bar
- type CryptoBar
- type CryptoClient
- type CryptoOption
- func WithCryptoBars(handler func(CryptoBar), symbols ...string) CryptoOption
- func WithCryptoDailyBars(handler func(CryptoBar), symbols ...string) CryptoOption
- func WithCryptoQuotes(handler func(CryptoQuote), symbols ...string) CryptoOption
- func WithCryptoTrades(handler func(CryptoTrade), symbols ...string) CryptoOption
- type CryptoQuote
- type CryptoTrade
- type Logger
- type Option
- type Quote
- type StockOption
- func WithBars(handler func(Bar), symbols ...string) StockOption
- func WithDailyBars(handler func(Bar), symbols ...string) StockOption
- func WithQuotes(handler func(Quote), symbols ...string) StockOption
- func WithStatuses(handler func(TradingStatus), symbols ...string) StockOption
- func WithTrades(handler func(Trade), symbols ...string) StockOption
- type StocksClient
- type StreamClient
- type Trade
- type TradingStatus
Constants ¶
This section is empty.
Variables ¶
var ErrBadAuthResponse = errors.New("did not receive authenticated message")
ErrBadAuthResponse is returned when the client could not successfully authenticate
var ErrConnectCalledMultipleTimes = errors.New("tried to call Connect multiple times")
ErrConnectCalledMultipleTimes is returned when Connect has been called multiple times on a single client
var ErrConnectionLimitExceeded = errors.New("connection limit exceeded")
ErrConnectionLimitExceeded is returned when the client has exceeded their connection limit
var ErrInvalidCredentials = errors.New("invalid credentials")
ErrInvalidCredentials is returned when invalid credentials have been sent by the user
var ErrNoConnected = errors.New("did not receive connected message")
ErrNoConnected is returned when the client did not receive the welcome message from the server
var ErrSlowClient = errors.New("slow client")
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
var ErrSubResponse = errors.New("did not receive subscribed message")
ErrSubResponse is returned when the client's subscription request was not acknowledged
var ErrSubscriptionChangeAfterTerminated = errors.New("subscription change after client termination")
ErrSubscriptionChangeAfterTerminated is returned when client attempts to change subscriptions after the client has been terminated
var ErrSubscriptionChangeAlreadyInProgress = errors.New("subscription change already in progress")
ErrSubscriptionChangeAlreadyInProgress is returned when a subscription change is called concurrently with another
var ErrSubscriptionChangeBeforeConnect = errors.New("subscription change attempted before calling Connect")
ErrSubscriptionChangeBeforeConnect is returned when the client attempts to change subscriptions before calling Connect
var ErrSubscriptionChangeInterrupted = errors.New("subscription change interrupted by client termination")
ErrSubscriptionChangeInterrupted is returned when a subscription change was in progress when the client has terminated
var ErrSymbolLimitExceeded = errors.New("symbol limit exceeded")
ErrSymbolLimitExceeded is returned when the client has subscribed to too many symbols
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 }
Bar is an aggregate of trades
type CryptoClient ¶
type CryptoClient interface { StreamClient SubscribeToTrades(handler func(trade CryptoTrade), symbols ...string) error UnsubscribeFromTrades(symbols ...string) error SubscribeToQuotes(handler func(quote CryptoQuote), symbols ...string) error UnsubscribeFromQuotes(symbols ...string) error SubscribeToBars(handler func(bar CryptoBar), symbols ...string) error UnsubscribeFromBars(symbols ...string) error SubscribeToDailyBars(handler func(bar CryptoBar), symbols ...string) error UnsubscribeFromDailyBars(symbols ...string) error }
CryptoClient is a client that connects to an Alpaca Data V2 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(opts ...CryptoOption) CryptoClient
NewCryptoClient returns a new CryptoClient that will connect to the crypto feed and whose default configurations are modified by opts.
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 inital bar symbols to subscribe to and the handler
func WithCryptoDailyBars ¶
func WithCryptoDailyBars(handler func(CryptoBar), symbols ...string) CryptoOption
WithCryptoDailyBars configures inital daily bar symbols to subscribe to and the handler
func WithCryptoQuotes ¶
func WithCryptoQuotes(handler func(CryptoQuote), symbols ...string) CryptoOption
WithCryptoQuotes configures inital quote symbols to subscribe to and the handler
func WithCryptoTrades ¶
func WithCryptoTrades(handler func(CryptoTrade), symbols ...string) CryptoOption
WithCryptoTrades configures inital trade symbols to subscribe to and the handler
type CryptoQuote ¶
type CryptoTrade ¶
type Option ¶
type Option interface { StockOption CryptoOption }
Option is a configuration option that can be used for both StockClient and CryptoClient
func WithBufferSize ¶
WithBufferSize sets the size for the buffer that is used for messages received from the server
func WithCredentials ¶
WithCredentials configures the key and secret to use
func WithProcessors ¶
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 ¶
WithReconnectSettings configures how many consecutive connection errors should be accepted and the delay (that is multipled 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 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 }
Quote is a stock quote from the market
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 inital bar symbols to subscribe to and the handler
func WithDailyBars ¶
func WithDailyBars(handler func(Bar), symbols ...string) StockOption
WithDailyBars configures inital daily bar symbols to subscribe to and the handler
func WithQuotes ¶
func WithQuotes(handler func(Quote), symbols ...string) StockOption
WithQuotes configures inital quote symbols to subscribe to and the handler
func WithStatuses ¶
func WithStatuses(handler func(TradingStatus), symbols ...string) StockOption
WithStatuses configures inital trading status symbols to subscribe to and the handler
func WithTrades ¶
func WithTrades(handler func(Trade), symbols ...string) StockOption
WithTrades configures inital trade symbols to subscribe to and the handler
type StocksClient ¶
type StocksClient interface { StreamClient SubscribeToTrades(handler func(trade Trade), symbols ...string) error UnsubscribeFromTrades(symbols ...string) error SubscribeToQuotes(handler func(quote Quote), symbols ...string) error UnsubscribeFromQuotes(symbols ...string) error SubscribeToBars(handler func(bar Bar), symbols ...string) error UnsubscribeFromBars(symbols ...string) error SubscribeToDailyBars(handler func(bar Bar), symbols ...string) error UnsubscribeFromDailyBars(symbols ...string) error SubscribeToStatuses(handler func(ts TradingStatus), symbols ...string) error UnsubscribeFromStatuses(symbols ...string) error }
StocksClient is a client that connects to an Alpaca Data V2 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 NewStocksClient ¶
func NewStocksClient(feed string, opts ...StockOption) StocksClient
NewStocksClient returns a new StocksClient that will connect to feed data feed and whose default configurations are modified by opts.
type StreamClient ¶
type StreamClient interface { // Connect establishes a connection and **reestablishes it when errors occur** // as long as the configured number of retires 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!** Connect(ctx context.Context) error // Terminated returns a channel that the client sends an error to when it has terminated. // The channel is also closed upon termination. Terminated() <-chan error }