Positions#

The position endpoints allow you to view and manage your open positions.

Get All Positions#

TradingClient.get_all_positions() Union[List[Position], Dict[str, Any]]#

Gets all the current open positions.

Returns:

List of open positions.

Return type:

List[Position]

Get Open Position#

TradingClient.get_open_position(symbol_or_asset_id: Union[UUID, str]) Union[Position, Dict[str, Any]]#

Gets the open position for an account for a single asset. Throws an APIError if the position does not exist.

Parameters:

symbol_or_asset_id (Union[UUID, str]) – The symbol name of asset id of the position to get.

Returns:

Open position of the asset.

Return type:

Position

Close All Positions#

TradingClient.close_all_positions(cancel_orders: Optional[bool] = None) Union[List[ClosePositionResponse], Dict[str, Any]]#

Liquidates all positions for an account.

Places an order for each open position to liquidate.

Parameters:

cancel_orders (Optional[bool]) – If true is specified, cancel all open orders before liquidating all positions.

Returns:

A list of responses from each closed position containing the status code and

order id.

Return type:

List[ClosePositionResponse]

Close A Position#

TradingClient.close_position(symbol_or_asset_id: Union[UUID, str], close_options: Optional[ClosePositionRequest] = None) Union[Order, Dict[str, Any]]#

Liquidates the position for a single asset.

Places a single order to close the position for the asset.

This method will throw an error if the position does not exist!

Parameters:
  • symbol_or_asset_id (Union[UUID, str]) – The symbol name of asset id of the position to close.

  • close_options – The various close position request parameters.

Returns:

The order that was placed to close the position.

Return type:

alpaca.trading.models.Order

Exercise An Option Contract#

TradingClient.exercise_options_position(symbol_or_contract_id: Union[UUID, str]) None#

This endpoint enables users to exercise a held option contract, converting it into the underlying asset based on the specified terms. All available held shares of this option contract will be exercised. By default, Alpaca will automatically exercise in-the-money (ITM) contracts at expiry. Exercise requests will be processed immediately once received. Exercise requests submitted outside market hours will be rejected. To cancel an exercise request or to submit a Do-not-exercise (DNE) instruction, please contact our support team.

Parameters:

symbol_or_contract_id (Union[UUID, str]) – Option contract symbol or ID.

Returns:

None