Skip to main content

Bulk Quotes

Retrieve live quotes for multiple stocks symbols in a single request or even get a full market snapshot with a quote for all symbols.

Making Requests

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

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

BulkStockQuotesRequest

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

BulkStockQuotesRequest represents a request to the v1/stocks/bulkquotes/ 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

Setter Methods

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.

// This example demonstrates how to create a BulkStockQuotesRequest, set its parameters,
// and perform an actual request to fetch stock quotes for multiple symbols.

// Initialize a new BulkStockQuotesRequest and fetch stock quotes for "AAPL", "META", and "MSFT".
symbols := []string{"AAPL", "META", "MSFT"}
bsqr, err := BulkStockQuotes().Symbols(symbols).Get()
if err != nil {
log.Fatalf("Failed to get bulk stock quotes: %v", err)
}

// Check if the response contains the symbols.
for _, quote := range bsqr {
fmt.Printf("Symbol: %s\n", quote.Symbol)
}

Output

Symbol: AAPL
Symbol: META
Symbol: MSFT

BulkStockQuotes

func BulkStockQuotes() *BulkStockQuotesRequest

BulkStockQuotes creates a new BulkStockQuotesRequest 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 stock quotes.

Returns

  • *BulkStockQuotesRequest

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

BulkStockQuotesRequest Setter Methods

Snapshot

func (bs *BulkStockQuotesRequest) Snapshot(q bool) *BulkStockQuotesRequest

Snapshot sets the snapshot parameter for the BulkStockQuotesRequest. This method is used to enable or disable the snapshot feature in the request and will result in all available tickers being returned in the response.

Parameters

  • bool

    A boolean value representing whether to enable or disable the snapshot feature.

Returns

  • *BulkStockQuotesRequest

    This method returns a pointer to the *BulkStockQuotesRequest instance it was called on. This allows for method chaining.

Symbols

func (bs *BulkStockQuotesRequest) Symbols(q []string) *BulkStockQuotesRequest

Symbols sets the symbols parameter for the BulkStockQuotesRequest. This method is used to specify multiple stock symbols for which candle data is requested.

Parameters

  • []string

    A slice of []string representing the stock symbols to be set.

Returns

  • *BulkStockQuotesRequest

    This method returns a pointer to the BulkStockQuotesRequest instance it was called on. This allows for method chaining.

BulkStockQuotesRequest Execution Methods

Get

func (bs *BulkStockQuotesRequest) Get() ([]models.StockQuote, error)

Get sends the BulkStockQuotesRequest, unpacks the StockQuotesResponse, and returns a slice of StockQuote. It returns an error if the request or unpacking fails.

Returns

  • []models.StockQuote

    A slice of StockQuote 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 (bs *BulkStockQuotesRequest) Packed() (*models.StockQuotesResponse, error)

Packed sends the BulkStockQuotesRequest and returns the StockQuotesResponse.

Returns

  • *models.StockQuotesResponse

    A pointer to the StockQuotesResponse obtained from the request.

  • error

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

Raw

func (bsqr *BulkStockQuotesRequest) Raw() (*resty.Response, error)

Raw executes the request for BulkStockQuotesRequest and returns the raw *resty.Response. This method does not allow for an optional MarketDataClient to be passed.

Returns

  • *resty.Response

    The raw response from the executed BulkStockQuotesRequest.

  • error

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

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 encapsulates the data structure for responses received from stock quote requests. It contains arrays for various stock attributes such as symbols, prices, volumes, and timestamps.

Generated By

Methods

  • String()

    Returns a string representation of the StockQuotesResponse.

  • Unpack()

    Transforms the StockQuotesResponse into a slice of StockQuote structs.

Notes

  • The Change, ChangePct, High52, and Low52 fields are pointers to accommodate nil values, indicating that the data may not be applicable or available for some stocks.

String

func (sqr *StockQuotesResponse) String() string

String constructs and returns a string representation of a StockQuotesResponse, encapsulating all relevant details of stock quotes including symbol, ask, bid, mid, last, change, change percentage, 52-week high, 52-week low, volume, and updated time. This method is primarily used for generating a human-readable summary of stock quotes response, which can be useful for logging, debugging, or displaying stock information in a textual format.

Returns

  • string

    A comprehensive, human-readable string representation of the stock quotes response.

Notes

  • Optional fields such as change, change percentage, 52-week high, and 52-week low are included in the string only if they are available.

Unpack

func (sqr *StockQuotesResponse) Unpack() ([]StockQuote, error)

Unpack transforms a StockQuotesResponse into a slice of StockQuote structs, effectively unpacking the bulk response into individual stock quotes. This method is primarily used to convert a grouped response of stock quotes into a more accessible format, where each stock quote is represented as a separate struct. It is particularly useful for scenarios where individual stock details need to be accessed or manipulated.

Returns

  • []StockQuote

    A slice of StockQuote structs representing the unpacked stock quotes.

  • error

    An error if any issues occur during the unpacking process. Currently, this implementation always returns nil for error.

Notes

  • This method handles optional fields such as Change, ChangePct, High52, and Low52 by checking for their existence before assignment, allowing for a flexible unpacking process that accommodates incomplete data.

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, encapsulating various details such as prices, volumes, and timestamps.

Generated By

Methods

  • String()

    Generates a string representation of the StockQuote struct.

Notes

  • The Change, ChangePct, High52, and Low52 fields are pointers to accommodate nil values, indicating that the data may not be applicable or available.

String

func (sq StockQuote) String() string

String generates a string representation of the StockQuote struct, providing a human-readable summary of a stock's details. This method is particularly useful for displaying stock information in a format that is easy to read and understand. It accounts for optional fields by conditionally including High52, Low52, Change, and ChangePct in the output, and formats the updated time to the America/New_York timezone.

Returns

  • string

    A string representation of the StockQuote struct.

Notes

  • Optional fields (High52, Low52, Change, and ChangePct) are displayed as "nil" if they are not available, ensuring clarity in the output.
  • The updated time is converted to the America/New_York timezone for consistency in display.