Documentation
¶
Index ¶
- Constants
- Variables
- func ParseMessage(rawMsg []byte) (interface{}, error)
- type CryptoPrice
- type CryptoPricesOptions
- type CryptoQuote
- type CryptoTrade
- type EndOfDayPricesOptions
- type EndpointType
- type ForexPricesOptions
- type ForexQuote
- type FundamentalsDailyOptions
- type FundamentalsStatement
- type FundamentalsStatementsOptions
- type IEXPrice
- type IEXQuote
- type IEXRealTimePricesOptions
- type IEXTrade
- type IEXWebSocketData
- type NewsFeedOptions
- type NewsItem
- type Option
- type PriceData
- type RawMessage
- type Response
- type RestClient
- func (c *RestClient) GetCryptoPrices(ctx context.Context, opts *CryptoPricesOptions) ([]*CryptoPrice, error)
- func (c *RestClient) GetEndOfDayPrices(ctx context.Context, ticker string, opts *EndOfDayPricesOptions) ([]*PriceData, error)
- func (c *RestClient) GetForexPrices(ctx context.Context, ticker string, opts *ForexPricesOptions) ([]*PriceData, error)
- func (c *RestClient) GetFundamentalsDaily(ctx context.Context, ticker string, opts *FundamentalsDailyOptions) ([]*FundamentalsStatement, error)
- func (c *RestClient) GetFundamentalsStatements(ctx context.Context, ticker string, opts *FundamentalsStatementsOptions) ([]*FundamentalsStatement, error)
- func (c *RestClient) GetIEXRealTimePrices(ctx context.Context, opts *IEXRealTimePricesOptions) ([]*IEXPrice, error)
- func (c *RestClient) GetNewsFeed(ctx context.Context, opts *NewsFeedOptions) ([]*NewsItem, error)
- func (c *RestClient) GetTickerMetadata(ctx context.Context, ticker string) (*TickerMetadata, error)
- func (c *RestClient) Search(ctx context.Context, opts *SearchOptions) ([]*SearchResult, error)
- type RestConfig
- type RestOption
- func WithBaseURL(baseURL string) RestOption
- func WithHTTPClient(client *http.Client) RestOption
- func WithRequestsPerSecond(rps int) RestOption
- func WithRetryDelay(delay time.Duration) RestOption
- func WithRetryMax(max uint32) RestOption
- func WithRetryPolicy(policy func(resp *http.Response, err error) error) RestOption
- func WithStrategy(strategy backoffpolicy.Strategy) RestOption
- func WithTimeout(timeout time.Duration) RestOption
- type SearchOptions
- type SearchResult
- type SubscribeRequest
- type SubscriptionConfirmation
- type TickerMetadata
- type Time
- type WebSocketMessage
- type WebsocketClient
- func (c *WebsocketClient) Close() error
- func (c *WebsocketClient) Connect(ctx context.Context, onError func(error)) error
- func (c *WebsocketClient) Subscribe(ticker string, handler func(message []byte, err error)) error
- func (c *WebsocketClient) SubscribeCryptoEndpointWithHandlers(ticker string, cryptoQuoteHandler func(msg *CryptoQuote, err error), ...) error
- func (c *WebsocketClient) SubscribeForexEndpointWithHandler(ticker string, forexQuoteHandler func(msg *ForexQuote, err error)) error
- func (c *WebsocketClient) SubscribeIEXEndpointWithHandlers(ticker string, iexQuoteHandler func(msg *IEXQuote, err error), ...) error
- func (c *WebsocketClient) Unsubscribe(ticker string) error
- type WebsocketConfig
Constants ¶
const ( StrategyLinear = backoffpolicy.StrategyLinear StrategyExponential = backoffpolicy.StrategyExponential )
Variables ¶
var ( ErrAlreadySubscribed = errors.New("already subscribed to ticker") ErrNotConnected = errors.New("websocket not connected") ErrAlreadyConnected = errors.New("already connected") )
WebSocket client errors
Functions ¶
func ParseMessage ¶
ParseMessage routes to appropriate parser
Types ¶
type CryptoPrice ¶
type CryptoPrice struct {
Ticker string `json:"ticker"`
BaseCurrency string `json:"baseCurrency"`
QuoteCurrency string `json:"quoteCurrency"`
Exchange string `json:"exchange"`
Date Time `json:"date"`
Open float64 `json:"open"`
High float64 `json:"high"`
Low float64 `json:"low"`
Close float64 `json:"close"`
Volume float64 `json:"volume"`
VolumeNotional float64 `json:"volumeNotional"`
TradesDone int `json:"tradesDone"`
}
type CryptoPricesOptions ¶
type CryptoPricesOptions struct {
Tickers string `url:"tickers,omitempty"`
StartDate string `url:"startDate,omitempty"`
EndDate string `url:"endDate,omitempty"`
ResampleFreq string `url:"resampleFreq,omitempty"`
Exchanges string `url:"exchanges,omitempty"`
ConsolidatedBaseCurrency bool `url:"consolidatedBaseCurrency,omitempty"`
ConvertCurrency string `url:"convertCurrency,omitempty"`
}
type CryptoQuote ¶
type CryptoQuote struct {
UpdateType string
Ticker string
Date time.Time
Exchange string
BidSize float64
BidPrice float64
MidPrice float64
AskSize float64
AskPrice float64
}
func ParseCryptoQuote ¶
func ParseCryptoQuote(data []interface{}) (*CryptoQuote, error)
type CryptoTrade ¶
type CryptoTrade struct {
UpdateType string
Ticker string
Date time.Time
Exchange string
LastSize float64
LastPrice float64
}
Crypto types
func ParseCryptoTrade ¶
func ParseCryptoTrade(data []interface{}) (*CryptoTrade, error)
type EndOfDayPricesOptions ¶
type EndpointType ¶
type EndpointType string
EndpointType defines the type for WebSocket endpoints.
const ( EndpointTypeIEX EndpointType = "iex" EndpointTypeCrypto EndpointType = "crypto" EndpointTypeForex EndpointType = "fx" )
Constants for Tiingo WebSocket endpoints.
type ForexPricesOptions ¶
type ForexQuote ¶
type ForexQuote struct {
UpdateType string
Ticker string
Date time.Time
BidSize float64
BidPrice float64
MidPrice float64
AskSize float64
AskPrice float64
}
Forex types
func ParseForexQuote ¶
func ParseForexQuote(data []interface{}) (*ForexQuote, error)
type FundamentalsStatement ¶
type IEXPrice ¶
type IEXPrice struct {
Ticker string `json:"ticker"`
Timestamp Time `json:"timestamp"`
QuoteTimestamp Time `json:"quoteTimestamp"`
LastSaleTimestamp Time `json:"lastSaleTimestamp"`
Last float64 `json:"last"`
LastSize float64 `json:"lastSize"`
BidSize float64 `json:"bidSize"`
BidPrice float64 `json:"bidPrice"`
AskSize float64 `json:"askSize"`
AskPrice float64 `json:"askPrice"`
Volume float64 `json:"volume"`
High float64 `json:"high"`
Low float64 `json:"low"`
Open float64 `json:"open"`
PrevClose float64 `json:"prevClose"`
Mid float64 `json:"mid"`
}
type IEXQuote ¶
type IEXQuote struct {
UpdateType string
Date time.Time
Nanoseconds int64
Ticker string
BidSize *int32
BidPrice *float64
MidPrice *float64
AskPrice *float64
AskSize *int32
LastPrice *float64
LastSize *int32
Halted int32
AfterHours int32
IntermarketSweep *int32
Oddlot *int32
NMSRule611 *int32
}
func ParseIEXQuote ¶
type IEXRealTimePricesOptions ¶
type IEXRealTimePricesOptions struct {
Tickers string `url:"tickers,omitempty"`
ResampleFreq string `url:"resampleFreq,omitempty"`
Columns string `url:"columns,omitempty"`
AfterHours bool `url:"afterHours,omitempty"`
ForceFill bool `url:"forceFill,omitempty"`
IncludeRawExchangeData bool `url:"includeRawExchangeData,omitempty"`
}
type IEXTrade ¶
type IEXTrade struct {
UpdateType string
Date time.Time
Nanoseconds int64
Ticker string
BidSize *int32
BidPrice *float64
MidPrice *float64
AskPrice *float64
AskSize *int32
LastPrice *float64
LastSize *int32
Halted int32
AfterHours int32
IntermarketSweep int32
Oddlot int32
NMSRule611 int32
}
IEX types
func ParseIEXTrade ¶
type IEXWebSocketData ¶
type IEXWebSocketData struct {
Ticker string `json:"ticker"`
Timestamp Time `json:"timestamp"`
Last float64 `json:"last"`
LastSize float64 `json:"lastSize"`
TngoLast float64 `json:"tngoLast"`
BidSize float64 `json:"bidSize"`
BidPrice float64 `json:"bidPrice"`
AskSize float64 `json:"askSize"`
AskPrice float64 `json:"askPrice"`
}
type NewsFeedOptions ¶
type NewsFeedOptions struct {
Tickers string `url:"tickers,omitempty"`
Tags string `url:"tags,omitempty"`
Sources string `url:"sources,omitempty"`
StartDate string `url:"startDate,omitempty"`
EndDate string `url:"endDate,omitempty"`
Limit int `url:"limit,omitempty"`
Offset int `url:"offset,omitempty"`
SortBy string `url:"sortBy,omitempty"`
}
type NewsItem ¶
type NewsItem struct {
ID int64 `json:"id"`
Title string `json:"title"`
URL string `json:"url"`
Description string `json:"description"`
PublishedDate Time `json:"publishedDate"`
CrawlDate Time `json:"crawlDate"`
Source string `json:"source"`
Tags []string `json:"tags"`
Tickers []string `json:"tickers"`
}
type Option ¶
type Option func(*WebsocketClient)
Option is a functional option for configuring the WebsocketClient.
func WithLivenessCheck ¶
WithLivenessCheck sets the interval for checking liveness.
func WithLivenessTimeout ¶
WithLivenessTimeout sets the duration after which an inactive connection is considered stale.
func WithThresholdLevel ¶
WithThresholdLevel sets the subscription threshold level.
type PriceData ¶
type PriceData struct {
Date Time `json:"date"`
Close float64 `json:"close"`
High float64 `json:"high"`
Low float64 `json:"low"`
Open float64 `json:"open"`
Volume float64 `json:"volume"`
AdjClose float64 `json:"adjClose"`
AdjHigh float64 `json:"adjHigh"`
AdjLow float64 `json:"adjLow"`
AdjOpen float64 `json:"adjOpen"`
AdjVolume float64 `json:"adjVolume"`
DivCash float64 `json:"divCash"`
SplitFactor float64 `json:"splitFactor"`
}
type RawMessage ¶
type RawMessage struct {
MessageType string `json:"messageType"`
Service string `json:"service"`
Data []interface{} `json:"data"`
}
RawMessage from WebSocket
type RestClient ¶
type RestClient struct {
// contains filtered or unexported fields
}
RestClient handles communication with the Tiingo REST API.
func NewRestClient ¶
func NewRestClient(ctx context.Context, apiKey string, options ...RestOption) (*RestClient, error)
NewRestClient creates a new client for the REST API.
func (*RestClient) GetCryptoPrices ¶
func (c *RestClient) GetCryptoPrices(ctx context.Context, opts *CryptoPricesOptions) ([]*CryptoPrice, error)
GetCryptoPrices retrieves cryptocurrency price data.
func (*RestClient) GetEndOfDayPrices ¶
func (c *RestClient) GetEndOfDayPrices(ctx context.Context, ticker string, opts *EndOfDayPricesOptions) ([]*PriceData, error)
GetEndOfDayPrices retrieves end-of-day price data for a ticker.
func (*RestClient) GetForexPrices ¶
func (c *RestClient) GetForexPrices(ctx context.Context, ticker string, opts *ForexPricesOptions) ([]*PriceData, error)
GetForexPrices retrieves forex price data.
func (*RestClient) GetFundamentalsDaily ¶
func (c *RestClient) GetFundamentalsDaily(ctx context.Context, ticker string, opts *FundamentalsDailyOptions) ([]*FundamentalsStatement, error)
GetFundamentalsDaily retrieves daily fundamental data for a ticker.
func (*RestClient) GetFundamentalsStatements ¶
func (c *RestClient) GetFundamentalsStatements(ctx context.Context, ticker string, opts *FundamentalsStatementsOptions) ([]*FundamentalsStatement, error)
GetFundamentalsStatements retrieves fundamental statements for a ticker.
func (*RestClient) GetIEXRealTimePrices ¶
func (c *RestClient) GetIEXRealTimePrices(ctx context.Context, opts *IEXRealTimePricesOptions) ([]*IEXPrice, error)
GetIEXRealTimePrices retrieves IEX real-time price data.
func (*RestClient) GetNewsFeed ¶
func (c *RestClient) GetNewsFeed(ctx context.Context, opts *NewsFeedOptions) ([]*NewsItem, error)
GetNewsFeed retrieves news articles.
func (*RestClient) GetTickerMetadata ¶
func (c *RestClient) GetTickerMetadata(ctx context.Context, ticker string) (*TickerMetadata, error)
GetTickerMetadata retrieves metadata for a given stock ticker.
func (*RestClient) Search ¶
func (c *RestClient) Search(ctx context.Context, opts *SearchOptions) ([]*SearchResult, error)
Search retrieves search results for a query.
type RestConfig ¶
type RestConfig struct {
BaseURL string
RequestsPerSec int
RetryMax uint32
RetryDelay time.Duration
Timeout time.Duration
HTTPClient *http.Client
RetryPolicy func(resp *http.Response, err error) error
RetryStrategy backoffpolicy.Strategy
}
RestConfig holds configuration for the REST client.
type RestOption ¶
type RestOption func(*RestConfig)
RestOption is a functional option for configuring the RestClient.
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) RestOption
WithHTTPClient sets a custom HTTP client.
func WithRequestsPerSecond ¶
func WithRequestsPerSecond(rps int) RestOption
WithRequestsPerSecond sets the rate limit for requests.
func WithRetryDelay ¶
func WithRetryDelay(delay time.Duration) RestOption
WithRetryDelay sets the delay between retry attempts.
func WithRetryMax ¶
func WithRetryMax(max uint32) RestOption
WithRetryMax sets the maximum number of retry attempts.
func WithRetryPolicy ¶
func WithRetryPolicy(policy func(resp *http.Response, err error) error) RestOption
WithRetryPolicy sets a custom retry policy.
func WithStrategy ¶
func WithStrategy(strategy backoffpolicy.Strategy) RestOption
WithStrategy sets the backoff strategy for retries.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) RestOption
WithTimeout sets the HTTP request timeout.
type SearchOptions ¶
type SearchResult ¶
type SubscribeRequest ¶
type SubscribeRequest struct {
EventName string `json:"eventName"`
Authorization string `json:"authorization"`
EventData map[string]interface{} `json:"eventData,omitempty"`
}
SubscribeRequest is the payload for subscribing/unsubscribing.
type SubscriptionConfirmation ¶
type SubscriptionConfirmation struct {
SubscriptionID int `json:"subscriptionId"`
Tickers []string `json:"tickers"`
ThresholdLevel string `json:"thresholdLevel"`
}
SubscriptionConfirmation defines the structure of the subscription confirmation message.
type TickerMetadata ¶
type WebSocketMessage ¶
type WebSocketMessage struct {
MessageType string `json:"messageType"`
Service string `json:"service"`
Response *Response `json:"response"`
Data json.RawMessage `json:"data"`
}
WebSocketMessage represents the generic wrapper for all incoming messages.
type WebsocketClient ¶
type WebsocketClient struct {
// contains filtered or unexported fields
}
WebsocketClient handles the WebSocket connection and data stream.
func NewWebsocketClient ¶
func NewWebsocketClient(apiKey string, endpointType EndpointType, options ...Option) *WebsocketClient
NewWebsocketClient creates a new client for the WebSocket API.
func (*WebsocketClient) Close ¶
func (c *WebsocketClient) Close() error
Close gracefully disconnects the websocket connection and waits for all routines to finish.
func (*WebsocketClient) Connect ¶
func (c *WebsocketClient) Connect(ctx context.Context, onError func(error)) error
Connect establishes a websocket connection with an error callback for connection-level errors.
func (*WebsocketClient) Subscribe ¶
func (c *WebsocketClient) Subscribe(ticker string, handler func(message []byte, err error)) error
func (*WebsocketClient) SubscribeCryptoEndpointWithHandlers ¶
func (c *WebsocketClient) SubscribeCryptoEndpointWithHandlers(ticker string, cryptoQuoteHandler func(msg *CryptoQuote, err error), cryptoTradeHandler func(msg *CryptoTrade, err error)) error
func (*WebsocketClient) SubscribeForexEndpointWithHandler ¶
func (c *WebsocketClient) SubscribeForexEndpointWithHandler(ticker string, forexQuoteHandler func(msg *ForexQuote, err error)) error
func (*WebsocketClient) SubscribeIEXEndpointWithHandlers ¶
func (*WebsocketClient) Unsubscribe ¶
func (c *WebsocketClient) Unsubscribe(ticker string) error
Unsubscribe removes a subscription for a ticker.