Models#

Asset#

class alpaca.trading.models.Asset(*, id: ~uuid.UUID, class: ~alpaca.trading.enums.AssetClass, exchange: ~alpaca.trading.enums.AssetExchange, symbol: str, name: str = None, status: ~alpaca.trading.enums.AssetStatus, tradable: bool, marginable: bool, shortable: bool, easy_to_borrow: bool, fractionable: bool)#

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

Position#

class alpaca.trading.models.Position(*, asset_id: UUID, symbol: str, exchange: AssetExchange, asset_class: AssetClass, avg_entry_price: str, qty: str, side: PositionSide, market_value: str, cost_basis: str, unrealized_pl: str, unrealized_plpc: str, unrealized_intraday_pl: str, unrealized_intraday_plpc: str, current_price: str, lastday_price: str, change_today: str)#

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

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

str

cost_basis#

Total cost basis in dollars.

Type

str

unrealized_pl#

Unrealized profit/loss in dollars.

Type

str

unrealized_plpc#

Unrealized profit/loss percent.

Type

str

unrealized_intraday_pl#

Unrealized profit/loss in dollars for the day.

Type

str

unrealized_intraday_plpc#

Unrealized profit/loss percent for the day.

Type

str

current_price#

Current asset price per share.

Type

str

lastday_price#

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

Type

str

change_today#

Percent change from last day’s price.

Type

str

Order#

class alpaca.trading.models.Order(*, id: UUID, client_order_id: str, created_at: datetime, updated_at: datetime, submitted_at: datetime, filled_at: datetime = None, expired_at: datetime = None, canceled_at: datetime = None, failed_at: datetime = None, replaced_at: datetime = None, replaced_by: UUID = None, replaces: UUID = None, asset_id: UUID, symbol: str, asset_class: AssetClass, notional: str = None, qty: str = None, filled_qty: str = None, filled_avg_price: str = None, order_class: OrderClass, order_type: OrderType, type: OrderType, side: OrderSide, time_in_force: TimeInForce, limit_price: str = None, stop_price: str = None, status: OrderStatus, extended_hours: bool, legs: List[Order] = None, trail_percent: str = None, trail_price: str = None, hwm: 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: AccountStatus = None, currency: str = None, buying_power: str, regt_buying_power: str, daytrading_buying_power: str, non_marginable_buying_power: str, cash: str, accrued_fees: str, pending_transfer_out: str = None, pending_transfer_in: str = None, portfolio_value: str, pattern_day_trader: bool, trading_blocked: bool, transfers_blocked: bool, account_blocked: bool, created_at: datetime, trade_suspended_by_user: bool, multiplier: str, shorting_enabled: bool, equity: str, last_equity: str, long_market_value: str, short_market_value: str, initial_margin: str, maintenance_margin: str, last_maintenance_margin: str, sma: str, daytrade_count: int)#

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

str

regt_buying_power#

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

Type

str

daytrading_buying_power#

The buying power for day trades for the account

Type

str

non_marginable_buying_power#

The non marginable buying power for the account

Type

str

cash#

Cash balance in the account

Type

str

accrued_fees#

Fees accrued in this account

Type

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

bool

trading_blocked#

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

Type

bool

transfers_blocked#

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

Type

bool

account_blocked#

If true, the account activity by user is prohibited.

Type

bool

created_at#

Timestamp this account was created at

Type

datetime

trade_suspended_by_user#

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

Type

bool

multiplier#

Multiplier value for this account.

Type

str

shorting_enabled#

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

Type

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

str

last_equity#

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

Type

str

long_market_value#

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

Type

str

short_market_value#

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

Type

str

initial_margin#

Reg T initial margin requirement

Type

str

maintenance_margin#

Maintenance margin requirement

Type

str

last_maintenance_margin#

Maintenance margin requirement on the previous trading day

Type

str

sma#

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

Type

str

daytrade_count#

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

Type

int

Watchlist#

class alpaca.trading.models.Watchlist(*, account_id: UUID, id: UUID, name: str, created_at: datetime, updated_at: datetime, assets: 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: NonTradeActivityStatus = None, symbol: str = None, qty: float = None, price: float = None, per_share_amount: 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[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[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: UUID = None, status: int = None, symbol: 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(*, available: float, code: int, existing_qty: float, held_for_orders: float, message: str, symbol: str)#

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: str, target_original_cusip: str, declaration_date: date = None, ex_date: date, record_date: date, payable_date: date, 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

str

target_original_cusip#

CUSIP of the child company involved in the announcement.

Type

str

declaration_date#

Date the corporate action or subsequent terms update was announced.

Type

date

ex_date#

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

Type

date

record_date#

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

Type

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

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