alpaca-py-nopandas 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- alpaca/__init__.py +2 -0
- alpaca/broker/__init__.py +8 -0
- alpaca/broker/client.py +2360 -0
- alpaca/broker/enums.py +528 -0
- alpaca/broker/models/__init__.py +7 -0
- alpaca/broker/models/accounts.py +347 -0
- alpaca/broker/models/cip.py +265 -0
- alpaca/broker/models/documents.py +159 -0
- alpaca/broker/models/funding.py +114 -0
- alpaca/broker/models/journals.py +71 -0
- alpaca/broker/models/rebalancing.py +80 -0
- alpaca/broker/models/trading.py +13 -0
- alpaca/broker/requests.py +1135 -0
- alpaca/common/__init__.py +6 -0
- alpaca/common/constants.py +13 -0
- alpaca/common/enums.py +64 -0
- alpaca/common/exceptions.py +47 -0
- alpaca/common/models.py +21 -0
- alpaca/common/requests.py +82 -0
- alpaca/common/rest.py +438 -0
- alpaca/common/types.py +7 -0
- alpaca/common/utils.py +89 -0
- alpaca/data/__init__.py +5 -0
- alpaca/data/enums.py +184 -0
- alpaca/data/historical/__init__.py +13 -0
- alpaca/data/historical/corporate_actions.py +76 -0
- alpaca/data/historical/crypto.py +299 -0
- alpaca/data/historical/news.py +63 -0
- alpaca/data/historical/option.py +230 -0
- alpaca/data/historical/screener.py +72 -0
- alpaca/data/historical/stock.py +226 -0
- alpaca/data/historical/utils.py +30 -0
- alpaca/data/live/__init__.py +11 -0
- alpaca/data/live/crypto.py +168 -0
- alpaca/data/live/news.py +62 -0
- alpaca/data/live/option.py +88 -0
- alpaca/data/live/stock.py +199 -0
- alpaca/data/live/websocket.py +390 -0
- alpaca/data/mappings.py +84 -0
- alpaca/data/models/__init__.py +7 -0
- alpaca/data/models/bars.py +83 -0
- alpaca/data/models/base.py +45 -0
- alpaca/data/models/corporate_actions.py +309 -0
- alpaca/data/models/news.py +90 -0
- alpaca/data/models/orderbooks.py +59 -0
- alpaca/data/models/quotes.py +78 -0
- alpaca/data/models/screener.py +68 -0
- alpaca/data/models/snapshots.py +132 -0
- alpaca/data/models/trades.py +204 -0
- alpaca/data/requests.py +580 -0
- alpaca/data/timeframe.py +148 -0
- alpaca/py.typed +0 -0
- alpaca/trading/__init__.py +5 -0
- alpaca/trading/client.py +784 -0
- alpaca/trading/enums.py +412 -0
- alpaca/trading/models.py +697 -0
- alpaca/trading/requests.py +604 -0
- alpaca/trading/stream.py +225 -0
- alpaca_py_nopandas-0.1.0.dist-info/LICENSE +201 -0
- alpaca_py_nopandas-0.1.0.dist-info/METADATA +299 -0
- alpaca_py_nopandas-0.1.0.dist-info/RECORD +62 -0
- alpaca_py_nopandas-0.1.0.dist-info/WHEEL +4 -0
alpaca/trading/models.py
ADDED
@@ -0,0 +1,697 @@
|
|
1
|
+
from alpaca.common.models import ModelWithID, ValidateBaseModel as BaseModel
|
2
|
+
from uuid import UUID
|
3
|
+
from datetime import datetime, date
|
4
|
+
from typing import Any, Optional, List, Union, Dict
|
5
|
+
from alpaca.trading.enums import (
|
6
|
+
AssetClass,
|
7
|
+
AssetStatus,
|
8
|
+
AssetExchange,
|
9
|
+
ContractType,
|
10
|
+
DTBPCheck,
|
11
|
+
ExerciseStyle,
|
12
|
+
OrderStatus,
|
13
|
+
OrderType,
|
14
|
+
OrderClass,
|
15
|
+
PDTCheck,
|
16
|
+
PositionIntent,
|
17
|
+
TimeInForce,
|
18
|
+
OrderSide,
|
19
|
+
PositionSide,
|
20
|
+
AccountStatus,
|
21
|
+
TradeActivityType,
|
22
|
+
NonTradeActivityStatus,
|
23
|
+
ActivityType,
|
24
|
+
CorporateActionType,
|
25
|
+
CorporateActionSubType,
|
26
|
+
TradeConfirmationEmail,
|
27
|
+
TradeEvent,
|
28
|
+
)
|
29
|
+
from pydantic import Field, model_validator
|
30
|
+
|
31
|
+
|
32
|
+
class Asset(ModelWithID):
|
33
|
+
"""
|
34
|
+
Represents a security. Some Assets are not tradable with Alpaca. These Assets are
|
35
|
+
marked with the flag `tradable=false`.
|
36
|
+
|
37
|
+
For more info, visit https://alpaca.markets/docs/api-references/trading-api/assets/
|
38
|
+
|
39
|
+
Attributes:
|
40
|
+
id (UUID): Unique id of asset
|
41
|
+
asset_class (AssetClass): The name of the asset class.
|
42
|
+
exchange (AssetExchange): Which exchange this asset is available through.
|
43
|
+
symbol (str): The symbol identifier of the asset.
|
44
|
+
name (Optional[str]): The name of the asset.
|
45
|
+
status (AssetStatus): The active status of the asset.
|
46
|
+
tradable (bool): Whether the asset can be traded.
|
47
|
+
marginable (bool): Whether the asset can be traded on margin.
|
48
|
+
shortable (bool): Whether the asset can be shorted.
|
49
|
+
easy_to_borrow (bool): When shorting, whether the asset is easy to borrow
|
50
|
+
fractionable (bool): Whether fractional shares are available
|
51
|
+
attributes (Optional[List[str]]): One of ptp_no_exception or ptp_with_exception. It will include unique characteristics of the asset here.
|
52
|
+
"""
|
53
|
+
|
54
|
+
asset_class: AssetClass = Field(
|
55
|
+
alias="class"
|
56
|
+
) # using a pydantic alias to allow parsing data with the `class` keyword field
|
57
|
+
exchange: AssetExchange
|
58
|
+
symbol: str
|
59
|
+
name: Optional[str] = None
|
60
|
+
status: AssetStatus
|
61
|
+
tradable: bool
|
62
|
+
marginable: bool
|
63
|
+
shortable: bool
|
64
|
+
easy_to_borrow: bool
|
65
|
+
fractionable: bool
|
66
|
+
min_order_size: Optional[float] = None
|
67
|
+
min_trade_increment: Optional[float] = None
|
68
|
+
price_increment: Optional[float] = None
|
69
|
+
maintenance_margin_requirement: Optional[float] = None
|
70
|
+
attributes: Optional[List[str]] = None
|
71
|
+
|
72
|
+
|
73
|
+
class USDPositionValues(BaseModel):
|
74
|
+
"""
|
75
|
+
Represents an open long or short holding in an asset in USD.
|
76
|
+
|
77
|
+
Attributes:
|
78
|
+
avg_entry_price (str): The average entry price of the position.
|
79
|
+
market_value (str): Total dollar amount of the position.
|
80
|
+
cost_basis (str): Total cost basis in dollars.
|
81
|
+
unrealized_pl (str): Unrealized profit/loss in dollars.
|
82
|
+
unrealized_plpc (str): Unrealized profit/loss percent.
|
83
|
+
unrealized_intraday_pl (str): Unrealized profit/loss in dollars for the day.
|
84
|
+
unrealized_intraday_plpc (str): Unrealized profit/loss percent for the day.
|
85
|
+
current_price (str): Current asset price per share.
|
86
|
+
lastday_price (str): Last day’s asset price per share based on the closing value of the last trading day.
|
87
|
+
change_today (str): Percent change from last day's price.
|
88
|
+
|
89
|
+
"""
|
90
|
+
|
91
|
+
avg_entry_price: str
|
92
|
+
market_value: str
|
93
|
+
cost_basis: str
|
94
|
+
unrealized_pl: str
|
95
|
+
unrealized_plpc: str
|
96
|
+
unrealized_intraday_pl: str
|
97
|
+
unrealized_intraday_plpc: str
|
98
|
+
current_price: str
|
99
|
+
lastday_price: str
|
100
|
+
change_today: str
|
101
|
+
|
102
|
+
|
103
|
+
class Position(BaseModel):
|
104
|
+
"""
|
105
|
+
Represents an open long or short holding in an asset.
|
106
|
+
|
107
|
+
Attributes:
|
108
|
+
asset_id (UUID): ID of the asset.
|
109
|
+
symbol (str): Symbol of the asset.
|
110
|
+
exchange (AssetExchange): Exchange name of the asset.
|
111
|
+
asset_class (AssetClass): Name of the asset's asset class.
|
112
|
+
asset_marginable (Optional[bool]): Indicates if this asset is marginable.
|
113
|
+
avg_entry_price (str): The average entry price of the position.
|
114
|
+
qty (str): The number of shares of the position.
|
115
|
+
side (PositionSide): "long" or "short" representing the side of the position.
|
116
|
+
market_value (Optional[str]): Total dollar amount of the position.
|
117
|
+
cost_basis (str): Total cost basis in dollars.
|
118
|
+
unrealized_pl (Optional[str]): Unrealized profit/loss in dollars.
|
119
|
+
unrealized_plpc (Optional[str]): Unrealized profit/loss percent.
|
120
|
+
unrealized_intraday_pl (Optional[str]): Unrealized profit/loss in dollars for the day.
|
121
|
+
unrealized_intraday_plpc (Optional[str]): Unrealized profit/loss percent for the day.
|
122
|
+
current_price (Optional[str]): Current asset price per share.
|
123
|
+
lastday_price (Optional[str]): Last day’s asset price per share based on the closing value of the last trading day.
|
124
|
+
change_today (Optional[str]): Percent change from last day's price.
|
125
|
+
swap_rate (Optional[str]): Swap rate is the exchange rate (without mark-up) used to convert the price into local currency or crypto asset.
|
126
|
+
avg_entry_swap_rate (Optional[str]): The average exchange rate the price was converted into the local currency at.
|
127
|
+
usd (USDPositionValues): Represents the position in USD values.
|
128
|
+
qty_available (Optional[str]): Total number of shares available minus open orders.
|
129
|
+
|
130
|
+
"""
|
131
|
+
|
132
|
+
asset_id: UUID
|
133
|
+
symbol: str
|
134
|
+
exchange: AssetExchange
|
135
|
+
asset_class: AssetClass
|
136
|
+
asset_marginable: Optional[bool] = None
|
137
|
+
avg_entry_price: str
|
138
|
+
qty: str
|
139
|
+
side: PositionSide
|
140
|
+
market_value: Optional[str] = None
|
141
|
+
cost_basis: str
|
142
|
+
unrealized_pl: Optional[str] = None
|
143
|
+
unrealized_plpc: Optional[str] = None
|
144
|
+
unrealized_intraday_pl: Optional[str] = None
|
145
|
+
unrealized_intraday_plpc: Optional[str] = None
|
146
|
+
current_price: Optional[str] = None
|
147
|
+
lastday_price: Optional[str] = None
|
148
|
+
change_today: Optional[str] = None
|
149
|
+
swap_rate: Optional[str] = None
|
150
|
+
avg_entry_swap_rate: Optional[str] = None
|
151
|
+
usd: Optional[USDPositionValues] = None
|
152
|
+
qty_available: Optional[str] = None
|
153
|
+
|
154
|
+
|
155
|
+
class AllAccountsPositions(BaseModel):
|
156
|
+
"""
|
157
|
+
Represents the positions of every account as of last market close.
|
158
|
+
|
159
|
+
Attributes:
|
160
|
+
as_of (datetime): Timestamp for which the positions are returned.
|
161
|
+
positions (Dict[str, List[Position]]): Positions held by an account, keyed by account_id.
|
162
|
+
"""
|
163
|
+
|
164
|
+
as_of: datetime
|
165
|
+
positions: Dict[str, List[Position]]
|
166
|
+
|
167
|
+
|
168
|
+
class Order(ModelWithID):
|
169
|
+
"""
|
170
|
+
Represents a request for the sale or purchase of an asset.
|
171
|
+
|
172
|
+
Attributes:
|
173
|
+
id (UUID): order ID generated by Alpaca.
|
174
|
+
client_order_id (str): Client unique order ID
|
175
|
+
created_at (datetime): Timestamp when the order was created.
|
176
|
+
updated_at (datetime): Timestamp when the order was last updated.
|
177
|
+
submitted_at (datetime): Timestamp when the order was submitted.
|
178
|
+
filled_at (Optional[datetime]): Timestamp when the order was filled.
|
179
|
+
expired_at (Optional[datetime]): Timestamp when the order expired at.
|
180
|
+
expires_at (Optional[datetime]): An auto cancel request will be triggered after this timestamp.
|
181
|
+
canceled_at (Optional[datetime]): Timestamp when the order was canceled.
|
182
|
+
failed_at (Optional[datetime]): Timestamp when the order failed at.
|
183
|
+
replaced_at (Optional[datetime]): Timestamp when the order was replaced by a new order.
|
184
|
+
replaced_by (Optional[UUID]): ID of order that replaces this order.
|
185
|
+
replaces (Optional[UUID]): ID of order which this order replaces.
|
186
|
+
asset_id (Optional[UUID]): ID of the asset. Omitted from top-level of response if the order is of mleg class.
|
187
|
+
symbol (Optional[str]): Symbol of the asset. Omitted from top-level of response if the order is of mleg class.
|
188
|
+
asset_class (Optional[AssetClass]): Asset class of the asset. Omitted from top-level of response if the order is of mleg class.
|
189
|
+
notional (Optional[str]): Ordered notional amount. If entered, qty will be null. Can take up to 9 decimal
|
190
|
+
points.
|
191
|
+
qty (Optional[str]): Ordered quantity. If entered, notional will be null. Can take up to 9 decimal points.
|
192
|
+
filled_qty (Optional[str]): Filled quantity.
|
193
|
+
filled_avg_price (Optional[str]): Filled average price. Can be 0 until order is processed in case order is
|
194
|
+
passed outside of market hours.
|
195
|
+
order_class (OrderClass): Valid values: simple, bracket, oco or oto.
|
196
|
+
order_type (Optional[OrderType]): Deprecated with just type field below. Omitted from legs of mleg orders.
|
197
|
+
type (Optional[OrderType]): Valid values: market, limit, stop, stop_limit, trailing_stop. Omitted from legs of mleg orders.
|
198
|
+
side (Optional[OrderSide]): Valid values: buy and sell. Omitted from top-level of response if the order is of mleg class.
|
199
|
+
time_in_force (TimeInForce): Length of time the order is in force.
|
200
|
+
limit_price (Optional[str]): Limit price of the order.
|
201
|
+
stop_price (Optional[str]): Stop price of the order.
|
202
|
+
status (OrderStatus): The status of the order.
|
203
|
+
extended_hours (bool): If true, eligible for execution outside regular trading hours.
|
204
|
+
legs (Optional[List[alpaca.trading.models.Order]]): When querying non-simple order_class orders in a nested style,
|
205
|
+
an array of order entities associated with this order. Otherwise, null.
|
206
|
+
trail_percent (Optional[str]): The percent value away from the high water mark for trailing stop orders.
|
207
|
+
trail_price (Optional[str]): The dollar value away from the high water mark for trailing stop orders.
|
208
|
+
hwm (Optional[str]): The highest (lowest) market price seen since the trailing stop order was submitted.
|
209
|
+
position_intent (Optional[PositionIntent]): Represents the desired position strategy.
|
210
|
+
ratio_qty (Optional[str]): The proportional quantity of this leg in relation to the overall multi-leg order quantity.
|
211
|
+
"""
|
212
|
+
|
213
|
+
client_order_id: str
|
214
|
+
created_at: datetime
|
215
|
+
updated_at: datetime
|
216
|
+
submitted_at: datetime
|
217
|
+
filled_at: Optional[datetime] = None
|
218
|
+
expired_at: Optional[datetime] = None
|
219
|
+
expires_at: Optional[datetime] = None
|
220
|
+
canceled_at: Optional[datetime] = None
|
221
|
+
failed_at: Optional[datetime] = None
|
222
|
+
replaced_at: Optional[datetime] = None
|
223
|
+
replaced_by: Optional[UUID] = None
|
224
|
+
replaces: Optional[UUID] = None
|
225
|
+
asset_id: Optional[UUID] = None
|
226
|
+
symbol: Optional[str] = None
|
227
|
+
asset_class: Optional[AssetClass] = None
|
228
|
+
notional: Optional[str] = None
|
229
|
+
qty: Optional[Union[str, float]] = None
|
230
|
+
filled_qty: Optional[Union[str, float]] = None
|
231
|
+
filled_avg_price: Optional[Union[str, float]] = None
|
232
|
+
order_class: OrderClass
|
233
|
+
order_type: Optional[OrderType] = None
|
234
|
+
type: Optional[OrderType] = None
|
235
|
+
side: Optional[OrderSide] = None
|
236
|
+
time_in_force: TimeInForce
|
237
|
+
limit_price: Optional[Union[str, float]] = None
|
238
|
+
stop_price: Optional[Union[str, float]] = None
|
239
|
+
status: OrderStatus
|
240
|
+
extended_hours: bool
|
241
|
+
legs: Optional[List["Order"]] = None
|
242
|
+
trail_percent: Optional[str] = None
|
243
|
+
trail_price: Optional[str] = None
|
244
|
+
hwm: Optional[str] = None
|
245
|
+
position_intent: Optional[PositionIntent] = None
|
246
|
+
ratio_qty: Optional[Union[str, float]] = None
|
247
|
+
|
248
|
+
def __init__(self, **data: Any) -> None:
|
249
|
+
if "order_class" not in data or data["order_class"] == "":
|
250
|
+
data["order_class"] = OrderClass.SIMPLE
|
251
|
+
|
252
|
+
# mleg responses will give ''s that will need to be converted to None
|
253
|
+
# to avoid validation errors from pydantic
|
254
|
+
for k in [
|
255
|
+
"asset_id",
|
256
|
+
"symbol",
|
257
|
+
"asset_class",
|
258
|
+
"side",
|
259
|
+
"position_intent",
|
260
|
+
"type",
|
261
|
+
"order_type",
|
262
|
+
]:
|
263
|
+
if k in data and data[k] == "":
|
264
|
+
data[k] = None
|
265
|
+
|
266
|
+
super().__init__(**data)
|
267
|
+
|
268
|
+
|
269
|
+
class FailedClosePositionDetails(BaseModel):
|
270
|
+
"""API response for failed close position request.
|
271
|
+
|
272
|
+
Attributes:
|
273
|
+
available (float): The qty available.
|
274
|
+
code (int): The status code.
|
275
|
+
existing_qty (float): The total qty in account.
|
276
|
+
held_for_orders (float): The qty locked up in existing orders.
|
277
|
+
message (str): Message for failed request.
|
278
|
+
symbol (str): The symbol for the request.
|
279
|
+
"""
|
280
|
+
|
281
|
+
code: int
|
282
|
+
message: str
|
283
|
+
available: Optional[float] = None
|
284
|
+
existing_qty: Optional[float] = None
|
285
|
+
held_for_orders: Optional[float] = None
|
286
|
+
symbol: Optional[str] = None
|
287
|
+
|
288
|
+
|
289
|
+
class ClosePositionResponse(BaseModel):
|
290
|
+
"""API response for a close position request.
|
291
|
+
Attributes:
|
292
|
+
order_id (Optional[UUID]): ID of order that was created to liquidate the position.
|
293
|
+
status (Optional[int]): Status code corresponding to the request to liquidate the position.
|
294
|
+
symbol (Optional[str]): The symbol of the position being closed.
|
295
|
+
body (Optional[dict]): Information relating to the successful or unsuccessful closing of the position.
|
296
|
+
"""
|
297
|
+
|
298
|
+
order_id: Optional[UUID] = None
|
299
|
+
status: Optional[int] = None
|
300
|
+
symbol: Optional[str] = None
|
301
|
+
body: Union[FailedClosePositionDetails, Order]
|
302
|
+
|
303
|
+
|
304
|
+
class PortfolioHistory(BaseModel):
|
305
|
+
"""
|
306
|
+
Contains information about the value of a portfolio over time.
|
307
|
+
|
308
|
+
Attributes:
|
309
|
+
timestamp (List[int]): Time of each data element, left-labeled (the beginning of time window).
|
310
|
+
equity (List[float]): Equity value of the account in dollar amount as of the end of each time window.
|
311
|
+
profit_loss (List[float]): Profit/loss in dollar from the base value.
|
312
|
+
profit_loss_pct (List[Optional[float]]): Profit/loss in percentage from the base value.
|
313
|
+
base_value (Optional[float]): Basis in dollar of the profit loss calculation.
|
314
|
+
timeframe (str): Time window size of each data element.
|
315
|
+
cashflow (Dict[ActivityType, List[float]]): Cash flow amounts per activity type, if any.
|
316
|
+
"""
|
317
|
+
|
318
|
+
timestamp: List[int]
|
319
|
+
equity: List[float]
|
320
|
+
profit_loss: List[float]
|
321
|
+
profit_loss_pct: List[Optional[float]]
|
322
|
+
base_value: Optional[float] = None
|
323
|
+
timeframe: str
|
324
|
+
cashflow: Dict[ActivityType, List[float]] = {}
|
325
|
+
|
326
|
+
|
327
|
+
class Watchlist(ModelWithID):
|
328
|
+
"""
|
329
|
+
A watchlist is an ordered list of assets. An account can have multiple watchlists.
|
330
|
+
Learn more about watchlists in the documentation. https://alpaca.markets/docs/api-references/trading-api/watchlist/
|
331
|
+
|
332
|
+
Attributes:
|
333
|
+
account_id (UUID): The uuid identifying the account the watchlist belongs to
|
334
|
+
id (UUID): The unique identifier for the watchlist
|
335
|
+
name (str): An arbitrary string up to 64 characters identifying the watchlist
|
336
|
+
created_at (datetime): When the watchlist was created
|
337
|
+
updated_at (datetime): When the watchlist was last updated
|
338
|
+
assets (Optional[List[Asset]]): The assets in the watchlist, not returned from all endpoints
|
339
|
+
"""
|
340
|
+
|
341
|
+
account_id: UUID
|
342
|
+
name: str
|
343
|
+
created_at: datetime
|
344
|
+
updated_at: datetime
|
345
|
+
assets: Optional[List[Asset]] = None
|
346
|
+
|
347
|
+
|
348
|
+
class Clock(BaseModel):
|
349
|
+
"""
|
350
|
+
The market clock for US equity markets. Timestamps are in eastern time.
|
351
|
+
|
352
|
+
Attributes:
|
353
|
+
timestamp (datetime): The current timestamp.
|
354
|
+
is_open (bool): Whether the market is currently open.
|
355
|
+
next_open (datetime): The timestamp when the market will next open.
|
356
|
+
next_close (datetime): The timestamp when the market will next close.
|
357
|
+
"""
|
358
|
+
|
359
|
+
timestamp: datetime
|
360
|
+
is_open: bool
|
361
|
+
next_open: datetime
|
362
|
+
next_close: datetime
|
363
|
+
|
364
|
+
|
365
|
+
class Calendar(BaseModel):
|
366
|
+
"""
|
367
|
+
The market calendar for equity markets. Describes the market open and close time on a given day.
|
368
|
+
"""
|
369
|
+
|
370
|
+
date: date
|
371
|
+
open: datetime
|
372
|
+
close: datetime
|
373
|
+
|
374
|
+
def __init__(self, **data: Any) -> None:
|
375
|
+
"""
|
376
|
+
Converts open and close time strings from %H:%M to a datetime
|
377
|
+
Args:
|
378
|
+
**data: The raw calendar data from API
|
379
|
+
"""
|
380
|
+
if "date" in data and "open" in data:
|
381
|
+
start_datetime_str = data["date"] + " " + data["open"]
|
382
|
+
data["open"] = datetime.strptime(start_datetime_str, "%Y-%m-%d %H:%M")
|
383
|
+
|
384
|
+
if "date" in data and "close" in data:
|
385
|
+
start_datetime_str = data["date"] + " " + data["close"]
|
386
|
+
data["close"] = datetime.strptime(start_datetime_str, "%Y-%m-%d %H:%M")
|
387
|
+
|
388
|
+
super().__init__(**data)
|
389
|
+
|
390
|
+
|
391
|
+
class BaseActivity(BaseModel):
|
392
|
+
"""
|
393
|
+
Represents Base information for an event/activity for a specific Account.
|
394
|
+
|
395
|
+
You most likely will want an instance of one of the child classes TradeActivity and NonTradeActivity
|
396
|
+
|
397
|
+
Attributes:
|
398
|
+
id (str): Unique ID of this Activity. Note that IDs for Activity instances are formatted like
|
399
|
+
`20220203000000000::045b3b8d-c566-4bef-b741-2bf598dd6ae7` the first part before the `::` is a date string
|
400
|
+
while the part after is a UUID
|
401
|
+
account_id (UUID): id of the Account this activity relates too
|
402
|
+
activity_type (ActivityType): What specific kind of Activity this was
|
403
|
+
"""
|
404
|
+
|
405
|
+
id: str
|
406
|
+
account_id: UUID
|
407
|
+
activity_type: ActivityType
|
408
|
+
|
409
|
+
def __init__(self, *args, **data):
|
410
|
+
if "account_id" in data and type(data["account_id"]) == str:
|
411
|
+
data["account_id"] = UUID(data["account_id"])
|
412
|
+
|
413
|
+
super().__init__(*args, **data)
|
414
|
+
|
415
|
+
|
416
|
+
class NonTradeActivity(BaseActivity):
|
417
|
+
"""
|
418
|
+
A NonTradeActivity represents an Activity that happened for an account that doesn't have to do with orders or trades.
|
419
|
+
|
420
|
+
Attributes:
|
421
|
+
date (date): The date on which the activity occurred or on which the transaction associated with the
|
422
|
+
activity settled.
|
423
|
+
net_amount (float): The net amount of money (positive or negative) associated with the activity.
|
424
|
+
description (str): Extra description of the NTA if needed. Can be empty string ""
|
425
|
+
status (NonTradeActivityStatus): Status of the activity. Not present for all activity types.
|
426
|
+
symbol (Optional[str]): The symbol of the security involved with the activity. Not present for all activity
|
427
|
+
types.
|
428
|
+
qty (Optional[float]): For dividend activities, the number of shares that contributed to the payment. Not
|
429
|
+
present for other activity types.
|
430
|
+
price (Optional[float]) Not present for all activity types.
|
431
|
+
per_share_amount (Optional[float]): For dividend activities, the average amount paid per share. Not present for
|
432
|
+
other activity types.
|
433
|
+
"""
|
434
|
+
|
435
|
+
date: date
|
436
|
+
net_amount: float
|
437
|
+
description: str
|
438
|
+
status: Optional[NonTradeActivityStatus] = None
|
439
|
+
symbol: Optional[str] = None
|
440
|
+
qty: Optional[float] = None
|
441
|
+
price: Optional[float] = None
|
442
|
+
per_share_amount: Optional[float] = None
|
443
|
+
|
444
|
+
|
445
|
+
class TradeActivity(BaseActivity):
|
446
|
+
"""
|
447
|
+
Represents information for TradeActivities. TradeActivities are Activities that pertain to trades that happened for
|
448
|
+
an account. IE Fills or partial fills for orders.
|
449
|
+
|
450
|
+
Attributes:
|
451
|
+
transaction_time (datetime): The time and date of when this trade was processed
|
452
|
+
type (TradeActivityType): What kind of trade this TradeActivity represents. See TradeActivityType for more
|
453
|
+
details
|
454
|
+
price (float): The per-share price that the trade was executed at.
|
455
|
+
qty (float): The number of shares involved in the trade execution.
|
456
|
+
side (OrderSide): What side the trade this TradeActivity represents was on. See OrderSide for more information
|
457
|
+
symbol (str): The symbol of the asset that was traded
|
458
|
+
leaves_qty (float): For partially filled orders, the quantity of shares that are left to be filled. Will be 0 if
|
459
|
+
order was not a partially filled order
|
460
|
+
order_id (UUID): The ID for the order filled
|
461
|
+
cum_qty (float): The cumulative quantity of shares involved in the execution.
|
462
|
+
order_status (OrderStatus): The status of the order that executed the trade. See OrderStatus for more details
|
463
|
+
"""
|
464
|
+
|
465
|
+
transaction_time: datetime
|
466
|
+
type: TradeActivityType
|
467
|
+
price: float
|
468
|
+
qty: float
|
469
|
+
side: OrderSide
|
470
|
+
symbol: str
|
471
|
+
leaves_qty: float
|
472
|
+
order_id: UUID
|
473
|
+
cum_qty: float
|
474
|
+
order_status: OrderStatus
|
475
|
+
|
476
|
+
|
477
|
+
class TradeAccount(ModelWithID):
|
478
|
+
"""
|
479
|
+
Represents trading account information for an Account.
|
480
|
+
|
481
|
+
Attributes:
|
482
|
+
id (UUID): The account ID
|
483
|
+
account_number (str): The account number
|
484
|
+
status (AccountStatus): The current status of the account
|
485
|
+
crypto_status (Optional[AccountStatus]): The status of the account in regards to trading crypto. Only present if
|
486
|
+
crypto trading is enabled for your brokerage account.
|
487
|
+
currency (Optional[str]): Currently will always be the value "USD".
|
488
|
+
buying_power (Optional[str]): Current available cash buying power. If multiplier = 2 then
|
489
|
+
buying_power = max(equity-initial_margin(0) * 2). If multiplier = 1 then buying_power = cash.
|
490
|
+
regt_buying_power (Optional[str]): User’s buying power under Regulation T
|
491
|
+
(excess equity - (equity - margin value) - * margin multiplier)
|
492
|
+
daytrading_buying_power (Optional[str]): The buying power for day trades for the account
|
493
|
+
non_marginable_buying_power (Optional[str]): The non marginable buying power for the account
|
494
|
+
cash (Optional[str]): Cash balance in the account
|
495
|
+
accrued_fees (Optional[str]): Fees accrued in this account
|
496
|
+
pending_transfer_out (Optional[str]): Cash pending transfer out of this account
|
497
|
+
pending_transfer_in (Optional[str]): Cash pending transfer into this account
|
498
|
+
portfolio_value (str): Total value of cash + holding positions.
|
499
|
+
(This field is deprecated. It is equivalent to the equity field.)
|
500
|
+
pattern_day_trader (Optional[bool]): Whether the account is flagged as pattern day trader or not.
|
501
|
+
trading_blocked (Optional[bool]): If true, the account is not allowed to place orders.
|
502
|
+
transfers_blocked (Optional[bool]): If true, the account is not allowed to request money transfers.
|
503
|
+
account_blocked (Optional[bool]): If true, the account activity by user is prohibited.
|
504
|
+
created_at (Optional[datetime]): Timestamp this account was created at
|
505
|
+
trade_suspended_by_user (Optional[bool]): If true, the account is not allowed to place orders.
|
506
|
+
multiplier (Optional[str]): Multiplier value for this account.
|
507
|
+
shorting_enabled (Optional[bool]): Flag to denote whether or not the account is permitted to short
|
508
|
+
equity (Optional[str]): This value is cash + long_market_value + short_market_value. This value isn't calculated in the
|
509
|
+
SDK it is computed on the server and we return the raw value here.
|
510
|
+
last_equity (Optional[str]): Equity as of previous trading day at 16:00:00 ET
|
511
|
+
long_market_value (Optional[str]): Real-time MtM value of all long positions held in the account
|
512
|
+
short_market_value (Optional[str]): Real-time MtM value of all short positions held in the account
|
513
|
+
initial_margin (Optional[str]): Reg T initial margin requirement
|
514
|
+
maintenance_margin (Optional[str]): Maintenance margin requirement
|
515
|
+
last_maintenance_margin (Optional[str]): Maintenance margin requirement on the previous trading day
|
516
|
+
sma (Optional[str]): Value of Special Memorandum Account (will be used at a later date to provide additional buying_power)
|
517
|
+
daytrade_count (Optional[int]): The current number of daytrades that have been made in the last 5 trading days
|
518
|
+
(inclusive of today)
|
519
|
+
options_buying_power (Optional[str]): Your buying power for options trading
|
520
|
+
options_approved_level (Optional[int]): The options trading level that was approved for this account.
|
521
|
+
0=disabled, 1=Covered Call/Cash-Secured Put, 2=Long Call/Put, 3=Spreads/Straddles.
|
522
|
+
options_trading_level (Optional[int]): The effective options trading level of the account. This is the minimum between account options_approved_level and account configurations max_options_trading_level.
|
523
|
+
0=disabled, 1=Covered Call/Cash-Secured Put, 2=Long, 3=Spreads/Straddles.
|
524
|
+
"""
|
525
|
+
|
526
|
+
account_number: str
|
527
|
+
status: AccountStatus
|
528
|
+
crypto_status: Optional[AccountStatus] = None
|
529
|
+
currency: Optional[str] = None
|
530
|
+
buying_power: Optional[str] = None
|
531
|
+
regt_buying_power: Optional[str] = None
|
532
|
+
daytrading_buying_power: Optional[str] = None
|
533
|
+
non_marginable_buying_power: Optional[str] = None
|
534
|
+
cash: Optional[str] = None
|
535
|
+
accrued_fees: Optional[str] = None
|
536
|
+
pending_transfer_out: Optional[str] = None
|
537
|
+
pending_transfer_in: Optional[str] = None
|
538
|
+
portfolio_value: Optional[str] = None
|
539
|
+
pattern_day_trader: Optional[bool] = None
|
540
|
+
trading_blocked: Optional[bool] = None
|
541
|
+
transfers_blocked: Optional[bool] = None
|
542
|
+
account_blocked: Optional[bool] = None
|
543
|
+
created_at: Optional[datetime] = None
|
544
|
+
trade_suspended_by_user: Optional[bool] = None
|
545
|
+
multiplier: Optional[str] = None
|
546
|
+
shorting_enabled: Optional[bool] = None
|
547
|
+
equity: Optional[str] = None
|
548
|
+
last_equity: Optional[str] = None
|
549
|
+
long_market_value: Optional[str] = None
|
550
|
+
short_market_value: Optional[str] = None
|
551
|
+
initial_margin: Optional[str] = None
|
552
|
+
maintenance_margin: Optional[str] = None
|
553
|
+
last_maintenance_margin: Optional[str] = None
|
554
|
+
sma: Optional[str] = None
|
555
|
+
daytrade_count: Optional[int] = None
|
556
|
+
options_buying_power: Optional[str] = None
|
557
|
+
options_approved_level: Optional[int] = None
|
558
|
+
options_trading_level: Optional[int] = None
|
559
|
+
|
560
|
+
|
561
|
+
class AccountConfiguration(BaseModel):
|
562
|
+
"""
|
563
|
+
Represents configuration options for a TradeAccount.
|
564
|
+
|
565
|
+
Attributes:
|
566
|
+
dtbp_check (DTBPCheck): Day Trade Buying Power Check. Controls Day Trading Margin Call (DTMC) checks.
|
567
|
+
fractional_trading (bool): If true, account is able to participate in fractional trading
|
568
|
+
max_margin_multiplier (str): A number between 1-4 that represents your max margin multiplier
|
569
|
+
no_shorting (bool): If true then Account becomes long-only mode.
|
570
|
+
pdt_check (PDTCheck): Controls Pattern Day Trader (PDT) checks.
|
571
|
+
suspend_trade (bool): If true Account becomes unable to submit new orders
|
572
|
+
trade_confirm_email (TradeConfirmationEmail): Controls whether Trade confirmation emails are sent.
|
573
|
+
ptp_no_exception_entry (bool): If set to true then Alpaca will accept orders for PTP symbols with no exception. Default is false.
|
574
|
+
max_options_trading_level (Optional[int]): The desired maximum options trading level. 0=disabled, 1=Covered Call/Cash-Secured Put, 2=Long Call/Put, 3=Spreads/Straddles.
|
575
|
+
"""
|
576
|
+
|
577
|
+
dtbp_check: DTBPCheck
|
578
|
+
fractional_trading: bool
|
579
|
+
max_margin_multiplier: str
|
580
|
+
no_shorting: bool
|
581
|
+
pdt_check: PDTCheck
|
582
|
+
suspend_trade: bool
|
583
|
+
trade_confirm_email: TradeConfirmationEmail
|
584
|
+
ptp_no_exception_entry: bool
|
585
|
+
max_options_trading_level: Optional[int] = None
|
586
|
+
|
587
|
+
|
588
|
+
class CorporateActionAnnouncement(ModelWithID):
|
589
|
+
"""
|
590
|
+
An announcement of a corporate action. Corporate actions are events like dividend payouts, mergers and stock splits.
|
591
|
+
|
592
|
+
Attributes:
|
593
|
+
id (UUID): The unique identifier for this single announcement.
|
594
|
+
corporate_action_id (str): ID that remains consistent across all announcements for the same corporate action.
|
595
|
+
ca_type (CorporateActionType): The type of corporate action that was announced.
|
596
|
+
ca_sub_type (CorporateActionSubType): The specific subtype of corporate action that was announced.
|
597
|
+
initiating_symbol (str): Symbol of the company initiating the announcement.
|
598
|
+
initiating_original_cusip (str): CUSIP of the company initiating the announcement.
|
599
|
+
target_symbol (Optional[str]): Symbol of the child company involved in the announcement.
|
600
|
+
target_original_cusip (Optional[str]): CUSIP of the child company involved in the announcement.
|
601
|
+
declaration_date (Optional[date]): Date the corporate action or subsequent terms update was announced.
|
602
|
+
ex_date (Optional[date]): The first date that purchasing a security will not result in a corporate action entitlement.
|
603
|
+
record_date (Optional[date]): The date an account must hold a settled position in the security in order to receive the
|
604
|
+
corporate action entitlement.
|
605
|
+
payable_date (Optional[date]): The date the announcement will take effect. On this date, account stock and cash
|
606
|
+
balances are expected to be processed accordingly.
|
607
|
+
cash (float): The amount of cash to be paid per share held by an account on the record date.
|
608
|
+
old_rate (float): The denominator to determine any quantity change ratios in positions.
|
609
|
+
new_rate (float): The numerator to determine any quantity change ratios in positions.
|
610
|
+
"""
|
611
|
+
|
612
|
+
corporate_action_id: str
|
613
|
+
ca_type: CorporateActionType
|
614
|
+
ca_sub_type: CorporateActionSubType
|
615
|
+
initiating_symbol: str
|
616
|
+
initiating_original_cusip: str
|
617
|
+
target_symbol: Optional[str] = None
|
618
|
+
target_original_cusip: Optional[str] = None
|
619
|
+
declaration_date: Optional[date] = None
|
620
|
+
ex_date: Optional[date] = None
|
621
|
+
record_date: Optional[date] = None
|
622
|
+
payable_date: Optional[date] = None
|
623
|
+
cash: float
|
624
|
+
old_rate: float
|
625
|
+
new_rate: float
|
626
|
+
|
627
|
+
|
628
|
+
class TradeUpdate(BaseModel):
|
629
|
+
"""
|
630
|
+
Represents a trade update.
|
631
|
+
|
632
|
+
ref. https://docs.alpaca.markets/docs/websocket-streaming#example
|
633
|
+
"""
|
634
|
+
|
635
|
+
event: Union[TradeEvent, str]
|
636
|
+
execution_id: Optional[UUID] = None
|
637
|
+
order: Order
|
638
|
+
timestamp: datetime
|
639
|
+
position_qty: Optional[float] = None
|
640
|
+
price: Optional[float] = None
|
641
|
+
qty: Optional[float] = None
|
642
|
+
|
643
|
+
|
644
|
+
class OptionContract(BaseModel):
|
645
|
+
"""
|
646
|
+
Represents an option contract.
|
647
|
+
|
648
|
+
Attributes:
|
649
|
+
id (str): The unique identifier of the option contract.
|
650
|
+
symbol (str): The symbol representing the option contract.
|
651
|
+
name (str): The name of the option contract.
|
652
|
+
status (AssetStatus): The status of the option contract.
|
653
|
+
tradable (bool): Indicates whether the option contract is tradable.
|
654
|
+
expiration_date (date): The expiration date of the option contract.
|
655
|
+
root_symbol (str): The root symbol of the option contract.
|
656
|
+
underlying_symbol (str): The underlying symbol of the option contract.
|
657
|
+
underlying_asset_id (UUID): The unique identifier of the underlying asset.
|
658
|
+
type (ContractType): The type of the option contract.
|
659
|
+
style (ExerciseStyle): The style of the option contract.
|
660
|
+
strike_price (float): The strike price of the option contract.
|
661
|
+
size (str): The size of the option contract. Usually contracts have size=100.
|
662
|
+
open_interest (Optional[str]): The open interest of the option contract.
|
663
|
+
open_interest_date (Optional[date]): The date of the open interest data.
|
664
|
+
close_price (Optional[str]): The close price of the option contract.
|
665
|
+
close_price_date (Optional[date]): The date of the close price data.
|
666
|
+
"""
|
667
|
+
|
668
|
+
id: str
|
669
|
+
symbol: str
|
670
|
+
name: str
|
671
|
+
status: AssetStatus
|
672
|
+
tradable: bool
|
673
|
+
expiration_date: date
|
674
|
+
root_symbol: str
|
675
|
+
underlying_symbol: str
|
676
|
+
underlying_asset_id: UUID
|
677
|
+
type: ContractType
|
678
|
+
style: ExerciseStyle
|
679
|
+
strike_price: float
|
680
|
+
size: str
|
681
|
+
open_interest: Optional[str] = None
|
682
|
+
open_interest_date: Optional[date] = None
|
683
|
+
close_price: Optional[str] = None
|
684
|
+
close_price_date: Optional[date] = None
|
685
|
+
|
686
|
+
|
687
|
+
class OptionContractsResponse(BaseModel):
|
688
|
+
"""
|
689
|
+
Represents a response from the option contracts endpoint.
|
690
|
+
|
691
|
+
Attributes:
|
692
|
+
option_contracts (Optional[List[OptionContract]]): The list of option contracts.
|
693
|
+
next_page_token (Optional[str]): Pagination token for next page.
|
694
|
+
"""
|
695
|
+
|
696
|
+
option_contracts: Optional[List[OptionContract]] = None
|
697
|
+
next_page_token: Optional[str] = None
|