py_alpaca_api.trading.corporate_actions

Exceptions

APIRequestError

Raised when an API request fails.

ValidationError

Raised when input validation fails.

Classes

Requests

CorporateActionModel

Base model for corporate action announcements.

CorporateActions

Functions

corporate_action_class_from_dict(→ CorporateActionModel)

Create appropriate corporate action model from dictionary.

Module Contents

exception py_alpaca_api.trading.corporate_actions.APIRequestError(status_code: int | None = None, message: str = '')[source]

Bases: PyAlpacaAPIError

Raised when an API request fails.

exception py_alpaca_api.trading.corporate_actions.ValidationError[source]

Bases: PyAlpacaAPIError

Raised when input validation fails.

class py_alpaca_api.trading.corporate_actions.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.trading.corporate_actions.CorporateActionModel[source]

Base model for corporate action announcements.

id: str
corporate_action_id: str
ca_type: str
ca_sub_type: str | None
initiating_symbol: str | None
initiating_original_cusip: str | None
target_symbol: str | None
target_original_cusip: str | None
declaration_date: str | None
ex_date: str | None
record_date: str | None
payable_date: str | None
cash: float | None
old_rate: float | None
new_rate: float | None
py_alpaca_api.trading.corporate_actions.corporate_action_class_from_dict(data: dict[str, Any]) CorporateActionModel[source]

Create appropriate corporate action model from dictionary.

Parameters:

data – Dictionary containing corporate action data

Returns:

CorporateActionModel or one of its subclasses based on ca_type

class py_alpaca_api.trading.corporate_actions.CorporateActions(headers: dict[str, str], base_url: str)[source]
get_announcements(since: str, until: str, ca_types: list[str], symbol: str | None = None, cusip: str | None = None, date_type: Literal['declaration_date', 'ex_date', 'record_date', 'payable_date'] | None = None, page_limit: int = 100, page_token: str | None = None) list[py_alpaca_api.models.corporate_action_model.CorporateActionModel][source]

Retrieve corporate action announcements.

Parameters:
  • since – The start (inclusive) of the date range in YYYY-MM-DD format. Date range is limited to 90 days.

  • until – The end (inclusive) of the date range in YYYY-MM-DD format. Date range is limited to 90 days.

  • ca_types – List of corporate action types to return. Valid types: dividend, merger, spinoff, split

  • symbol – Optional filter by symbol

  • cusip – Optional filter by CUSIP

  • date_type – Optional date type for filtering (declaration_date, ex_date, record_date, payable_date)

  • page_limit – Number of results per page (Note: API may return all results regardless)

  • page_token – Token for pagination (currently not used by API)

Returns:

List of CorporateActionModel objects

Raises:
get_announcement_by_id(announcement_id: str) py_alpaca_api.models.corporate_action_model.CorporateActionModel[source]

Retrieve a specific corporate action announcement by ID.

Parameters:

announcement_id – The unique ID of the announcement

Returns:

CorporateActionModel object

Raises:

APIRequestError – If the API request fails or announcement not found

get_all_announcements(since: str, until: str, ca_types: list[str], symbol: str | None = None, cusip: str | None = None, date_type: Literal['declaration_date', 'ex_date', 'record_date', 'payable_date'] | None = None) list[py_alpaca_api.models.corporate_action_model.CorporateActionModel][source]

Retrieve all corporate action announcements.

Note: The API currently returns all results within the date range without pagination, so this method simply calls get_announcements.

Parameters:
  • since – The start (inclusive) of the date range in YYYY-MM-DD format.

  • until – The end (inclusive) of the date range in YYYY-MM-DD format.

  • ca_types – List of corporate action types to return.

  • symbol – Optional filter by symbol

  • cusip – Optional filter by CUSIP

  • date_type – Optional date type for filtering

Returns:

List of all CorporateActionModel objects

Raises: