Skip to main content

Quotes

Retrieve real-time quotes for any supported index.

Making Requests

Utilize IndexQuoteRequest to make requests to the endpoint through one of the three supported execution methods:

MethodExecutionReturn TypeDescription
GetDirect[]IndexQuoteDirectly returns a slice of []IndexQuote, facilitating individual access to each quote.
PackedIntermediate*IndexQuotesResponseReturns a packed *IndexQuotesResponse object. Must be unpacked to access the []IndexQuote slice.
RawLow-level*resty.ResponseOffers the raw *resty.Response for utmost flexibility. Direct access to raw JSON or *http.Response.

IndexQuoteRequest

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

IndexQuoteRequest represents a request to the /v1/indices/quotes/ endpoint. It encapsulates parameters for symbol and fifty-two-week data to be used in the request. This struct provides methods such as Symbol() and FiftyTwoWeek() to set these parameters respectively.

Generated By

  • IndexQuotes()

    IndexQuotes creates a new *IndexQuoteRequest and returns a pointer to the request allowing for method chaining.

Setter Methods

These methods are used to set the parameters of the request. They allow for method chaining by returning a pointer to the *IndexQuoteRequest instance they modify.

Execution Methods

These methods are used to send the request in different formats or retrieve the data. They handle the actual communication with the API endpoint.

IndexQuotes

func IndexQuotes() *IndexQuoteRequest

IndexQuotes creates a new IndexQuoteRequest and associates it with the default client. This function initializes the request with default parameters for symbol and fifty-two-week data, and sets the request path based on the predefined endpoints for index quotes.

Returns

  • *IndexQuoteRequest

    A pointer to the newly created IndexQuoteRequest with default parameters and associated with the default client.

IndexQuoteRequest Setter Methods

FiftyTwoWeek

func (iqr *IndexQuoteRequest) FiftyTwoWeek(q bool) *IndexQuoteRequest

FiftyTwoWeek sets the FiftyTwoWeek parameter for the IndexQuoteRequest. This method is used to specify whether to include fifty-two-week high and low data in the quote. It modifies the fiftyTwoWeekParams field of the IndexQuoteRequest instance to store the boolean value.

Parameters

  • bool

    A boolean indicating whether to include fifty-two-week data.

Returns

  • *IndexQuoteRequest

    This method returns a pointer to the IndexQuoteRequest instance it was called on. This allows for method chaining. If the receiver (*IndexQuoteRequest) is nil, it returns nil to prevent a panic.

Symbol

func (iqr *IndexQuoteRequest) Symbol(q string) *IndexQuoteRequest

Symbol sets the symbol parameter for the IndexQuoteRequest. This method is used to specify the market symbol for which the quote data is requested. It modifies the symbolParams field of the IndexQuoteRequest instance to store the symbol value.

Parameters

  • string

    A string representing the market symbol to be set.

Returns

  • *IndexQuoteRequest

    This method returns a pointer to the IndexQuoteRequest instance it was called on. This allows for method chaining, where multiple setter methods can be called in a single statement. If the receiver (*IndexQuoteRequest) is nil, it returns nil to prevent a panic.

Note:

  • If an error occurs while setting the symbol (e.g., if the symbol value is not supported), the Error field of the IndexQuoteRequest is set with the encountered error, but the method still returns the IndexQuoteRequest instance to allow for further method calls or error handling by the caller.

IndexQuoteRequest Execution Methods

Get

func (iqr *IndexQuoteRequest) Get() ([]models.IndexQuote, error)

Get sends the IndexQuoteRequest, unpacks the IndexQuotesResponse, and returns a slice of IndexQuote. It returns an error if the request or unpacking fails. This method is crucial for obtaining the actual quote data from the index quote request. The method first checks if the IndexQuoteRequest receiver is nil, which would result in an error as the request cannot be sent. It then proceeds to send the request using the default client with the Packed method. Upon receiving the response, it unpacks the data into a slice of IndexQuote using the Unpack method from the response.

Returns

  • []models.IndexQuote

    A slice of IndexQuote containing the unpacked quote data from the response.

  • error

    An error object that indicates a failure in sending the request or unpacking the response.

Packed

func (iqr *IndexQuoteRequest) Packed() (*models.IndexQuotesResponse, error)

Packed sends the IndexQuoteRequest and returns the IndexQuotesResponse. This method checks if the IndexQuoteRequest receiver is nil, returning an error if true. It proceeds to send the request using the default client and returns the IndexQuotesResponse along with any error encountered during the request.

Returns

  • *models.IndexQuotesResponse

    A pointer to the IndexQuotesResponse obtained from the request.

  • error

    An error object that indicates a failure in sending the request.

Raw

func (iqr *IndexQuoteRequest) Raw() (*resty.Response, error)

Raw executes the IndexQuoteRequest and returns the raw *resty.Response. The *resty.Response can be directly used to access the raw JSON or *http.Response for further processing.

Returns

  • *resty.Response

    The raw HTTP response from the executed IndexQuoteRequest.

  • error

    An error object if the IndexQuoteRequest is nil or if an error occurs during the request execution.

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 encapsulates the data for index quotes, including symbols, last prices, price changes, percentage changes, 52-week highs and lows, and update timestamps.

Generated By

Methods

Notes

  • The Change and ChangePct fields are pointers to accommodate nil values, indicating that the change information is not applicable or unavailable.
  • The High52 and Low52 fields are pointers to slices, allowing for the entire field to be nil if 52-week high/low data is not applicable or unavailable.

String

func (iqr *IndexQuotesResponse) String() string

String provides a formatted string representation of the IndexQuotesResponse instance. This method is primarily used for logging or debugging purposes, allowing the user to easily view the contents of an IndexQuotesResponse object in a human-readable format. It concatenates various fields of the IndexQuotesResponse into a single string, making it easier to understand the response at a glance.

Returns

  • string

    A formatted string containing the contents of the IndexQuotesResponse.

Unpack

func (iqr *IndexQuotesResponse) Unpack() ([]IndexQuote, error)

Unpack transforms the IndexQuotesResponse into a slice of IndexQuote. This method is primarily used for converting a bulk response of index quotes into individual index quote objects, making them easier to work with in a program. It is useful when you need to process or display index quotes individually after fetching them in bulk.

Returns

  • []IndexQuote

    A slice of IndexQuote derived from the IndexQuotesResponse, allowing for individual access and manipulation of index quotes.

  • error

    An error if any issues occur during the unpacking process, enabling error handling in the calling function.

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, encapsulating details such as the symbol, last traded price, price changes, 52-week high and low prices, volume, and the timestamp of the last update.

Generated By

Methods

Notes

  • The Change and ChangePct fields are pointers to accommodate nil values, indicating that the change information is not applicable or unavailable.
  • The High52 and Low52 fields are also pointers, allowing these fields to be nil if 52-week high/low data is not applicable or unavailable.

String

func (iq IndexQuote) String() string

String generates a string representation of the IndexQuote for easy human-readable display. It is useful for logging, debugging, or displaying the IndexQuote details, including symbol, last traded price, volume, update timestamp, and optionally, 52-week highs, lows, and price changes if available.

Returns

  • string

    A formatted string encapsulating the IndexQuote details. It includes the symbol, last price, volume, update timestamp, and, if not nil, 52-week highs, lows, change, and percentage change.