Requests#

OrderRequest#

class alpaca.trading.requests.OrderRequest(*, symbol: str, qty: float = None, notional: float = None, side: OrderSide, type: OrderType, time_in_force: TimeInForce, order_class: OrderClass = None, extended_hours: bool = None, client_order_id: str = None, take_profit: TakeProfitRequest = None, stop_loss: StopLossRequest = 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[float]

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]

MarketOrderRequest#

class alpaca.trading.requests.MarketOrderRequest(*, symbol: str, qty: float = None, notional: float = None, side: OrderSide, type: OrderType, time_in_force: TimeInForce, order_class: OrderClass = None, extended_hours: bool = None, client_order_id: str = None, take_profit: TakeProfitRequest = None, stop_loss: StopLossRequest = 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[float]

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]

StopOrderRequest#

class alpaca.trading.requests.StopOrderRequest(*, symbol: str, qty: float = None, notional: float = None, side: OrderSide, type: OrderType, time_in_force: TimeInForce, order_class: OrderClass = None, extended_hours: bool = None, client_order_id: str = None, take_profit: TakeProfitRequest = None, stop_loss: StopLossRequest = 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[float]

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

LimitOrderRequest#

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

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[float]

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

float

StopLimitOrderRequest#

class alpaca.trading.requests.StopLimitOrderRequest(*, symbol: str, qty: float = None, notional: float = None, side: OrderSide, type: OrderType, time_in_force: TimeInForce, order_class: OrderClass = None, extended_hours: bool = None, client_order_id: str = None, take_profit: TakeProfitRequest = None, stop_loss: StopLossRequest = 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[float]

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

TrailingStopOrderRequest#

class alpaca.trading.requests.TrailingStopOrderRequest(*, symbol: str, qty: float = None, notional: float = None, side: OrderSide, type: OrderType, time_in_force: TimeInForce, order_class: OrderClass = None, extended_hours: bool = None, client_order_id: str = None, take_profit: TakeProfitRequest = None, stop_loss: StopLossRequest = None, trail_price: float = None, trail_percent: 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[float]

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]

GetOrdersRequest#

class alpaca.trading.requests.GetOrdersRequest(*, status: OrderStatus = None, limit: int = None, after: datetime = None, until: datetime = None, direction: Sort = None, nested: bool = None, side: OrderSide = None, symbols: 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.

Type

Optional[OrderStatus]

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: int = None, time_in_force: TimeInForce = None, limit_price: float = None, stop_price: float = None, trail: float = None, client_order_id: 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: 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: str = None, percentage: 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: AssetStatus = None, asset_class: AssetClass = None, exchange: AssetExchange = 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]

GetPortfolioHistoryRequest#

class alpaca.trading.requests.GetPortfolioHistoryRequest(*, period: str = None, timeframe: str = None, date_end: date = None, extended_hours: bool = 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]

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]

GetCalendarRequest#

class alpaca.trading.requests.GetCalendarRequest(*, start: date = None, end: 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: str = None, symbols: 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)#

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

GetCorporateAnnouncementsRequest#

class alpaca.trading.requests.GetCorporateAnnouncementsRequest(*, ca_types: List[CorporateActionType], since: date, until: date, symbol: str = None, cusip: str = None, date_type: 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]