Models#

Asset#

class alpaca.trading.models.Asset(*, id: UUID, asset_class: AssetClass, exchange: AssetExchange, symbol: str, name: Optional[str] = None, status: AssetStatus, tradable: bool, marginable: bool, shortable: bool, easy_to_borrow: bool, fractionable: bool, min_order_size: Optional[float] = None, min_trade_increment: Optional[float] = None, price_increment: Optional[float] = None, maintenance_margin_requirement: Optional[float] = None, attributes: Optional[List[str]] = None)#

Represents a security. Some Assets are not tradable with Alpaca. These Assets are marked with the flag tradable=false.

For more info, visit https://alpaca.markets/docs/api-references/trading-api/assets/

id#

Unique id of asset

Type:

UUID

asset_class#

The name of the asset class.

Type:

AssetClass

exchange#

Which exchange this asset is available through.

Type:

AssetExchange

symbol#

The symbol identifier of the asset.

Type:

str

name#

The name of the asset.

Type:

Optional[str]

status#

The active status of the asset.

Type:

AssetStatus

tradable#

Whether the asset can be traded.

Type:

bool

marginable#

Whether the asset can be traded on margin.

Type:

bool

shortable#

Whether the asset can be shorted.

Type:

bool

easy_to_borrow#

When shorting, whether the asset is easy to borrow

Type:

bool

fractionable#

Whether fractional shares are available

Type:

bool

attributes#

One of ptp_no_exception or ptp_with_exception. It will include unique characteristics of the asset here.

Type:

Optional[List[str]]

Position#

class alpaca.trading.models.Position(*, asset_id: UUID, symbol: str, exchange: AssetExchange, asset_class: AssetClass, asset_marginable: Optional[bool] = None, avg_entry_price: str, qty: str, side: PositionSide, market_value: Optional[str] = None, cost_basis: str, unrealized_pl: Optional[str] = None, unrealized_plpc: Optional[str] = None, unrealized_intraday_pl: Optional[str] = None, unrealized_intraday_plpc: Optional[str] = None, current_price: Optional[str] = None, lastday_price: Optional[str] = None, change_today: Optional[str] = None, swap_rate: Optional[str] = None, avg_entry_swap_rate: Optional[str] = None, usd: Optional[USDPositionValues] = None, qty_available: Optional[str] = None)#

Represents an open long or short holding in an asset.

asset_id#

ID of the asset.

Type:

UUID

symbol#

Symbol of the asset.

Type:

str

exchange#

Exchange name of the asset.

Type:

AssetExchange

asset_class#

Name of the asset’s asset class.

Type:

AssetClass

asset_marginable#

Indicates if this asset is marginable.

Type:

Optional[bool]

avg_entry_price#

The average entry price of the position.

Type:

str

qty#

The number of shares of the position.

Type:

str

side#

“long” or “short” representing the side of the position.

Type:

PositionSide

market_value#

Total dollar amount of the position.

Type:

Optional[str]

cost_basis#

Total cost basis in dollars.

Type:

str

unrealized_pl#

Unrealized profit/loss in dollars.

Type:

Optional[str]

unrealized_plpc#

Unrealized profit/loss percent.

Type:

Optional[str]

unrealized_intraday_pl#

Unrealized profit/loss in dollars for the day.

Type:

Optional[str]

unrealized_intraday_plpc#

Unrealized profit/loss percent for the day.

Type:

Optional[str]

current_price#

Current asset price per share.

Type:

Optional[str]

lastday_price#

Last day’s asset price per share based on the closing value of the last trading day.

Type:

Optional[str]

change_today#

Percent change from last day’s price.

Type:

Optional[str]

swap_rate#

Swap rate is the exchange rate (without mark-up) used to convert the price into local currency or crypto asset.

Type:

Optional[str]

avg_entry_swap_rate#

The average exchange rate the price was converted into the local currency at.

Type:

Optional[str]

usd#

Represents the position in USD values.

Type:

USDPositionValues

qty_available#

Total number of shares available minus open orders.

Type:

Optional[str]

Order#

class alpaca.trading.models.Order(*, id: UUID, client_order_id: str, created_at: datetime, updated_at: datetime, submitted_at: datetime, filled_at: Optional[datetime] = None, expired_at: Optional[datetime] = None, canceled_at: Optional[datetime] = None, failed_at: Optional[datetime] = None, replaced_at: Optional[datetime] = None, replaced_by: Optional[UUID] = None, replaces: Optional[UUID] = None, asset_id: UUID, symbol: str, asset_class: AssetClass, notional: Optional[str] = None, qty: Optional[Union[str, float]] = None, filled_qty: Optional[Union[str, float]] = None, filled_avg_price: Optional[Union[str, float]] = None, order_class: OrderClass, order_type: OrderType, type: OrderType, side: OrderSide, time_in_force: TimeInForce, limit_price: Optional[Union[str, float]] = None, stop_price: Optional[Union[str, float]] = None, status: OrderStatus, extended_hours: bool, legs: Optional[List[Order]] = None, trail_percent: Optional[str] = None, trail_price: Optional[str] = None, hwm: Optional[str] = None)#

Represents a request for the sale or purchase of an asset.

id#

order ID generated by Alpaca.

Type:

UUID

client_order_id#

Client unique order ID

Type:

str

created_at#

Timestamp when the order was created.

Type:

datetime

updated_at#

Timestamp when the order was last updated.

Type:

datetime

submitted_at#

Timestamp when the order was submitted.

Type:

datetime

filled_at#

Timestamp when the order was filled.

Type:

Optional[datetime]

expired_at#

Timestamp when the order expired at.

Type:

Optional[datetime]

canceled_at#

Timestamp when the order was canceled.

Type:

Optional[datetime]

failed_at#

Timestamp when the order failed at.

Type:

Optional[datetime]

replaced_at#

Timestamp when the order was replaced by a new order.

Type:

Optional[datetime]

replaced_by#

ID of order that replaces this order.

Type:

Optional[UUID]

replaces#

ID of order which this order replaces.

Type:

Optional[UUID]

asset_id#

ID of the asset.

Type:

UUID

symbol#

Symbol of the asset.

Type:

str

asset_class#

Asset class of the asset.

Type:

AssetClass

notional#

Ordered notional amount. If entered, qty will be null. Can take up to 9 decimal points.

Type:

Optional[str]

qty#

Ordered quantity. If entered, notional will be null. Can take up to 9 decimal points.

Type:

Optional[str]

filled_qty#

Filled quantity.

Type:

Optional[str]

filled_avg_price#

Filled average price. Can be 0 until order is processed in case order is passed outside of market hours.

Type:

Optional[str]

order_class#

Valid values: simple, bracket, oco or oto.

Type:

OrderClass

order_type#

Deprecated with just type field below.

Type:

OrderType

type#

Valid values: market, limit, stop, stop_limit, trailing_stop.

Type:

OrderType

side#

Valid values: buy and sell.

Type:

OrderSide

time_in_force#

Length of time the order is in force.

Type:

TimeInForce

limit_price#

Limit price of the order.

Type:

Optional[str]

stop_price#

Stop price of the order.

Type:

Optional[str]

status#

The status of the order.

Type:

OrderStatus

extended_hours#

If true, eligible for execution outside regular trading hours.

Type:

bool

legs#

When querying non-simple order_class orders in a nested style, an array of order entities associated with this order. Otherwise, null.

Type:

Optional[List[alpaca.trading.models.Order]]

trail_percent#

The percent value away from the high water mark for trailing stop orders.

Type:

Optional[str]

trail_price#

The dollar value away from the high water mark for trailing stop orders.

Type:

Optional[str]

hwm#

The highest (lowest) market price seen since the trailing stop order was submitted.

Type:

Optional[str]

TradeAccount#

class alpaca.trading.models.TradeAccount(*, id: UUID, account_number: str, status: AccountStatus, crypto_status: Optional[AccountStatus] = None, currency: Optional[str] = None, buying_power: Optional[str] = None, regt_buying_power: Optional[str] = None, daytrading_buying_power: Optional[str] = None, non_marginable_buying_power: Optional[str] = None, cash: Optional[str] = None, accrued_fees: Optional[str] = None, pending_transfer_out: Optional[str] = None, pending_transfer_in: Optional[str] = None, portfolio_value: Optional[str] = None, pattern_day_trader: Optional[bool] = None, trading_blocked: Optional[bool] = None, transfers_blocked: Optional[bool] = None, account_blocked: Optional[bool] = None, created_at: Optional[datetime] = None, trade_suspended_by_user: Optional[bool] = None, multiplier: Optional[str] = None, shorting_enabled: Optional[bool] = None, equity: Optional[str] = None, last_equity: Optional[str] = None, long_market_value: Optional[str] = None, short_market_value: Optional[str] = None, initial_margin: Optional[str] = None, maintenance_margin: Optional[str] = None, last_maintenance_margin: Optional[str] = None, sma: Optional[str] = None, daytrade_count: Optional[int] = None, options_buying_power: Optional[str] = None, options_approved_level: Optional[int] = None, options_trading_level: Optional[int] = None)#

Represents trading account information for an Account.

id#

The account ID

Type:

UUID

account_number#

The account number

Type:

str

status#

The current status of the account

Type:

AccountStatus

crypto_status#

The status of the account in regards to trading crypto. Only present if crypto trading is enabled for your brokerage account.

Type:

Optional[AccountStatus]

currency#

Currently will always be the value “USD”.

Type:

Optional[str]

buying_power#

Current available cash buying power. If multiplier = 2 then buying_power = max(equity-initial_margin(0) * 2). If multiplier = 1 then buying_power = cash.

Type:

Optional[str]

regt_buying_power#

User’s buying power under Regulation T (excess equity - (equity - margin value) - * margin multiplier)

Type:

Optional[str]

daytrading_buying_power#

The buying power for day trades for the account

Type:

Optional[str]

non_marginable_buying_power#

The non marginable buying power for the account

Type:

Optional[str]

cash#

Cash balance in the account

Type:

Optional[str]

accrued_fees#

Fees accrued in this account

Type:

Optional[str]

pending_transfer_out#

Cash pending transfer out of this account

Type:

Optional[str]

pending_transfer_in#

Cash pending transfer into this account

Type:

Optional[str]

portfolio_value#

Total value of cash + holding positions. (This field is deprecated. It is equivalent to the equity field.)

Type:

str

pattern_day_trader#

Whether the account is flagged as pattern day trader or not.

Type:

Optional[bool]

trading_blocked#

If true, the account is not allowed to place orders.

Type:

Optional[bool]

transfers_blocked#

If true, the account is not allowed to request money transfers.

Type:

Optional[bool]

account_blocked#

If true, the account activity by user is prohibited.

Type:

Optional[bool]

created_at#

Timestamp this account was created at

Type:

Optional[datetime]

trade_suspended_by_user#

If true, the account is not allowed to place orders.

Type:

Optional[bool]

multiplier#

Multiplier value for this account.

Type:

Optional[str]

shorting_enabled#

Flag to denote whether or not the account is permitted to short

Type:

Optional[bool]

equity#

This value is cash + long_market_value + short_market_value. This value isn’t calculated in the SDK it is computed on the server and we return the raw value here.

Type:

Optional[str]

last_equity#

Equity as of previous trading day at 16:00:00 ET

Type:

Optional[str]

long_market_value#

Real-time MtM value of all long positions held in the account

Type:

Optional[str]

short_market_value#

Real-time MtM value of all short positions held in the account

Type:

Optional[str]

initial_margin#

Reg T initial margin requirement

Type:

Optional[str]

maintenance_margin#

Maintenance margin requirement

Type:

Optional[str]

last_maintenance_margin#

Maintenance margin requirement on the previous trading day

Type:

Optional[str]

sma#

Value of Special Memorandum Account (will be used at a later date to provide additional buying_power)

Type:

Optional[str]

daytrade_count#

The current number of daytrades that have been made in the last 5 trading days (inclusive of today)

Type:

Optional[int]

options_buying_power#

Your buying power for options trading

Type:

Optional[str]

options_approved_level#

The options trading level that was approved for this account. 0=disabled, 1=Covered Call/Cash-Secured Put, 2=Long Call/Put.

Type:

Optional[int]

options_trading_level#

The effective options trading level of the account. This is the minimum between account options_approved_level and account configurations max_options_trading_level. 0=disabled, 1=Covered Call/Cash-Secured Put, 2=Long

Type:

Optional[int]

AccountConfiguration#

class alpaca.trading.models.AccountConfiguration(*, dtbp_check: DTBPCheck, fractional_trading: bool, max_margin_multiplier: str, no_shorting: bool, pdt_check: PDTCheck, suspend_trade: bool, trade_confirm_email: TradeConfirmationEmail, ptp_no_exception_entry: bool, max_options_trading_level: Optional[int] = None)#

Represents configuration options for a TradeAccount.

dtbp_check#

Day Trade Buying Power Check. Controls Day Trading Margin Call (DTMC) checks.

Type:

DTBPCheck

fractional_trading#

If true, account is able to participate in fractional trading

Type:

bool

max_margin_multiplier#

A number between 1-4 that represents your max margin multiplier

Type:

str

no_shorting#

If true then Account becomes long-only mode.

Type:

bool

pdt_check#

Controls Pattern Day Trader (PDT) checks.

Type:

PDTCheck

suspend_trade#

If true Account becomes unable to submit new orders

Type:

bool

trade_confirm_email#

Controls whether Trade confirmation emails are sent.

Type:

TradeConfirmationEmail

ptp_no_exception_entry#

If set to true then Alpaca will accept orders for PTP symbols with no exception. Default is false.

Type:

bool

max_options_trading_level#

The desired maximum options trading level. 0=disabled, 1=Covered Call/Cash-Secured Put, 2=Long Call/Put.

Type:

Optional[int]

Watchlist#

class alpaca.trading.models.Watchlist(*, id: UUID, account_id: UUID, name: str, created_at: datetime, updated_at: datetime, assets: Optional[List[Asset]] = None)#

A watchlist is an ordered list of assets. An account can have multiple watchlists. Learn more about watchlists in the documentation. https://alpaca.markets/docs/api-references/trading-api/watchlist/

account_id#

The uuid identifying the account the watchlist belongs to

Type:

UUID

id#

The unique identifier for the watchlist

Type:

UUID

name#

An arbitrary string up to 64 characters identifying the watchlist

Type:

str

created_at#

When the watchlist was created

Type:

datetime

updated_at#

When the watchlist was last updated

Type:

datetime

assets#

The assets in the watchlist, not returned from all endpoints

Type:

Optional[List[Asset]]

Clock#

class alpaca.trading.models.Clock(*, timestamp: datetime, is_open: bool, next_open: datetime, next_close: datetime)#

The market clock for US equity markets. Timestamps are in eastern time.

timestamp#

The current timestamp.

Type:

datetime

is_open#

Whether the market is currently open.

Type:

bool

next_open#

The timestamp when the market will next open.

Type:

datetime

next_close#

The timestamp when the market will next close.

Type:

datetime

Calendar#

class alpaca.trading.models.Calendar(*, date: date, open: datetime, close: datetime)#

The market calendar for equity markets. Describes the market open and close time on a given day.

NonTradeActivity#

class alpaca.trading.models.NonTradeActivity(*args, id: str, account_id: UUID, activity_type: ActivityType, date: date, net_amount: float, description: str, status: Optional[NonTradeActivityStatus] = None, symbol: Optional[str] = None, qty: Optional[float] = None, price: Optional[float] = None, per_share_amount: Optional[float] = None)#

A NonTradeActivity represents an Activity that happened for an account that doesn’t have to do with orders or trades.

date#

The date on which the activity occurred or on which the transaction associated with the activity settled.

Type:

date

net_amount#

The net amount of money (positive or negative) associated with the activity.

Type:

float

description#

Extra description of the NTA if needed. Can be empty string “”

Type:

str

status#

Status of the activity. Not present for all activity types.

Type:

NonTradeActivityStatus

symbol#

The symbol of the security involved with the activity. Not present for all activity types.

Type:

Optional[str]

qty#

For dividend activities, the number of shares that contributed to the payment. Not present for other activity types.

Type:

Optional[float]

price#
Type:

Optional[float]

per_share_amount#

For dividend activities, the average amount paid per share. Not present for other activity types.

Type:

Optional[float]

TradeActivity#

class alpaca.trading.models.TradeActivity(*args, id: str, account_id: UUID, activity_type: ActivityType, transaction_time: datetime, type: TradeActivityType, price: float, qty: float, side: OrderSide, symbol: str, leaves_qty: float, order_id: UUID, cum_qty: float, order_status: OrderStatus)#

Represents information for TradeActivities. TradeActivities are Activities that pertain to trades that happened for an account. IE Fills or partial fills for orders.

transaction_time#

The time and date of when this trade was processed

Type:

datetime

type#

What kind of trade this TradeActivity represents. See TradeActivityType for more details

Type:

TradeActivityType

price#

The per-share price that the trade was executed at.

Type:

float

qty#

The number of shares involved in the trade execution.

Type:

float

side#

What side the trade this TradeActivity represents was on. See OrderSide for more information

Type:

OrderSide

symbol#

The symbol of the asset that was traded

Type:

str

leaves_qty#

For partially filled orders, the quantity of shares that are left to be filled. Will be 0 if order was not a partially filled order

Type:

float

order_id#

The ID for the order filled

Type:

UUID

cum_qty#

The cumulative quantity of shares involved in the execution.

Type:

float

order_status#

The status of the order that executed the trade. See OrderStatus for more details

Type:

OrderStatus

PortfolioHistory#

class alpaca.trading.models.PortfolioHistory(*, timestamp: List[int], equity: List[float], profit_loss: List[float], profit_loss_pct: List[Optional[float]], base_value: float, timeframe: str)#

Contains information about the value of a portfolio over time.

timestamp#

Time of each data element, left-labeled (the beginning of time window).

Type:

List[int]

equity#

Equity value of the account in dollar amount as of the end of each time window.

Type:

List[float]

profit_loss#

Profit/loss in dollar from the base value.

Type:

List[float]

profit_loss_pct#

Profit/loss in percentage from the base value.

Type:

List[Optional[float]]

base_value#

Basis in dollar of the profit loss calculation.

Type:

float

timeframe#

Time window size of each data element.

Type:

str

ClosePositionResponse#

class alpaca.trading.models.ClosePositionResponse(*, order_id: Optional[UUID] = None, status: Optional[int] = None, symbol: Optional[str] = None, body: Union[FailedClosePositionDetails, Order])#

API response for a close position request. .. attribute:: order_id

ID of order that was created to liquidate the position.

type:

Optional[UUID]

status#

Status code corresponding to the request to liquidate the position.

Type:

Optional[int]

symbol#

The symbol of the position being closed.

Type:

Optional[str]

body#

Information relating to the successful or unsuccessful closing of the position.

Type:

Optional[dict]

FailedClosePositionDetails#

class alpaca.trading.models.FailedClosePositionDetails(*, code: int, message: str, available: Optional[float] = None, existing_qty: Optional[float] = None, held_for_orders: Optional[float] = None, symbol: Optional[str] = None)#

API response for failed close position request.

available#

The qty available.

Type:

float

code#

The status code.

Type:

int

existing_qty#

The total qty in account.

Type:

float

held_for_orders#

The qty locked up in existing orders.

Type:

float

message#

Message for failed request.

Type:

str

symbol#

The symbol for the request.

Type:

str

CorporateActionAnnouncement#

class alpaca.trading.models.CorporateActionAnnouncement(*, id: UUID, corporate_action_id: str, ca_type: CorporateActionType, ca_sub_type: CorporateActionSubType, initiating_symbol: str, initiating_original_cusip: str, target_symbol: Optional[str] = None, target_original_cusip: Optional[str] = None, declaration_date: Optional[date] = None, ex_date: Optional[date] = None, record_date: Optional[date] = None, payable_date: Optional[date] = None, cash: float, old_rate: float, new_rate: float)#

An announcement of a corporate action. Corporate actions are events like dividend payouts, mergers and stock splits.

id#

The unique identifier for this single announcement.

Type:

UUID

corporate_action_id#

ID that remains consistent across all announcements for the same corporate action.

Type:

str

ca_type#

The type of corporate action that was announced.

Type:

CorporateActionType

ca_sub_type#

The specific subtype of corporate action that was announced.

Type:

CorporateActionSubType

initiating_symbol#

Symbol of the company initiating the announcement.

Type:

str

initiating_original_cusip#

CUSIP of the company initiating the announcement.

Type:

str

target_symbol#

Symbol of the child company involved in the announcement.

Type:

Optional[str]

target_original_cusip#

CUSIP of the child company involved in the announcement.

Type:

Optional[str]

declaration_date#

Date the corporate action or subsequent terms update was announced.

Type:

Optional[date]

ex_date#

The first date that purchasing a security will not result in a corporate action entitlement.

Type:

Optional[date]

record_date#

The date an account must hold a settled position in the security in order to receive the corporate action entitlement.

Type:

Optional[date]

payable_date#

The date the announcement will take effect. On this date, account stock and cash balances are expected to be processed accordingly.

Type:

Optional[date]

cash#

The amount of cash to be paid per share held by an account on the record date.

Type:

float

old_rate#

The denominator to determine any quantity change ratios in positions.

Type:

float

new_rate#

The numerator to determine any quantity change ratios in positions.

Type:

float