py_alpaca_api.stock.logos

Company logos functionality for Alpaca Market Data API.

Exceptions

ValidationError

Raised when input validation fails.

Classes

Requests

Logos

Handles company logo retrieval from Alpaca API.

Module Contents

exception py_alpaca_api.stock.logos.ValidationError[source]

Bases: PyAlpacaAPIError

Raised when input validation fails.

class py_alpaca_api.stock.logos.Requests[source]
request(method: str, url: str, headers: dict[str, str] | None = None, params: dict[str, str | bool | float | int] | None = None, json: dict[str, Any] | None = None, raw_response: bool = False)[source]

Execute HTTP request with retry logic.

Parameters:
  • method – A string representing the HTTP method to be used in the request.

  • url – A string representing the URL to send the request to.

  • headers – An optional dictionary containing the headers for the request.

  • params – An optional dictionary containing the query parameters for the request.

  • json – An optional dictionary containing the JSON payload for the request.

  • raw_response – If True, return the raw response object without status checks. Defaults to False.

Returns:

The response object returned by the server.

Raises:

APIRequestError – If the response status code is not one of the acceptable statuses (200, 204, 207) and raw_response is False.

class py_alpaca_api.stock.logos.Logos(headers: dict[str, str])[source]

Handles company logo retrieval from Alpaca API.

Get the logo for a specific symbol.

Retrieves the company logo as binary image data.

Parameters:
  • symbol – The stock symbol to get the logo for.

  • placeholder – If True, returns a placeholder image when logo is not available. Defaults to False.

Returns:

The logo image as binary data.

Return type:

bytes

Raises:
get_logo_url(symbol: str, placeholder: bool = False) str[source]

Get the URL for a symbol’s logo.

This method returns the direct URL to fetch the logo, which can be used in HTML img tags or for direct browser access.

Parameters:
  • symbol – The stock symbol to get the logo URL for.

  • placeholder – If True, includes placeholder parameter in URL. Defaults to False.

Returns:

The URL to the logo image.

Return type:

str

Raises:

ValidationError – If the symbol is invalid.

Save a symbol’s logo to a file.

Downloads the logo and saves it to the specified file path.

Parameters:
  • symbol – The stock symbol to get the logo for.

  • filepath – The path where the logo should be saved.

  • placeholder – If True, saves a placeholder image when logo is not available. Defaults to False.

Raises:
  • ValidationError – If the symbol or filepath is invalid.

  • Exception – If the API request fails or file cannot be written.

get_logo_base64(symbol: str, placeholder: bool = False) str[source]

Get the logo as a base64 encoded string.

Useful for embedding logos directly in HTML or JSON responses.

Parameters:
  • symbol – The stock symbol to get the logo for.

  • placeholder – If True, returns a placeholder image when logo is not available. Defaults to False.

Returns:

The logo image as a base64 encoded string.

Return type:

str

Raises:
get_multiple_logos(symbols: list[str], placeholder: bool = False) dict[str, bytes | None][source]

Get logos for multiple symbols.

Retrieves logos for multiple symbols in a single batch operation.

Parameters:
  • symbols – List of stock symbols to get logos for.

  • placeholder – If True, returns placeholder images when logos are not available. Defaults to False.

Returns:

Dictionary mapping symbols to their logo binary data.

Symbols without logos will have None as value unless placeholder is True.

Return type:

dict

Raises:

ValidationError – If symbols list is invalid.