Documentation
¶
Overview ¶
Package models defines the data structures used to represent the responses from the Market Data API. It includes models for stock quotes, options quotes, stock candles, market status, and more. Each model is designed to parse and validate the JSON responses from the API, providing a structured way to interact with market data. The package also includes methods for unpacking these responses into more usable Go data types, such as converting timestamps to time.Time objects.
Index ¶
- func CombineTickerResponses(responses []*TickersResponse) (map[string]Ticker, error)
- func SaveToCSV(tickerMap map[string]Ticker, filename string) error
- type IndexCandle
- type IndexQuote
- type IndexQuotesResponse
- type IndicesCandlesResponse
- func (icr *IndicesCandlesResponse) IsValid() bool
- func (icr *IndicesCandlesResponse) MarshalJSON() ([]byte, error)
- func (icr *IndicesCandlesResponse) String() string
- func (icr *IndicesCandlesResponse) UnmarshalJSON(data []byte) error
- func (icr *IndicesCandlesResponse) Unpack() ([]IndexCandle, error)
- func (icr *IndicesCandlesResponse) Validate() error
- type MarketStatusReport
- type MarketStatusResponse
- func (msr *MarketStatusResponse) GetClosedDates() ([]time.Time, error)
- func (msr *MarketStatusResponse) GetDateRange() (*dates.DateRange, error)
- func (msr *MarketStatusResponse) GetOpenDates() ([]time.Time, error)
- func (msr *MarketStatusResponse) IsValid() bool
- func (msr *MarketStatusResponse) String() string
- func (msr *MarketStatusResponse) Unpack() ([]MarketStatusReport, error)
- type OptionLookupResponse
- type OptionQuote
- type OptionQuotesResponse
- type OptionsExpirationsResponse
- type OptionsStrikes
- type OptionsStrikesResponse
- type StockCandle
- type StockCandlesResponse
- func (s *StockCandlesResponse) GetDateRange() (dates.DateRange, error)
- func (s *StockCandlesResponse) IsValid() bool
- func (s *StockCandlesResponse) MarshalJSON() ([]byte, error)
- func (s *StockCandlesResponse) PruneOutsideDateRange(dr dates.DateRange) error
- func (s *StockCandlesResponse) String() string
- func (s *StockCandlesResponse) UnmarshalJSON(data []byte) error
- func (scr *StockCandlesResponse) Unpack() ([]StockCandle, error)
- func (s *StockCandlesResponse) Validate() error
- type StockEarningsReport
- type StockEarningsResponse
- type StockNews
- type StockNewsResponse
- type StockQuote
- type StockQuotesResponse
- type Ticker
- type TickersResponse
- func (tr *TickersResponse) IsValid() bool
- func (tr *TickersResponse) MarshalJSON() ([]byte, error)
- func (tr *TickersResponse) String() string
- func (tr *TickersResponse) ToMap() (map[string]Ticker, error)
- func (tr *TickersResponse) UniqueSymbols() ([]string, error)
- func (tr *TickersResponse) Unpack() ([]Ticker, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CombineTickerResponses ¶
func CombineTickerResponses(responses []*TickersResponse) (map[string]Ticker, error)
CombineTickerResponses combines multiple TickersResponses into a single map.
This function takes a slice of pointers to TickersResponse structs and combines them into a single map where the key is a string representing the ticker symbol and the value is a Ticker struct. It handles concurrent access to the map using a mutex to ensure thread safety.
Parameters:
- responses: A slice of pointers to TickersResponse structs that are to be combined.
Returns:
- A map where the key is a string representing the ticker symbol and the value is a Ticker struct.
- An error if any of the TickersResponse structs cannot be converted to a map or if any other error occurs during the process.
func SaveToCSV ¶
SaveToCSV writes the contents of tickerMap to a CSV file specified by filename.
Parameters:
- tickerMap: A map where the key is a string representing the ticker symbol, and the value is a Ticker struct.
- filename: The name of the file to which the CSV data will be written.
Returns:
- An error if writing to the CSV file fails, otherwise nil.
Types ¶
type IndexCandle ¶
IndexCandle represents a single candle data point with time, open, high, low, and close values.
func (IndexCandle) String ¶
func (ic IndexCandle) String() string
String returns a string representation of the IndexCandle with the time in America/New_York timezone.
Returns:
- A formatted string containing the time, open, high, low, and close values.
type IndexQuote ¶
type IndexQuote struct { Symbol string // Symbol is the stock symbol or ticker. Last float64 // Last is the last traded price. Change *float64 // Change represents the change in price, can be nil if not applicable. ChangePct *float64 // ChangePct represents the percentage change in price, can be nil if not applicable. High52 *float64 // High52 is the 52-week high price, can be nil if not applicable. Low52 *float64 // Low52 is the 52-week low price, can be nil if not applicable. Volume int64 // Volume is the number of shares traded. Updated time.Time // Updated is the timestamp of the last update. }
IndexQuote represents a single quote for an index. It includes the symbol, last price, change, percentage change, 52-week high, 52-week low, volume, and update timestamp.
func (IndexQuote) String ¶
func (iq IndexQuote) String() string
String returns a string representation of the IndexQuote.
Returns:
- A string that represents the IndexQuote.
type IndexQuotesResponse ¶
type IndexQuotesResponse struct { Symbol []string `json:"symbol"` // Symbols are the stock symbols or tickers. Last []float64 `json:"last"` // Last contains the last traded prices. Change []*float64 `json:"change,omitempty"` // Change represents the change in price, can be nil if not applicable. ChangePct []*float64 `json:"changepct,omitempty"` // ChangePct represents the percentage change in price, can be nil if not applicable. High52 *[]float64 `json:"52weekHigh,omitempty"` // High52 points to a slice of 52-week high prices, can be nil if not applicable. Low52 *[]float64 `json:"52weekLow,omitempty"` // Low52 points to a slice of 52-week low prices, can be nil if not applicable. Updated []int64 `json:"updated"` // Updated contains timestamps of the last updates. }
IndexQuotesResponse represents the response structure for index quotes. It includes slices for symbols, last prices, changes, percentage changes, 52-week highs, 52-week lows, and update timestamps.
func (*IndexQuotesResponse) String ¶
func (iqr *IndexQuotesResponse) String() string
String returns a string representation of the IndexQuotesResponse.
Returns:
- A string that represents the IndexQuotesResponse.
func (*IndexQuotesResponse) Unpack ¶
func (iqr *IndexQuotesResponse) Unpack() ([]IndexQuote, error)
Unpack transforms the IndexQuotesResponse into a slice of IndexQuote.
Returns:
- A slice of IndexQuote derived from the IndexQuotesResponse.
- An error if any issues occur during the unpacking process.
type IndicesCandlesResponse ¶
type IndicesCandlesResponse struct { Time []int64 `json:"t" human:"Date"` Open []float64 `json:"o" human:"Open"` High []float64 `json:"h" human:"High"` Low []float64 `json:"l" human:"Low"` Close []float64 `json:"c" human:"Close"` }
IndicesCandlesResponse represents the response structure for indices candles data. It includes slices for time, open, high, low, and close values of the indices.
func (*IndicesCandlesResponse) IsValid ¶
func (icr *IndicesCandlesResponse) IsValid() bool
IsValid checks if the IndicesCandlesResponse passes all validation checks.
Returns:
- A boolean indicating if the response is valid.
func (*IndicesCandlesResponse) MarshalJSON ¶
func (icr *IndicesCandlesResponse) MarshalJSON() ([]byte, error)
MarshalJSON is a method on the IndicesCandlesResponse struct. It marshals the struct into a JSON object. The JSON object is an ordered map with keys "s", "t", "o", "h", "l", and "c". The "s" key is always set to "ok". The "t", "o", "h", "l", and "c" keys correspond to the Time, Open, High, Low, and Close slices in the struct.
Returns:
- A byte slice of the JSON object, error if marshaling fails.
func (*IndicesCandlesResponse) String ¶
func (icr *IndicesCandlesResponse) String() string
String returns a string representation of the IndicesCandlesResponse.
Returns:
- A formatted string containing the time, open, high, low, and close values.
func (*IndicesCandlesResponse) UnmarshalJSON ¶
func (icr *IndicesCandlesResponse) UnmarshalJSON(data []byte) error
UnmarshalJSON custom unmarshals a JSON object into the IndicesCandlesResponse.
Parameters:
- data: A byte slice of the JSON object to be unmarshaled.
Returns:
- An error if unmarshaling or validation fails.
func (*IndicesCandlesResponse) Unpack ¶
func (icr *IndicesCandlesResponse) Unpack() ([]IndexCandle, error)
Unpack converts the IndicesCandlesResponse into a slice of IndexCandle.
Returns:
- A slice of IndexCandle, error if there's an inconsistency in the data slices.
func (*IndicesCandlesResponse) Validate ¶
func (icr *IndicesCandlesResponse) Validate() error
Validate runs multiple checks on the IndicesCandlesResponse: time in ascending order, equal slice lengths, and no empty slices.
Returns:
- An error if any of the checks fail, nil otherwise.
type MarketStatusReport ¶ added in v0.0.5
MarketStatusReport represents the status of a market.
func (MarketStatusReport) String ¶ added in v0.0.5
func (ms MarketStatusReport) String() string
String returns a string representation of the MarketStatusReport.
Returns:
- string: A string representation of the MarketStatusReport.
type MarketStatusResponse ¶
type MarketStatusResponse struct { Date []int64 `json:"date"` // Date contains UNIX timestamps for each market status entry. Status *[]string `json:"status,omitempty"` // Status is a pointer to a slice of market status strings, which can be omitted if empty. }
MarketStatusResponse holds the response data for a market status request. It includes a slice of dates and an optional slice of corresponding market statuses.
func (*MarketStatusResponse) GetClosedDates ¶
func (msr *MarketStatusResponse) GetClosedDates() ([]time.Time, error)
GetClosedDates returns a slice of dates when the market was closed.
Returns:
- []time.Time: A slice of time.Time representing the dates when the market was closed.
- error: An error if there's an issue unpacking the MarketStatusResponse.
func (*MarketStatusResponse) GetDateRange ¶
func (msr *MarketStatusResponse) GetDateRange() (*dates.DateRange, error)
GetDateRange returns the date range of the MarketStatusResponse.
Returns:
- *dates.DateRange: A pointer to a DateRange object representing the earliest and latest dates in the MarketStatusResponse.
- error: An error if there's an issue finding the earliest or latest date.
func (*MarketStatusResponse) GetOpenDates ¶
func (msr *MarketStatusResponse) GetOpenDates() ([]time.Time, error)
GetOpenDates returns a slice of dates when the market was open.
Returns:
- []time.Time: A slice of time.Time representing the dates when the market was open.
- error: An error if there's an issue unpacking the MarketStatusResponse.
func (*MarketStatusResponse) IsValid ¶
func (msr *MarketStatusResponse) IsValid() bool
IsValid checks if the MarketStatusResponse contains at least one date.
Returns:
- bool: True if there is at least one date, false otherwise.
func (*MarketStatusResponse) String ¶
func (msr *MarketStatusResponse) String() string
String returns a string representation of the MarketStatusResponse, including dates and their corresponding statuses.
Returns:
- string: A string representation of the MarketStatusResponse.
func (*MarketStatusResponse) Unpack ¶
func (msr *MarketStatusResponse) Unpack() ([]MarketStatusReport, error)
Unpack unpacks the MarketStatusResponse into a slice of MarketStatusReport.
Returns:
- []MarketStatusReport: A slice of MarketStatusReport derived from the MarketStatusResponse.
- error: An error if the date and status slices are not of the same length or any other issue occurs.
type OptionLookupResponse ¶ added in v0.0.5
type OptionLookupResponse struct {
OptionSymbol string `json:"optionSymbol"` // OptionSymbol is the symbol of the option.
}
OptionLookupResponse represents the response structure for an option lookup request. It contains the symbol of the option being looked up.
func (*OptionLookupResponse) IsValid ¶ added in v0.0.5
func (olr *OptionLookupResponse) IsValid() bool
IsValid checks if the OptionLookupResponse is valid.
Returns:
- bool: True if the OptionLookupResponse has a non-empty OptionSymbol, otherwise false.
func (*OptionLookupResponse) String ¶ added in v0.0.5
func (olr *OptionLookupResponse) String() string
String returns a string representation of the OptionLookupResponse.
Returns:
- string: A string that represents the OptionLookupResponse, including the OptionSymbol.
func (*OptionLookupResponse) Unpack ¶ added in v0.0.5
func (olr *OptionLookupResponse) Unpack() (string, error)
Unpack validates the OptionLookupResponse and returns the OptionSymbol if valid.
Returns:
- string: The OptionSymbol of the OptionLookupResponse if it is valid.
- error: An error if the OptionLookupResponse is invalid.
type OptionQuote ¶ added in v0.0.5
type OptionQuote struct { OptionSymbol string // OptionSymbol is the symbol of the option. Underlying string // Underlying is the symbol of the underlying asset. Expiration time.Time // Expiration is the time when the option expires. Side string // Side indicates whether the option is a call or a put. Strike float64 // Strike is the strike price of the option. FirstTraded time.Time // FirstTraded is the time when the option was first traded. DTE int // DTE (Days to Expiration) is the number of days until the option expires. Ask float64 // Ask is the ask price of the option. AskSize int64 // AskSize is the size of the ask order. Bid float64 // Bid is the bid price of the option. BidSize int64 // BidSize is the size of the bid order. Mid float64 // Mid is the mid price calculated between the bid and ask prices. Last float64 // Last is the last traded price of the option. Volume int64 // Volume is the trading volume of the option. OpenInterest int64 // OpenInterest is the total number of outstanding contracts. UnderlyingPrice float64 // UnderlyingPrice is the price of the underlying asset. InTheMoney bool // InTheMoney indicates whether the option is in the money. Updated time.Time // Updated is the time when the option data was last updated. IV *float64 // IV (Implied Volatility) is the implied volatility of the option. Delta *float64 // Delta measures the rate of change of the option's price with respect to the underlying asset's price. Gamma *float64 // Gamma measures the rate of change in delta over the underlying asset's price movement. Theta *float64 // Theta represents the rate of decline in the option's value with time. Vega *float64 // Vega measures sensitivity to volatility. Rho *float64 // Rho measures sensitivity to the interest rate. IntrinsicValue float64 // IntrinsicValue is the value of the option if it were exercised now. ExtrinsicValue float64 // ExtrinsicValue is the value of the option above its intrinsic value. }
OptionQuote represents a single option quote with detailed information such as the symbol, underlying asset, expiration time, and pricing information.
func (OptionQuote) DisplayDelta ¶ added in v0.1.0
func (oq OptionQuote) DisplayDelta() string
func (OptionQuote) DisplayGamma ¶ added in v0.1.0
func (oq OptionQuote) DisplayGamma() string
func (OptionQuote) DisplayIV ¶ added in v0.1.0
func (oq OptionQuote) DisplayIV() string
func (OptionQuote) DisplayRho ¶ added in v0.1.0
func (oq OptionQuote) DisplayRho() string
func (OptionQuote) DisplayTheta ¶ added in v0.1.0
func (oq OptionQuote) DisplayTheta() string
func (OptionQuote) DisplayVega ¶ added in v0.1.0
func (oq OptionQuote) DisplayVega() string
func (OptionQuote) String ¶ added in v0.0.5
func (oq OptionQuote) String() string
String returns a formatted string representation of an OptionQuote.
Parameters:
- oq: The OptionQuote instance.
Returns:
- A string that represents the OptionQuote in a human-readable format.
type OptionQuotesResponse ¶ added in v0.0.5
type OptionQuotesResponse struct { OptionSymbol []string `json:"optionSymbol"` // OptionSymbol holds the symbols of the options. Underlying []string `json:"underlying"` // Underlying contains the symbols of the underlying assets. Expiration []int64 `json:"expiration"` // Expiration stores UNIX timestamps for when the options expire. Side []string `json:"side"` // Side indicates whether the option is a call or a put. Strike []float64 `json:"strike"` // Strike represents the strike prices of the options. FirstTraded []int64 `json:"firstTraded"` // FirstTraded stores UNIX timestamps for when the options were first traded. DTE []int `json:"dte"` // DTE (Days to Expiration) indicates the number of days until the options expire. Ask []float64 `json:"ask"` // Ask contains the ask prices of the options. AskSize []int64 `json:"askSize"` // AskSize holds the sizes of the ask orders. Bid []float64 `json:"bid"` // Bid contains the bid prices of the options. BidSize []int64 `json:"bidSize"` // BidSize holds the sizes of the bid orders. Mid []float64 `json:"mid"` // Mid represents the mid prices calculated between the bid and ask prices. Last []float64 `json:"last"` // Last contains the last traded prices of the options. Volume []int64 `json:"volume"` // Volume indicates the trading volumes of the options. OpenInterest []int64 `json:"openInterest"` // OpenInterest represents the total number of outstanding contracts. UnderlyingPrice []float64 `json:"underlyingPrice"` // UnderlyingPrice contains the prices of the underlying assets. InTheMoney []bool `json:"inTheMoney"` // InTheMoney indicates whether the options are in the money. Updated []int64 `json:"updated"` // Updated stores UNIX timestamps for when the option data was last updated. IV []*float64 `json:"iv,omitempty"` // IV (Implied Volatility) represents the implied volatilities of the options. Delta []*float64 `json:"delta,omitempty"` // Delta measures the rate of change of the option's price with respect to the underlying asset's price. Gamma []*float64 `json:"gamm,omitempty"` // Gamma measures the rate of change in delta over the underlying asset's price movement. Theta []*float64 `json:"theta,omitempty"` // Theta represents the rate of decline in the option's value with time. Vega []*float64 `json:"vega,omitempty"` // Vega measures sensitivity to volatility. Rho []*float64 `json:"rho,omitempty"` // Rho measures sensitivity to the interest rate. IntrinsicValue []float64 `json:"intrinsicValue"` // IntrinsicValue represents the value of the option if it were exercised now. ExtrinsicValue []float64 `json:"extrinsicValue"` // ExtrinsicValue represents the value of the option above its intrinsic value. }
OptionQuotesResponse represents the JSON structure of the response received for option quotes. It includes slices for various option attributes such as symbols, underlying assets, expiration times, and pricing information.
func (*OptionQuotesResponse) IsValid ¶ added in v0.1.0
func (oqr *OptionQuotesResponse) IsValid() bool
IsValid checks if an OptionQuotesResponse is valid by utilizing the Validate method.
Returns:
- A boolean indicating if the OptionQuotesResponse is valid.
func (*OptionQuotesResponse) String ¶ added in v0.0.5
func (oqr *OptionQuotesResponse) String() string
String returns a formatted string representation of all OptionQuotes contained in the OptionQuotesResponse.
Parameters:
- oqr: A pointer to the OptionQuotesResponse instance.
Returns:
- A string that represents all OptionQuotes in a human-readable format.
func (*OptionQuotesResponse) Unpack ¶ added in v0.0.5
func (oqr *OptionQuotesResponse) Unpack() ([]OptionQuote, error)
Unpack converts the OptionQuotesResponse into a slice of OptionQuote structs.
Parameters:
- oqr: A pointer to the OptionQuotesResponse instance to be unpacked.
Returns:
- A slice of OptionQuote structs that represent the unpacked data.
- An error if the time zone loading fails or if the validation fails.
func (*OptionQuotesResponse) Validate ¶ added in v0.1.0
func (oqr *OptionQuotesResponse) Validate() error
Validate checks the consistency of the OptionQuotesResponse struct.
Returns:
- An error if there is an inconsistency in the lengths of slices or if there are no option symbols.
type OptionsExpirationsResponse ¶
type OptionsExpirationsResponse struct { Expirations []string // Expirations is a slice of strings representing the expiration dates of options. Updated int64 // Updated is a UNIX timestamp indicating when the data was last updated. }
OptionsExpirationsResponse represents the response structure for options expirations. It includes a slice of expiration dates as strings and a timestamp for when the data was last updated.
func (*OptionsExpirationsResponse) IsValid ¶
func (oer *OptionsExpirationsResponse) IsValid() bool
IsValid checks the validity of the options expirations response.
It verifies that the Expirations slice is not empty and that each expiration date string can be parsed into a time.Time object. This parsing is done according to the "America/New_York" timezone.
Returns:
- A boolean indicating whether the OptionsExpirationsResponse is valid.
func (*OptionsExpirationsResponse) String ¶
func (oer *OptionsExpirationsResponse) String() string
String provides a string representation of the OptionsExpirationsResponse.
It formats the expirations and the updated timestamp into a readable string.
Returns:
- A string that represents the OptionsExpirationsResponse object.
func (*OptionsExpirationsResponse) Unpack ¶
func (oer *OptionsExpirationsResponse) Unpack() ([]time.Time, error)
Unpack converts the expiration date strings in the OptionsExpirationsResponse to a slice of time.Time objects.
It parses each date string in the Expirations slice into a time.Time object, adjusting the time to 4:00 PM Eastern Time, which is the typical expiration time for options contracts.
Returns:
- A slice of time.Time objects representing the expiration dates and times.
- An error if any date string cannot be parsed or if the "America/New_York" timezone cannot be loaded.
type OptionsStrikes ¶ added in v0.0.5
type OptionsStrikes struct { Expiration time.Time // Expiration is the date and time when the option expires. Strikes []float64 // Strikes is a slice of strike prices available for the option. }
OptionsStrikes represents the expiration date and strike prices for an option.
func (OptionsStrikes) String ¶ added in v0.0.5
func (os OptionsStrikes) String() string
String returns a string representation of the OptionsStrikes struct.
Returns:
- string: The string representation of the OptionsStrikes.
type OptionsStrikesResponse ¶ added in v0.0.5
type OptionsStrikesResponse struct { Updated int `json:"updated"` // Updated is a UNIX timestamp indicating when the data was last updated. Strikes *orderedmap.OrderedMap `json:"-"` // Strikes is a map where each key is a date string and the value is a slice of strike prices for that date. }
OptionsStrikesResponse encapsulates the response structure for a request to retrieve option strikes.
func (*OptionsStrikesResponse) IsValid ¶ added in v0.0.5
func (osr *OptionsStrikesResponse) IsValid() bool
IsValid checks if the OptionsStrikesResponse is valid by leveraging the Validate method.
Returns:
- bool: True if the response is valid, false otherwise.
func (*OptionsStrikesResponse) String ¶ added in v0.0.5
func (osr *OptionsStrikesResponse) String() string
String returns a string representation of the OptionsStrikesResponse struct.
Returns:
- string: The string representation of the OptionsStrikesResponse.
func (*OptionsStrikesResponse) UnmarshalJSON ¶ added in v0.0.5
func (osr *OptionsStrikesResponse) UnmarshalJSON(data []byte) error
UnmarshalJSON custom unmarshals the JSON data into the OptionsStrikesResponse struct.
Parameters:
- data []byte: The JSON data to be unmarshaled.
Returns:
- error: An error if unmarshaling fails, nil otherwise.
UnmarshalJSON custom unmarshals the JSON data into the OptionsStrikesResponse struct.
func (*OptionsStrikesResponse) Unpack ¶ added in v0.0.5
func (osr *OptionsStrikesResponse) Unpack() ([]OptionsStrikes, error)
Unpack converts the ordered map of strikes in the response to a slice of OptionsStrikes.
func (*OptionsStrikesResponse) Validate ¶ added in v0.1.0
func (osr *OptionsStrikesResponse) Validate() error
Validate checks if the OptionsStrikesResponse is valid.
Returns:
- error: An error if the response is not valid, nil otherwise.
type StockCandle ¶
type StockCandle struct { Time time.Time // Time represents the date and time of the candle. Open float64 // Open is the opening price of the candle. High float64 // High is the highest price reached during the candle's time. Low float64 // Low is the lowest price reached during the candle's time. Close float64 // Close is the closing price of the candle. Volume int64 // Volume represents the trading volume during the candle's time. VWAP float64 // VWAP is the Volume Weighted Average Price, optional. N int64 // N is the number of trades that occurred, optional. }
StockCandle represents a single candle in a stock candlestick chart. It includes the time, open, high, low, close prices, volume, and optionally VWAP and number of trades.
func (StockCandle) String ¶
func (sc StockCandle) String() string
String returns a string representation of a StockCandle.
Returns:
- A string representation of the StockCandle.
type StockCandlesResponse ¶
type StockCandlesResponse struct { Time []int64 `json:"t" human:"Date"` // Time holds UNIX timestamps for each candle. Open []float64 `json:"o" human:"Open"` // Open holds the opening prices for each candle. High []float64 `json:"h" human:"High"` // High holds the highest prices reached in each candle. Low []float64 `json:"l" human:"Low"` // Low holds the lowest prices reached in each candle. Close []float64 `json:"c" human:"Close"` // Close holds the closing prices for each candle. Volume []int64 `json:"v" human:"Volume"` // Volume represents the trading volume in each candle. VWAP *[]float64 `json:"vwap,omitempty" human:"VWAP,omitempty"` // VWAP holds the Volume Weighted Average Price for each candle, optional. N *[]int64 `json:"n,omitempty" human:"No. of Trades,omitempty"` // N holds the number of trades for each candle, optional. }
StockCandlesResponse represents the JSON response structure for stock candles data. It includes slices for time, open, high, low, close prices, and volume for each candle. Optional fields VWAP and N are available for V2 candles.
func CombineStockCandles ¶
func CombineStockCandles(s1, s2 *StockCandlesResponse) (*StockCandlesResponse, error)
CombineStockCandles merges two StockCandlesResponse structs into a single one. It checks if the versions of the two structs are the same, ensures there is no time overlap between them, and then combines their data into a new StockCandlesResponse struct. If the versions are both V2, it also combines the VWAP and N slices. Finally, it validates the combined struct.
Parameters:
- s1 *StockCandlesResponse: The first StockCandlesResponse struct to be combined.
- s2 *StockCandlesResponse: The second StockCandlesResponse struct to be combined.
Returns:
- *StockCandlesResponse: A pointer to the newly combined StockCandlesResponse struct.
- error: An error if the versions do not match, there is a time overlap, or the combined struct fails validation.
func (*StockCandlesResponse) GetDateRange ¶
func (s *StockCandlesResponse) GetDateRange() (dates.DateRange, error)
GetDateRange returns the date range of a StockCandlesResponse.
Returns:
- A DateRange object.
- An error if calculating the date range fails.
func (*StockCandlesResponse) IsValid ¶
func (s *StockCandlesResponse) IsValid() bool
IsValid checks if a StockCandlesResponse is valid.
Returns:
- A boolean indicating if the StockCandlesResponse is valid.
func (*StockCandlesResponse) MarshalJSON ¶
func (s *StockCandlesResponse) MarshalJSON() ([]byte, error)
MarshalJSON marshals a StockCandlesResponse into JSON.
Returns:
- A byte slice of the JSON representation.
- An error if marshaling fails.
func (*StockCandlesResponse) PruneOutsideDateRange ¶
func (s *StockCandlesResponse) PruneOutsideDateRange(dr dates.DateRange) error
PruneOutsideDateRange removes data points outside a specified date range from a StockCandlesResponse.
Parameters:
- dr: A DateRange struct specifying the start and end dates for the range within which data points should be retained.
Returns:
- An error if pruning fails.
func (*StockCandlesResponse) String ¶
func (s *StockCandlesResponse) String() string
String returns a string representation of a StockCandlesResponse.
Returns:
- A string representation of the StockCandlesResponse.
func (*StockCandlesResponse) UnmarshalJSON ¶
func (s *StockCandlesResponse) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals JSON into a StockCandlesResponse.
Returns:
- An error if unmarshaling or validation fails.
func (*StockCandlesResponse) Unpack ¶
func (scr *StockCandlesResponse) Unpack() ([]StockCandle, error)
Unpack converts a StockCandlesResponse into a slice of StockCandle.
Returns:
- A slice of StockCandle.
- An error if the slices within StockCandlesResponse are not of equal length.
func (*StockCandlesResponse) Validate ¶
func (s *StockCandlesResponse) Validate() error
Validate validates a StockCandlesResponse.
Returns:
- An error if the StockCandlesResponse is not valid.
type StockEarningsReport ¶
type StockEarningsReport struct { Symbol string // Symbol represents the stock symbol. FiscalYear *int64 // FiscalYear represents the fiscal year of the earnings report. FiscalQuarter *int64 // FiscalQuarter represents the fiscal quarter of the earnings report. Date time.Time // Date represents the earnings announcement date. ReportDate time.Time // ReportDate represents the report release date. ReportTime string // ReportTime represents the time of day the earnings were reported. Currency string // Currency represents the currency used in the earnings report. ReportedEPS *float64 // ReportedEPS represents the actual earnings per share reported. EstimatedEPS *float64 // EstimatedEPS represents the consensus earnings per share estimate. SurpriseEPS *float64 // SurpriseEPS represents the difference between reported EPS and estimated EPS. SurpriseEPSpct *float64 // SurpriseEPSpct represents the percentage difference between reported and estimated EPS. Updated time.Time // Updated represents the last update time. }
StockEarningsReport represents a single earnings report for a stock. It includes the stock symbol, fiscal year, fiscal quarter, date of the earnings, report date, report time, currency of the report, reported EPS, estimated EPS, surprise EPS, surprise EPS percentage, and the last updated time.
func (StockEarningsReport) String ¶
func (ser StockEarningsReport) String() string
type StockEarningsResponse ¶
type StockEarningsResponse struct { Symbol []string `json:"symbol"` // Symbol represents the stock symbols. FiscalYear []*int64 `json:"fiscalYear"` // FiscalYear represents the fiscal years of the earnings report. FiscalQuarter []*int64 `json:"fiscalQuarter"` // FiscalQuarter represents the fiscal quarters of the earnings report. Date []int64 `json:"date"` // Date represents the earnings announcement dates in UNIX timestamp. ReportDate []int64 `json:"reportDate"` // ReportDate represents the report release dates in UNIX timestamp. ReportTime []string `json:"reportTime"` // ReportTime represents the time of day the earnings were reported. Currency []string `json:"currency"` // Currency represents the currency used in the earnings report. ReportedEPS []*float64 `json:"reportedEPS"` // ReportedEPS represents the actual earnings per share reported. EstimatedEPS []*float64 `json:"estimatedEPS"` // EstimatedEPS represents the consensus earnings per share estimate. SurpriseEPS []*float64 `json:"surpriseEPS"` // SurpriseEPS represents the difference between reported EPS and estimated EPS. SurpriseEPSpct []*float64 `json:"surpriseEPSpct"` // SurpriseEPSpct represents the percentage difference between reported and estimated EPS. Updated []int64 `json:"updated"` // Updated represents the last update time in UNIX timestamp. }
StockEarningsResponse represents the response structure for stock earnings data. It includes slices for symbols, fiscal years, fiscal quarters, dates (UNIX timestamp), report dates (UNIX timestamp), report times, currencies, reported EPS (Earnings Per Share), estimated EPS, surprise EPS, surprise EPS percentage, and last updated time (UNIX timestamp).
func (*StockEarningsResponse) String ¶
func (ser *StockEarningsResponse) String() string
String generates a string representation of the StockEarningsResponse.
This method formats the StockEarningsResponse fields into a readable string, including handling nil values for EPS fields and empty values for fiscalYear and fiscalQuarter gracefully by displaying them as "nil" or "empty" respectively.
Returns:
- A string representation of the StockEarningsResponse.
func (*StockEarningsResponse) Unpack ¶
func (ser *StockEarningsResponse) Unpack() ([]StockEarningsReport, error)
Unpack converts the StockEarningsResponse struct into a slice of StockEarningsReport structs.
This method iterates over the fields of a StockEarningsResponse struct, creating a StockEarningsReport struct for each symbol present in the response. It then populates the fields of each StockEarningsReport struct with the corresponding data from the StockEarningsResponse struct. The method handles the conversion of Unix timestamps to time.Time objects for the Date, ReportDate, and Updated fields. It also directly assigns pointer fields for ReportedEPS, EstimatedEPS, SurpriseEPS, and SurpriseEPSpct to handle potential nil values gracefully.
Returns:
- []StockEarningsReport: A slice of StockEarningsReport structs constructed from the StockEarningsResponse.
- error: An error if the unpacking process fails, nil otherwise.
type StockNews ¶ added in v0.0.5
type StockNews struct { Symbol string // Symbol is the stock symbol associated with the news article. Headline string // Headline is the headline of the news article. Content string // Content is the full text content of the news article. Source string // Source is the source from which the news article was obtained. PublicationDate time.Time // PublicationDate is the publication date of the news article. }
StockNews represents a single news article related to a stock. It includes the stock symbol, headline, content, source, and publication date.
type StockNewsResponse ¶ added in v0.0.5
type StockNewsResponse struct { Symbol []string `json:"symbol"` // Symbol contains the stock symbols associated with the news. Headline []string `json:"headline"` // Headline contains the headlines of the news articles. Content []string `json:"content"` // Content contains the full text content of the news articles. Source []string `json:"source"` // Source contains the sources from which the news articles were obtained. PublicationDate []int64 `json:"publicationDate"` // PublicationDate contains the publication dates of the news articles as UNIX timestamps. Updated int64 `json:"updated"` // Updated contains the timestamp of the last update to the news data. }
StockNewsResponse represents the JSON response structure for stock news. It includes slices for symbols, headlines, content, sources, and publication dates, as well as a timestamp for when the data was last updated.
func (*StockNewsResponse) String ¶ added in v0.0.5
func (snr *StockNewsResponse) String() string
String generates a string representation of the StockNewsResponse struct.
This method iterates over each news article in the StockNewsResponse, appending a formatted string for each article to a strings.Builder. If the 'Updated' field is non-zero, it appends an "Updated" field at the end of the string.
Returns:
- A string representation of the StockNewsResponse struct.
func (*StockNewsResponse) Unpack ¶ added in v0.0.5
func (snr *StockNewsResponse) Unpack() ([]StockNews, error)
Unpack transforms the StockNewsResponse struct into a slice of StockNews structs.
Returns:
- A slice of StockNews structs representing the unpacked news articles.
- An error if any issues occur during the unpacking process. This implementation always returns nil for error.
type StockQuote ¶
type StockQuote struct { Symbol string // Symbol is the stock symbol. Ask float64 // Ask is the asking price for the stock. AskSize int64 // AskSize is the size (quantity) of the ask. Bid float64 // Bid is the bidding price for the stock. BidSize int64 // BidSize is the size (quantity) of the bid. Mid float64 // Mid is the mid price calculated between the ask and bid prices. Last float64 // Last is the last traded price for the stock. Change *float64 // Change is the price change, can be nil if not applicable. ChangePct *float64 // ChangePct is the percentage change in price, can be nil if not applicable. High52 *float64 // High52 is the 52-week high price, can be nil if not applicable. Low52 *float64 // Low52 is the 52-week low price, can be nil if not applicable. Volume int64 // Volume is the trading volume for the stock. Updated time.Time // Updated is the time when the quote was last updated. }
StockQuote represents a single stock quote. It includes the stock symbol, ask price, ask size, bid price, bid size, mid price, last trade price, change, change percentage, 52-week high, 52-week low, volume, and the time of the last update.
func (StockQuote) String ¶
func (sq StockQuote) String() string
String generates a string representation of the StockQuote struct.
This method formats the fields of a StockQuote into a readable string. It includes conditional formatting based on the presence of optional fields such as High52, Low52, Change, and ChangePct. The updated time is formatted in the America/New_York timezone.
Returns:
- A string representation of the StockQuote struct.
type StockQuotesResponse ¶
type StockQuotesResponse struct { Symbol []string `json:"symbol"` // Symbol holds the stock symbols. Ask []float64 `json:"ask"` // Ask holds the asking prices for the stocks. AskSize []int64 `json:"askSize"` // AskSize holds the sizes (quantities) of the asks. Bid []float64 `json:"bid"` // Bid holds the bidding prices for the stocks. BidSize []int64 `json:"bidSize"` // BidSize holds the sizes (quantities) of the bids. Mid []float64 `json:"mid"` // Mid holds the mid prices calculated between the ask and bid prices. Last []float64 `json:"last"` // Last holds the last traded prices for the stocks. Change []*float64 `json:"change,omitempty"` // Change holds the price changes, can be nil if not applicable. ChangePct []*float64 `json:"changepct,omitempty"` // ChangePct holds the percentage changes in prices, can be nil if not applicable. High52 *[]float64 `json:"52weekHigh,omitempty"` // High52 holds the 52-week high prices, can be nil if not applicable. Low52 *[]float64 `json:"52weekLow,omitempty"` // Low52 holds the 52-week low prices, can be nil if not applicable. Volume []int64 `json:"volume"` // Volume holds the trading volumes for the stocks. Updated []int64 `json:"updated"` // Updated holds the UNIX timestamps for when the quotes were last updated. }
StockQuotesResponse represents the response structure for stock quotes. It includes slices for symbols, ask prices, ask sizes, bid prices, bid sizes, mid prices, last trade prices, changes, change percentages, 52-week highs, 52-week lows, volumes, and update timestamps.
func (*StockQuotesResponse) String ¶
func (sqr *StockQuotesResponse) String() string
String returns a string representation of a StockQuotesResponse.
This method constructs a string that includes the symbol, ask, ask size, bid, bid size, mid, last, change (if available), change percentage (if available), 52-week high (if available), 52-week low (if available), volume, and updated time of the stock quotes response.
Returns:
- A string that represents the stock quotes response.
func (*StockQuotesResponse) Unpack ¶
func (sqr *StockQuotesResponse) Unpack() ([]StockQuote, error)
Unpack transforms the StockQuotesResponse into a slice of StockQuote structs.
This method iterates over the fields of a StockQuotesResponse and constructs a slice of StockQuote structs by assigning the corresponding values from the response to each StockQuote. It handles optional fields such as Change, ChangePct, High52, and Low52 by checking for their existence before assignment.
Returns:
- A slice of StockQuote structs representing the unpacked stock quotes.
- An error if any issues occur during the unpacking process (currently, this implementation always returns nil for error).
type Ticker ¶ added in v0.0.5
type Ticker struct { Symbol string Name string Type string Currency string Exchange string FigiComposite string Cik string Updated *time.Time }
Ticker represents the information of a ticker.
type TickersResponse ¶
type TickersResponse struct { Symbol []string `json:"symbol"` // Symbol contains the stock symbols. Name []string `json:"name,omitempty"` // Name contains the names of the stocks. Optional. Type []string `json:"type,omitempty"` // Type contains the types of the stocks. Optional. Currency []string `json:"currency,omitempty"` // Currency contains the currencies in which the stocks are traded. Optional. Exchange []string `json:"exchange,omitempty"` // Exchange contains the stock exchanges on which the stocks are listed. Optional. FigiComposite []string `json:"figiComposite,omitempty"` // FigiComposite contains the composite FIGI codes. Optional. Cik []string `json:"cik,omitempty"` // Cik contains the Central Index Key (CIK) numbers. Optional. Updated *[]int64 `json:"updated,omitempty"` // Updated contains UNIX timestamps of the last updates. Optional. }
TickersResponse represents the response structure for the /stocks/tickers API endpoint. It includes slices for various stock attributes such as symbol, name, type, currency, and exchange. Optional fields are marked with 'omitempty' to exclude them from the JSON output if they are empty.
func MapToTickersResponse ¶
func MapToTickersResponse(tickerMap map[string]Ticker) *TickersResponse
MapToTickersResponse converts a map of Ticker structs into a TickersResponse struct.
Parameters:
- tickerMap: A map where the key is a string representing the ticker symbol, and the value is a Ticker struct.
Returns:
- A pointer to a TickersResponse struct that aggregates the information from the input map.
func (*TickersResponse) IsValid ¶
func (tr *TickersResponse) IsValid() bool
IsValid determines if the TickersResponse has at least one symbol.
Returns:
- true if there is at least one symbol; otherwise, false.
func (*TickersResponse) MarshalJSON ¶
func (tr *TickersResponse) MarshalJSON() ([]byte, error)
MarshalJSON customizes the JSON encoding for the TickersResponse struct.
Returns:
- []byte: The JSON-encoded representation of the TickersResponse.
- error: An error if the encoding fails.
func (*TickersResponse) String ¶
func (tr *TickersResponse) String() string
String constructs a string representation of the TickersResponse. It iterates through each symbol and its associated data, formatting them into a readable string. If the 'Updated' field is not nil and contains data, it includes the update time for each symbol.
Returns:
- A string detailing the contents of the TickersResponse, including symbols, names, types, currencies, exchanges, FIGI codes, CIK numbers, and update times.
func (*TickersResponse) ToMap ¶
func (tr *TickersResponse) ToMap() (map[string]Ticker, error)
ToMap converts a TickersResponse into a map where each key is a stock symbol and its value is the corresponding Ticker struct.
Returns:
- map[string]Ticker: A map with stock symbols as keys and Ticker structs as values.
- error: An error if the conversion fails.
func (*TickersResponse) UniqueSymbols ¶
func (tr *TickersResponse) UniqueSymbols() ([]string, error)
UniqueSymbols extracts and returns a slice of unique stock symbols from the TickersResponse.
Returns:
- []string: A slice of unique stock symbols.
- error: An error encountered during the conversion to a map, if any.
func (*TickersResponse) Unpack ¶
func (tr *TickersResponse) Unpack() ([]Ticker, error)
Unpack converts a TickersResponse instance into a slice of Ticker structs.
This method iterates through the fields of the TickersResponse struct, creating a Ticker struct for each symbol present in the response. It ensures that all corresponding fields are populated correctly. If the 'Updated' field is not nil, it converts the UNIX timestamp to a time.Time object for each Ticker struct.
Returns:
- A slice of Ticker structs representing the unpacked tickers.
- An error if the TickersResponse is nil, its 'Updated' field is nil, or if there is a mismatch in the lengths of the slices within the TickersResponse.