Requests#

OrderRequest#

class alpaca.trading.requests.OrderRequest(*, symbol: str, qty: Optional[float] = None, notional: Optional[float] = None, side: OrderSide, type: OrderType, time_in_force: TimeInForce, order_class: Optional[OrderClass] = None, extended_hours: Optional[bool] = None, client_order_id: Optional[str] = None, take_profit: Optional[TakeProfitRequest] = None, stop_loss: Optional[StopLossRequest] = None, position_intent: Optional[PositionIntent] = None)#

A base class for requests for creating an order. You probably shouldn’t directly use this class when submitting an order. Instead, use one of the order type specific classes.

symbol#

The symbol identifier for the asset being traded

Type:

str

qty#

The number of shares to trade. Fractional qty for stocks only with market orders.

Type:

Optional[float]

notional#

The base currency value of the shares to trade. For stocks, only works with MarketOrders. Does not work with qty.

Type:

Optional[float]

side#

Whether the order will buy or sell the asset.

Type:

OrderSide

type#

The execution logic type of the order (market, limit, etc).

Type:

OrderType

time_in_force#

The expiration logic of the order.

Type:

TimeInForce

extended_hours#

Whether the order can be executed during regular market hours.

Type:

Optional[float]

client_order_id#

A string to identify which client submitted the order.

Type:

Optional[str]

order_class#

The class of the order. Simple orders have no other legs.

Type:

Optional[OrderClass]

take_profit#

For orders with multiple legs, an order to exit a profitable trade.

Type:

Optional[TakeProfitRequest]

stop_loss#

For orders with multiple legs, an order to exit a losing trade.

Type:

Optional[StopLossRequest]

position_intent#

An enum to indicate the desired position strategy: BTO, BTC, STO, STC.

Type:

Optional[PositionIntent]

MarketOrderRequest#

class alpaca.trading.requests.MarketOrderRequest(*, symbol: str, qty: Optional[float] = None, notional: Optional[float] = None, side: OrderSide, type: OrderType, time_in_force: TimeInForce, order_class: Optional[OrderClass] = None, extended_hours: Optional[bool] = None, client_order_id: Optional[str] = None, take_profit: Optional[TakeProfitRequest] = None, stop_loss: Optional[StopLossRequest] = None, position_intent: Optional[PositionIntent] = None)#

Used to submit a market order.

symbol#

The symbol identifier for the asset being traded

Type:

str

qty#

The number of shares to trade. Fractional qty for stocks only with market orders.

Type:

Optional[float]

notional#

The base currency value of the shares to trade. For stocks, only works with MarketOrders. Does not work with qty.

Type:

Optional[float]

side#

Whether the order will buy or sell the asset.

Type:

OrderSide

type#

The execution logic type of the order (market, limit, etc).

Type:

OrderType

time_in_force#

The expiration logic of the order.

Type:

TimeInForce

extended_hours#

Whether the order can be executed during regular market hours.

Type:

Optional[float]

client_order_id#

A string to identify which client submitted the order.

Type:

Optional[str]

order_class#

The class of the order. Simple orders have no other legs.

Type:

Optional[OrderClass]

take_profit#

For orders with multiple legs, an order to exit a profitable trade.

Type:

Optional[TakeProfitRequest]

stop_loss#

For orders with multiple legs, an order to exit a losing trade.

Type:

Optional[StopLossRequest]

position_intent#

An enum to indicate the desired position strategy: BTO, BTC, STO, STC.

Type:

Optional[PositionIntent]

StopOrderRequest#

class alpaca.trading.requests.StopOrderRequest(*, symbol: str, qty: Optional[float] = None, notional: Optional[float] = None, side: OrderSide, type: OrderType, time_in_force: TimeInForce, order_class: Optional[OrderClass] = None, extended_hours: Optional[bool] = None, client_order_id: Optional[str] = None, take_profit: Optional[TakeProfitRequest] = None, stop_loss: Optional[StopLossRequest] = None, position_intent: Optional[PositionIntent] = None, stop_price: float)#

Used to submit a stop order.

symbol#

The symbol identifier for the asset being traded

Type:

str

qty#

The number of shares to trade. Fractional qty for stocks only with market orders.

Type:

Optional[float]

notional#

The base currency value of the shares to trade. For stocks, only works with MarketOrders. Does not work with qty.

Type:

Optional[float]

side#

Whether the order will buy or sell the asset.

Type:

OrderSide

type#

The execution logic type of the order (market, limit, etc).

Type:

OrderType

time_in_force#

The expiration logic of the order.

Type:

TimeInForce

extended_hours#

Whether the order can be executed during regular market hours.

Type:

Optional[float]

client_order_id#

A string to identify which client submitted the order.

Type:

Optional[str]

order_class#

The class of the order. Simple orders have no other legs.

Type:

Optional[OrderClass]

take_profit#

For orders with multiple legs, an order to exit a profitable trade.

Type:

Optional[TakeProfitRequest]

stop_loss#

For orders with multiple legs, an order to exit a losing trade.

Type:

Optional[StopLossRequest]

stop_price#

The price at which the stop order is converted to a market order or a stop limit order is converted to a limit order.

Type:

float

position_intent#

An enum to indicate the desired position strategy: BTO, BTC, STO, STC.

Type:

Optional[PositionIntent]

LimitOrderRequest#

class alpaca.trading.requests.LimitOrderRequest(*, symbol: str, qty: Optional[float] = None, notional: Optional[float] = None, side: OrderSide, type: OrderType, time_in_force: TimeInForce, order_class: Optional[OrderClass] = None, extended_hours: Optional[bool] = None, client_order_id: Optional[str] = None, take_profit: Optional[TakeProfitRequest] = None, stop_loss: Optional[StopLossRequest] = None, position_intent: Optional[PositionIntent] = None, limit_price: Optional[float] = None)#

Used to submit a limit order.

symbol#

The symbol identifier for the asset being traded

Type:

str

qty#

The number of shares to trade. Fractional qty for stocks only with market orders.

Type:

Optional[float]

notional#

The base currency value of the shares to trade. For stocks, only works with MarketOrders. Does not work with qty.

Type:

Optional[float]

side#

Whether the order will buy or sell the asset.

Type:

OrderSide

type#

The execution logic type of the order (market, limit, etc).

Type:

OrderType

time_in_force#

The expiration logic of the order.

Type:

TimeInForce

extended_hours#

Whether the order can be executed during regular market hours.

Type:

Optional[float]

client_order_id#

A string to identify which client submitted the order.

Type:

Optional[str]

order_class#

The class of the order. Simple orders have no other legs.

Type:

Optional[OrderClass]

take_profit#

For orders with multiple legs, an order to exit a profitable trade.

Type:

Optional[TakeProfitRequest]

stop_loss#

For orders with multiple legs, an order to exit a losing trade.

Type:

Optional[StopLossRequest]

limit_price#

The worst fill price for a limit or stop limit order.

Type:

Optional[float]

position_intent#

An enum to indicate the desired position strategy: BTO, BTC, STO, STC.

Type:

Optional[PositionIntent]

StopLimitOrderRequest#

class alpaca.trading.requests.StopLimitOrderRequest(*, symbol: str, qty: Optional[float] = None, notional: Optional[float] = None, side: OrderSide, type: OrderType, time_in_force: TimeInForce, order_class: Optional[OrderClass] = None, extended_hours: Optional[bool] = None, client_order_id: Optional[str] = None, take_profit: Optional[TakeProfitRequest] = None, stop_loss: Optional[StopLossRequest] = None, position_intent: Optional[PositionIntent] = None, stop_price: float, limit_price: float)#

Used to submit a stop limit order.

symbol#

The symbol identifier for the asset being traded

Type:

str

qty#

The number of shares to trade. Fractional qty for stocks only with market orders.

Type:

Optional[float]

notional#

The base currency value of the shares to trade. For stocks, only works with MarketOrders. Does not work with qty.

Type:

Optional[float]

side#

Whether the order will buy or sell the asset.

Type:

OrderSide

type#

The execution logic type of the order (market, limit, etc).

Type:

OrderType

time_in_force#

The expiration logic of the order.

Type:

TimeInForce

extended_hours#

Whether the order can be executed during regular market hours.

Type:

Optional[float]

client_order_id#

A string to identify which client submitted the order.

Type:

Optional[str]

order_class#

The class of the order. Simple orders have no other legs.

Type:

Optional[OrderClass]

take_profit#

For orders with multiple legs, an order to exit a profitable trade.

Type:

Optional[TakeProfitRequest]

stop_loss#

For orders with multiple legs, an order to exit a losing trade.

Type:

Optional[StopLossRequest]

stop_price#

The price at which the stop order is converted to a market order or a stop limit order is converted to a limit order.

Type:

float

limit_price#

The worst fill price for a limit or stop limit order.

Type:

float

position_intent#

An enum to indicate the desired position strategy: BTO, BTC, STO, STC.

Type:

Optional[PositionIntent]

TrailingStopOrderRequest#

class alpaca.trading.requests.TrailingStopOrderRequest(*, symbol: str, qty: Optional[float] = None, notional: Optional[float] = None, side: OrderSide, type: OrderType, time_in_force: TimeInForce, order_class: Optional[OrderClass] = None, extended_hours: Optional[bool] = None, client_order_id: Optional[str] = None, take_profit: Optional[TakeProfitRequest] = None, stop_loss: Optional[StopLossRequest] = None, position_intent: Optional[PositionIntent] = None, trail_price: Optional[float] = None, trail_percent: Optional[float] = None)#

Used to submit a trailing stop order.

symbol#

The symbol identifier for the asset being traded

Type:

str

qty#

The number of shares to trade. Fractional qty for stocks only with market orders.

Type:

Optional[float]

notional#

The base currency value of the shares to trade. For stocks, only works with MarketOrders. Does not work with qty.

Type:

Optional[float]

side#

Whether the order will buy or sell the asset.

Type:

OrderSide

type#

The execution logic type of the order (market, limit, etc).

Type:

OrderType

time_in_force#

The expiration logic of the order.

Type:

TimeInForce

extended_hours#

Whether the order can be executed during regular market hours.

Type:

Optional[float]

client_order_id#

A string to identify which client submitted the order.

Type:

Optional[str]

order_class#

The class of the order. Simple orders have no other legs.

Type:

Optional[OrderClass]

take_profit#

For orders with multiple legs, an order to exit a profitable trade.

Type:

Optional[TakeProfitRequest]

stop_loss#

For orders with multiple legs, an order to exit a losing trade.

Type:

Optional[StopLossRequest]

trail_price#

The absolute price difference by which the trailing stop will trail.

Type:

Optional[float]

trail_percent#

The percent price difference by which the trailing stop will trail.

Type:

Optional[float]

position_intent#

An enum to indicate the desired position strategy: BTO, BTC, STO, STC.

Type:

Optional[PositionIntent]

GetOrdersRequest#

class alpaca.trading.requests.GetOrdersRequest(*, status: Optional[QueryOrderStatus] = None, limit: Optional[int] = None, after: Optional[datetime] = None, until: Optional[datetime] = None, direction: Optional[Sort] = None, nested: Optional[bool] = None, side: Optional[OrderSide] = None, symbols: Optional[List[str]] = None)#

Contains data for submitting a request to retrieve orders.

status#

Order status to be queried. open, closed or all. Defaults to open. Not same as OrderStatus property of Order.

Type:

Optional[QueryOrderStatus]

limit#

The maximum number of orders in response. Defaults to 50 and max is 500.

Type:

Optional[int]

after#

The response will include only ones submitted after this timestamp.

Type:

Optional[datetime]

until#

The response will include only ones submitted until this timestamp.

Type:

Optional[datetime]

direction#

The chronological order of response based on the submission time. asc or desc. Defaults to desc.

Type:

Optional[Sort]

nested#

If true, the result will roll up multi-leg orders under the legs field of primary order.

Type:

Optional[bool]

side#

Filters down to orders that have a matching side field set.

Type:

Optional[OrderSide]

symbols#

List of symbols to filter by.

Type:

Optional[List[str]]

GetOrderByIdRequest#

class alpaca.trading.requests.GetOrderByIdRequest(*, nested: bool)#

Contains data for submitting a request to retrieve a single order by its order id.

nested#

If true, the result will roll up multi-leg orders under the legs field of primary order.

Type:

bool

ReplaceOrderRequest#

class alpaca.trading.requests.ReplaceOrderRequest(*, qty: Optional[int] = None, time_in_force: Optional[TimeInForce] = None, limit_price: Optional[float] = None, stop_price: Optional[float] = None, trail: Optional[float] = None, client_order_id: Optional[str] = None)#

Contains data for submitting a request to replace an order.

qty#

Number of shares to trade

Type:

Optional[int]

time_in_force#

The new expiration logic of the order.

Type:

Optional[TimeInForce]

limit_price#

Required if type of order being replaced is limit or stop_limit

Type:

Optional[float]

stop_price#

Required if type of order being replaced is stop or stop_limit

Type:

Optional[float]

trail#

The new value of the trail_price or trail_percent value (works only for type=“trailing_stop”)

Type:

Optional[float]

client_order_id#

A unique identifier for the order.

Type:

Optional[str]

TakeProfitRequest#

class alpaca.trading.requests.TakeProfitRequest(*, limit_price: float)#

Used for providing take profit details for a bracket order.

limit_price#

The execution price for exiting a profitable trade.

Type:

float

StopLossRequest#

class alpaca.trading.requests.StopLossRequest(*, stop_price: float, limit_price: Optional[float] = None)#

Used for providing stop loss details for a bracket order.

stop_price#

The price at which the stop loss is triggered.

Type:

float

limit_price#

The execution price for exiting a losing trade. If not provided, the stop loss will execute as a market order.

Type:

Optional[float]

ClosePositionRequest#

class alpaca.trading.requests.ClosePositionRequest(*, qty: Optional[str] = None, percentage: Optional[str] = None)#
qty#

The number of shares to liquidate.

Type:

str

percentage#

The percentage of shares to liquidate.

Type:

str

GetAssetsRequest#

class alpaca.trading.requests.GetAssetsRequest(*, status: Optional[AssetStatus] = None, asset_class: Optional[AssetClass] = None, exchange: Optional[AssetExchange] = None, attributes: Optional[str] = None)#

When querying for available assets, this model provides the parameters that can be filtered by.

status#

The active status of the asset.

Type:

Optional[AssetStatus]

asset_class#

The type of asset (i.e. us_equity, crypto).

Type:

Optional[AssetClass]

exchange#

The exchange the asset trades on.

Type:

Optional[AssetExchange]

attributes#

Comma separated values to query for more than one attribute.

Type:

Optional[str]

GetPortfolioHistoryRequest#

class alpaca.trading.requests.GetPortfolioHistoryRequest(*, period: Optional[str] = None, timeframe: Optional[str] = None, intraday_reporting: Optional[str] = None, start: Optional[datetime] = None, pnl_reset: Optional[str] = None, end: Optional[datetime] = None, date_end: Optional[date] = None, extended_hours: Optional[bool] = None, cashflow_types: Optional[str] = None)#
period#

The duration of the data in number + unit, such as 1D. unit can be D for day, W for week, M for month and A for year. Defaults to 1M.

Type:

Optional[str]

timeframe#

The resolution of time window. 1Min, 5Min, 15Min, 1H, or 1D. If omitted, 1Min for less than 7 days period, 15Min for less than 30 days, or otherwise 1D.

Type:

Optional[str]

intraday_reporting#

this specfies which timestamps to return data points

Type:

Optional[str]

start#

The timestamp the data is returned starting from in RFC3339 format (including timezone specification).

Type:

Optional[datetime]

pnl_reset#

efines how we are calculating the baseline values for Profit And Loss (pnl) for queries with timeframe less than 1D (intraday queries).

Type:

Optional[str]

end#

The timestamp the data is returned up to in RFC3339 format (including timezone specification).

Type:

Optional[datetime]

date_end#

The date the data is returned up to. Defaults to the current market date (rolls over at the market open if extended_hours is false, otherwise at 7am ET).

Type:

Optional[date]

extended_hours#

If true, include extended hours in the result. This is effective only for timeframe less than 1D.

Type:

Optional[bool]

cashflow_types#

The cashflow activities to include in the report

Type:

Optional[str]

GetCalendarRequest#

class alpaca.trading.requests.GetCalendarRequest(*, start: Optional[date] = None, end: Optional[date] = None)#

Represents the optional filtering you can do when requesting a Calendar object

CreateWatchlistRequest#

class alpaca.trading.requests.CreateWatchlistRequest(*, name: str, symbols: List[str])#

Represents the fields you can specify when creating a Watchlist

name#

Name of the Watchlist

Type:

str

symbols#

Symbols of Assets to watch

Type:

List[str]

UpdateWatchlistRequest#

class alpaca.trading.requests.UpdateWatchlistRequest(*, name: Optional[str] = None, symbols: Optional[List[str]] = None)#

Represents the fields you can specify when updating a Watchlist

name#

Name of the Watchlist

Type:

Optional[str]

symbols#

Symbols of Assets to watch

Type:

Optional[List[str]]

CancelOrderResponse#

class alpaca.trading.requests.CancelOrderResponse(*, id: UUID, status: int, body: Optional[Dict[str, Any]] = None)#

Data returned after requesting to cancel an order. It contains the cancel status of an order.

id#

The order id

Type:

UUID

status#

The HTTP status returned after attempting to cancel the order.

Type:

int

body#

an error description

Type:

Dict[str, Any]

GetCorporateAnnouncementsRequest#

class alpaca.trading.requests.GetCorporateAnnouncementsRequest(*, ca_types: List[CorporateActionType], since: date, until: date, symbol: Optional[str] = None, cusip: Optional[str] = None, date_type: Optional[CorporateActionDateType] = None)#

Contains parameters for querying corporate action data. .. attribute:: ca_types

A list of corporate action types.

type:

List[CorporateActionType]

since#

The start (inclusive) of the date range when searching corporate action announcements. The date range is limited to 90 days.

Type:

date

until#

The end (inclusive) of the date range when searching corporate action announcements. The date range is limited to 90 days.

Type:

date

symbol#

The symbol of the company initiating the announcement.

Type:

Optional[str]

cusip#

The CUSIP of the company initiating the announcement.

Type:

Optional[str]

date_type#

The date type for the announcement.

Type:

Optional[CorporateActionDateType]