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.
Files changed (62) hide show
  1. alpaca/__init__.py +2 -0
  2. alpaca/broker/__init__.py +8 -0
  3. alpaca/broker/client.py +2360 -0
  4. alpaca/broker/enums.py +528 -0
  5. alpaca/broker/models/__init__.py +7 -0
  6. alpaca/broker/models/accounts.py +347 -0
  7. alpaca/broker/models/cip.py +265 -0
  8. alpaca/broker/models/documents.py +159 -0
  9. alpaca/broker/models/funding.py +114 -0
  10. alpaca/broker/models/journals.py +71 -0
  11. alpaca/broker/models/rebalancing.py +80 -0
  12. alpaca/broker/models/trading.py +13 -0
  13. alpaca/broker/requests.py +1135 -0
  14. alpaca/common/__init__.py +6 -0
  15. alpaca/common/constants.py +13 -0
  16. alpaca/common/enums.py +64 -0
  17. alpaca/common/exceptions.py +47 -0
  18. alpaca/common/models.py +21 -0
  19. alpaca/common/requests.py +82 -0
  20. alpaca/common/rest.py +438 -0
  21. alpaca/common/types.py +7 -0
  22. alpaca/common/utils.py +89 -0
  23. alpaca/data/__init__.py +5 -0
  24. alpaca/data/enums.py +184 -0
  25. alpaca/data/historical/__init__.py +13 -0
  26. alpaca/data/historical/corporate_actions.py +76 -0
  27. alpaca/data/historical/crypto.py +299 -0
  28. alpaca/data/historical/news.py +63 -0
  29. alpaca/data/historical/option.py +230 -0
  30. alpaca/data/historical/screener.py +72 -0
  31. alpaca/data/historical/stock.py +226 -0
  32. alpaca/data/historical/utils.py +30 -0
  33. alpaca/data/live/__init__.py +11 -0
  34. alpaca/data/live/crypto.py +168 -0
  35. alpaca/data/live/news.py +62 -0
  36. alpaca/data/live/option.py +88 -0
  37. alpaca/data/live/stock.py +199 -0
  38. alpaca/data/live/websocket.py +390 -0
  39. alpaca/data/mappings.py +84 -0
  40. alpaca/data/models/__init__.py +7 -0
  41. alpaca/data/models/bars.py +83 -0
  42. alpaca/data/models/base.py +45 -0
  43. alpaca/data/models/corporate_actions.py +309 -0
  44. alpaca/data/models/news.py +90 -0
  45. alpaca/data/models/orderbooks.py +59 -0
  46. alpaca/data/models/quotes.py +78 -0
  47. alpaca/data/models/screener.py +68 -0
  48. alpaca/data/models/snapshots.py +132 -0
  49. alpaca/data/models/trades.py +204 -0
  50. alpaca/data/requests.py +580 -0
  51. alpaca/data/timeframe.py +148 -0
  52. alpaca/py.typed +0 -0
  53. alpaca/trading/__init__.py +5 -0
  54. alpaca/trading/client.py +784 -0
  55. alpaca/trading/enums.py +412 -0
  56. alpaca/trading/models.py +697 -0
  57. alpaca/trading/requests.py +604 -0
  58. alpaca/trading/stream.py +225 -0
  59. alpaca_py_nopandas-0.1.0.dist-info/LICENSE +201 -0
  60. alpaca_py_nopandas-0.1.0.dist-info/METADATA +299 -0
  61. alpaca_py_nopandas-0.1.0.dist-info/RECORD +62 -0
  62. alpaca_py_nopandas-0.1.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,604 @@
1
+ from datetime import date, datetime, timedelta
2
+ from typing import Any, Dict, List, Optional, Union
3
+
4
+ from pydantic import model_validator
5
+
6
+ from alpaca.common.enums import Sort
7
+ from alpaca.common.models import ModelWithID
8
+ from alpaca.common.requests import NonEmptyRequest
9
+ from alpaca.trading.enums import (
10
+ AssetClass,
11
+ AssetExchange,
12
+ AssetStatus,
13
+ ContractType,
14
+ CorporateActionDateType,
15
+ CorporateActionType,
16
+ ExerciseStyle,
17
+ OrderClass,
18
+ OrderSide,
19
+ OrderType,
20
+ PositionIntent,
21
+ QueryOrderStatus,
22
+ TimeInForce,
23
+ )
24
+
25
+
26
+ class ClosePositionRequest(NonEmptyRequest):
27
+ """
28
+ Attributes:
29
+ qty (str): The number of shares to liquidate.
30
+ percentage (str): The percentage of shares to liquidate.
31
+ """
32
+
33
+ qty: Optional[str] = None
34
+ percentage: Optional[str] = None
35
+
36
+ @model_validator(mode="before")
37
+ def root_validator(cls, values: dict) -> dict:
38
+ qty = values.get("qty", None)
39
+ percentage = values.get("percentage", None)
40
+ if qty is None and percentage is None:
41
+ raise ValueError(
42
+ "qty or percentage must be given to the ClosePositionRequest, got None for both."
43
+ )
44
+
45
+ if qty is not None and percentage is not None:
46
+ raise ValueError(
47
+ "Only one of qty or percentage must be given to the ClosePositionRequest, got both."
48
+ )
49
+
50
+ return values
51
+
52
+
53
+ class GetPortfolioHistoryRequest(NonEmptyRequest):
54
+ """
55
+ Attributes:
56
+ period (Optional[str]): The duration of the data in number + unit, such as 1D. unit can be D for day, W for
57
+ week, M for month and A for year. Defaults to 1M.
58
+ timeframe (Optional[str]): The resolution of time window. 1Min, 5Min, 15Min, 1H, or 1D. If omitted, 1Min for
59
+ less than 7 days period, 15Min for less than 30 days, or otherwise 1D.
60
+ intraday_reporting (Optional[str]): this specfies which timestamps to return data points
61
+ start (Optional[datetime]): The timestamp the data is returned starting from in RFC3339 format (including timezone specification).
62
+ pnl_reset (Optional[str]): efines how we are calculating the baseline values for Profit And Loss (pnl) for queries with timeframe less than 1D (intraday queries).
63
+ end (Optional[datetime]): The timestamp the data is returned up to in RFC3339 format (including timezone specification).
64
+ date_end (Optional[date]): The date the data is returned up to. Defaults to the current market date (rolls over
65
+ at the market open if extended_hours is false, otherwise at 7am ET).
66
+ extended_hours (Optional[bool]): If true, include extended hours in the result. This is effective only for
67
+ timeframe less than 1D.
68
+ cashflow_types (Optional[str]): The cashflow activities to include in the report
69
+ """
70
+
71
+ period: Optional[str] = None
72
+ timeframe: Optional[str] = None
73
+ intraday_reporting: Optional[str] = None
74
+ start: Optional[datetime] = None
75
+ pnl_reset: Optional[str] = None
76
+ end: Optional[datetime] = None
77
+ date_end: Optional[date] = None
78
+ extended_hours: Optional[bool] = None
79
+ cashflow_types: Optional[str] = None
80
+
81
+
82
+ class GetCalendarRequest(NonEmptyRequest):
83
+ """
84
+ Represents the optional filtering you can do when requesting a Calendar object
85
+ """
86
+
87
+ start: Optional[date] = None
88
+ end: Optional[date] = None
89
+
90
+
91
+ class CreateWatchlistRequest(NonEmptyRequest):
92
+ """
93
+ Represents the fields you can specify when creating a Watchlist
94
+
95
+ Attributes:
96
+ name(str): Name of the Watchlist
97
+ symbols(List[str]): Symbols of Assets to watch
98
+ """
99
+
100
+ name: str
101
+ symbols: List[str]
102
+
103
+
104
+ class UpdateWatchlistRequest(NonEmptyRequest):
105
+ """
106
+ Represents the fields you can specify when updating a Watchlist
107
+
108
+ Attributes:
109
+ name(Optional[str]): Name of the Watchlist
110
+ symbols(Optional[List[str]]): Symbols of Assets to watch
111
+ """
112
+
113
+ name: Optional[str] = None
114
+ symbols: Optional[List[str]] = None
115
+
116
+ @model_validator(mode="before")
117
+ def root_validator(cls, values: dict) -> dict:
118
+ if ("name" not in values or values["name"] is None) and (
119
+ "symbols" not in values or values["symbols"] is None
120
+ ):
121
+ raise ValueError("One of 'name' or 'symbols' must be defined")
122
+
123
+ return values
124
+
125
+
126
+ class GetAssetsRequest(NonEmptyRequest):
127
+ """
128
+ When querying for available assets, this model provides the parameters that can be filtered by.
129
+
130
+ Attributes:
131
+ status (Optional[AssetStatus]): The active status of the asset.
132
+ asset_class (Optional[AssetClass]): The type of asset (i.e. us_equity, crypto).
133
+ exchange (Optional[AssetExchange]): The exchange the asset trades on.
134
+ attributes (Optional[str]): Comma separated values to query for more than one attribute.
135
+ """
136
+
137
+ status: Optional[AssetStatus] = None
138
+ asset_class: Optional[AssetClass] = None
139
+ exchange: Optional[AssetExchange] = None
140
+ attributes: Optional[str] = None
141
+
142
+
143
+ class TakeProfitRequest(NonEmptyRequest):
144
+ """
145
+ Used for providing take profit details for a bracket order.
146
+
147
+ Attributes:
148
+ limit_price (float): The execution price for exiting a profitable trade.
149
+ """
150
+
151
+ limit_price: float
152
+
153
+
154
+ class StopLossRequest(NonEmptyRequest):
155
+ """
156
+ Used for providing stop loss details for a bracket order.
157
+
158
+ Attributes:
159
+ stop_price (float): The price at which the stop loss is triggered.
160
+ limit_price (Optional[float]): The execution price for exiting a losing trade. If not provided, the
161
+ stop loss will execute as a market order.
162
+ """
163
+
164
+ stop_price: float
165
+ limit_price: Optional[float] = None
166
+
167
+
168
+ class OptionLegRequest(NonEmptyRequest):
169
+ """
170
+ Used for providing details for a leg of a multi-leg order.
171
+
172
+ Attributes:
173
+ symbol (str): The symbol identifier for the asset being traded.
174
+ ratio_qty (float): The proportional quantity of this leg in relation to the overall multi-leg order quantity.
175
+ side (Optional[OrderSide]): Represents the side this order was on.
176
+ position_intent (Optional[PositionIntent]): Represents the position strategy for this leg.
177
+ """
178
+
179
+ symbol: str
180
+ ratio_qty: float
181
+ side: Optional[OrderSide] = None
182
+ position_intent: Optional[PositionIntent] = None
183
+
184
+ @model_validator(mode="before")
185
+ def root_validator(cls, values: dict) -> dict:
186
+ side = values.get("side", None)
187
+ position_intent = values.get("position_intent", None)
188
+
189
+ if side is None and position_intent is None:
190
+ raise ValueError(
191
+ "at least one of side or position_intent must be provided for OptionLegRequest"
192
+ )
193
+
194
+ return values
195
+
196
+
197
+ class GetOrdersRequest(NonEmptyRequest):
198
+ """Contains data for submitting a request to retrieve orders.
199
+
200
+ Attributes:
201
+ status (Optional[QueryOrderStatus]): Order status to be queried. open, closed or all. Defaults to open. Not same as OrderStatus property of Order.
202
+ limit (Optional[int]): The maximum number of orders in response. Defaults to 50 and max is 500.
203
+ after (Optional[datetime]): The response will include only ones submitted after this timestamp.
204
+ until (Optional[datetime]): The response will include only ones submitted until this timestamp.
205
+ direction (Optional[Sort]): The chronological order of response based on the submission time. asc or desc. Defaults to desc.
206
+ nested (Optional[bool]): If true, the result will roll up multi-leg orders under the legs field of primary order.
207
+ side (Optional[OrderSide]): Filters down to orders that have a matching side field set.
208
+ symbols (Optional[List[str]]): List of symbols to filter by.
209
+ """
210
+
211
+ status: Optional[QueryOrderStatus] = None
212
+ limit: Optional[int] = None # not pagination = None
213
+ after: Optional[datetime] = None
214
+ until: Optional[datetime] = None
215
+ direction: Optional[Sort] = None
216
+ nested: Optional[bool] = None
217
+ side: Optional[OrderSide] = None
218
+ symbols: Optional[List[str]] = None
219
+
220
+
221
+ class GetOrderByIdRequest(NonEmptyRequest):
222
+ """Contains data for submitting a request to retrieve a single order by its order id.
223
+
224
+ Attributes:
225
+ nested (bool): If true, the result will roll up multi-leg orders under the legs field of primary order.
226
+ """
227
+
228
+ nested: bool
229
+
230
+
231
+ class ReplaceOrderRequest(NonEmptyRequest):
232
+ """Contains data for submitting a request to replace an order.
233
+
234
+ Attributes:
235
+ qty (Optional[int]): Number of shares to trade
236
+ time_in_force (Optional[TimeInForce]): The new expiration logic of the order.
237
+ limit_price (Optional[float]): Required if type of order being replaced is limit or stop_limit
238
+ stop_price (Optional[float]): Required if type of order being replaced is stop or stop_limit
239
+ trail (Optional[float]): The new value of the trail_price or trail_percent value (works only for type=“trailing_stop”)
240
+ client_order_id (Optional[str]): A unique identifier for the order.
241
+ """
242
+
243
+ qty: Optional[int] = None
244
+ time_in_force: Optional[TimeInForce] = None
245
+ limit_price: Optional[float] = None
246
+ stop_price: Optional[float] = None
247
+ trail: Optional[float] = None
248
+ client_order_id: Optional[str] = None
249
+
250
+ @model_validator(mode="before")
251
+ def root_validator(cls, values: dict) -> dict:
252
+ qty = values.get("qty", None)
253
+ limit_price = values.get("limit_price", None)
254
+ stop_price = values.get("stop_price", None)
255
+ trail = values.get("trail", None)
256
+
257
+ if (qty is not None) and (qty <= 0):
258
+ raise ValueError("qty must be greater than 0")
259
+ if (limit_price is not None) and (limit_price <= 0):
260
+ raise ValueError("limit_price must be greater than 0")
261
+ if (stop_price is not None) and (stop_price <= 0):
262
+ raise ValueError("stop_price must be greater than 0")
263
+ if (trail is not None) and (trail <= 0):
264
+ raise ValueError("trail must be greater than 0")
265
+
266
+ return values
267
+
268
+
269
+ class CancelOrderResponse(ModelWithID):
270
+ """
271
+ Data returned after requesting to cancel an order. It contains the cancel status of an order.
272
+
273
+ Attributes:
274
+ id (UUID): The order id
275
+ status (int): The HTTP status returned after attempting to cancel the order.
276
+ body (Dict[str, Any]): an error description
277
+ """
278
+
279
+ status: int
280
+ body: Optional[Dict[str, Any]] = None
281
+
282
+
283
+ class OrderRequest(NonEmptyRequest):
284
+ """A base class for requests for creating an order. You probably shouldn't directly use
285
+ this class when submitting an order. Instead, use one of the order type specific classes.
286
+
287
+ Attributes:
288
+ symbol (str): The symbol identifier for the asset being traded. Required for all order classes other than
289
+ mleg.
290
+ qty (Optional[float]): The number of shares to trade. Fractional qty for stocks only with market orders.
291
+ Required for mleg order class.
292
+ notional (Optional[float]): The base currency value of the shares to trade. For stocks, only works with MarketOrders.
293
+ **Does not work with qty**.
294
+ side (Optional[OrderSide]): Whether the order will buy or sell the asset. Either side or position_intent is required for all order classes other than mleg.
295
+ type (OrderType): The execution logic type of the order (market, limit, etc).
296
+ time_in_force (TimeInForce): The expiration logic of the order.
297
+ extended_hours (Optional[float]): Whether the order can be executed during regular market hours.
298
+ client_order_id (Optional[str]): A string to identify which client submitted the order.
299
+ order_class (Optional[OrderClass]): The class of the order. Simple orders have no other legs.
300
+ legs (Optional[List[OptionLegRequest]]): For multi-leg option orders, the legs of the order If specified (must contain at least 2 but no more than 4 legs for options).
301
+ Otherwise, for equities, a list of individual orders.
302
+ take_profit (Optional[TakeProfitRequest]): For orders with multiple legs, an order to exit a profitable trade.
303
+ stop_loss (Optional[StopLossRequest]): For orders with multiple legs, an order to exit a losing trade.
304
+ position_intent (Optional[PositionIntent]): An enum to indicate the desired position strategy: BTO, BTC, STO, STC.
305
+ """
306
+
307
+ symbol: Optional[str] = None
308
+ qty: Optional[float] = None
309
+ notional: Optional[float] = None
310
+ side: Optional[OrderSide] = None
311
+ type: OrderType
312
+ time_in_force: TimeInForce
313
+ order_class: Optional[OrderClass] = None
314
+ extended_hours: Optional[bool] = None
315
+ client_order_id: Optional[str] = None
316
+ legs: Optional[List[OptionLegRequest]] = None
317
+ take_profit: Optional[TakeProfitRequest] = None
318
+ stop_loss: Optional[StopLossRequest] = None
319
+ position_intent: Optional[PositionIntent] = None
320
+
321
+ @model_validator(mode="before")
322
+ def root_validator(cls, values: dict) -> dict:
323
+ qty_set = "qty" in values and values["qty"] is not None
324
+ notional_set = "notional" in values and values["notional"] is not None
325
+
326
+ if not qty_set and not notional_set:
327
+ raise ValueError("At least one of qty or notional must be provided")
328
+ elif qty_set and notional_set:
329
+ raise ValueError("Both qty and notional can not be set.")
330
+
331
+ # mleg-related checks
332
+ if "order_class" in values and values["order_class"] == OrderClass.MLEG:
333
+ if not qty_set:
334
+ raise ValueError("qty is required for the mleg order class.")
335
+ if "legs" not in values or values["legs"] is None:
336
+ raise ValueError("legs is required for the mleg order class.")
337
+ l_len = len(values["legs"])
338
+ if l_len > 4:
339
+ raise ValueError("At most 4 legs are allowed for the mleg order class.")
340
+ if l_len < 2:
341
+ raise ValueError(
342
+ "At least 2 legs are required for the mleg order class."
343
+ )
344
+ n_unique = len(set([l.symbol for l in values["legs"]]))
345
+ if n_unique != l_len:
346
+ raise ValueError("All legs must have unique symbols.")
347
+ else:
348
+ if "symbol" not in values or values["symbol"] is None:
349
+ raise ValueError(
350
+ "symbol is required for all order classes other than mleg."
351
+ )
352
+ if "side" not in values or values["side"] is None:
353
+ raise ValueError(
354
+ "side is required for all order classes other than mleg."
355
+ )
356
+
357
+ return values
358
+
359
+
360
+ class MarketOrderRequest(OrderRequest):
361
+ """
362
+ Used to submit a market order.
363
+
364
+ Attributes:
365
+ symbol (str): The symbol identifier for the asset being traded. Required for all order classes other than
366
+ mleg.
367
+ qty (Optional[float]): The number of shares to trade. Fractional qty for stocks only with market orders.
368
+ notional (Optional[float]): The base currency value of the shares to trade. For stocks, only works with MarketOrders.
369
+ **Does not work with qty**.
370
+ side (OrderSide): Whether the order will buy or sell the asset. Required for all order classes other than mleg.
371
+ type (OrderType): The execution logic type of the order (market, limit, etc).
372
+ time_in_force (TimeInForce): The expiration logic of the order.
373
+ extended_hours (Optional[float]): Whether the order can be executed during regular market hours.
374
+ client_order_id (Optional[str]): A string to identify which client submitted the order.
375
+ order_class (Optional[OrderClass]): The class of the order. Simple orders have no other legs.
376
+ legs (Optional[List[OptionLegRequest]]): For multi-leg option orders, the legs of the order. At most 4 legs are allowed for options.
377
+ take_profit (Optional[TakeProfitRequest]): For orders with multiple legs, an order to exit a profitable trade.
378
+ stop_loss (Optional[StopLossRequest]): For orders with multiple legs, an order to exit a losing trade.
379
+ position_intent (Optional[PositionIntent]): An enum to indicate the desired position strategy: BTO, BTC, STO, STC.
380
+ """
381
+
382
+ def __init__(self, **data: Any) -> None:
383
+ data["type"] = OrderType.MARKET
384
+
385
+ super().__init__(**data)
386
+
387
+
388
+ class StopOrderRequest(OrderRequest):
389
+ """
390
+ Used to submit a stop order.
391
+
392
+ Attributes:
393
+ symbol (str): The symbol identifier for the asset being traded
394
+ qty (Optional[float]): The number of shares to trade. Fractional qty for stocks only with market orders.
395
+ notional (Optional[float]): The base currency value of the shares to trade. For stocks, only works with MarketOrders.
396
+ **Does not work with qty**.
397
+ side (OrderSide): Whether the order will buy or sell the asset.
398
+ type (OrderType): The execution logic type of the order (market, limit, etc).
399
+ time_in_force (TimeInForce): The expiration logic of the order.
400
+ extended_hours (Optional[float]): Whether the order can be executed during regular market hours.
401
+ client_order_id (Optional[str]): A string to identify which client submitted the order.
402
+ order_class (Optional[OrderClass]): The class of the order. Simple orders have no other legs.
403
+ legs (Optional[List[OptionLegRequest]]): For multi-leg option orders, the legs of the order. At most 4 legs are allowed for options.
404
+ take_profit (Optional[TakeProfitRequest]): For orders with multiple legs, an order to exit a profitable trade.
405
+ stop_loss (Optional[StopLossRequest]): For orders with multiple legs, an order to exit a losing trade.
406
+ stop_price (float): The price at which the stop order is converted to a market order or a stop limit
407
+ order is converted to a limit order.
408
+ position_intent (Optional[PositionIntent]): An enum to indicate the desired position strategy: BTO, BTC, STO, STC.
409
+ """
410
+
411
+ stop_price: float
412
+
413
+ def __init__(self, **data: Any) -> None:
414
+ data["type"] = OrderType.STOP
415
+
416
+ super().__init__(**data)
417
+
418
+
419
+ class LimitOrderRequest(OrderRequest):
420
+ """
421
+ Used to submit a limit order.
422
+
423
+ Attributes:
424
+ symbol (str): The symbol identifier for the asset being traded
425
+ qty (Optional[float]): The number of shares to trade. Fractional qty for stocks only with market orders.
426
+ notional (Optional[float]): The base currency value of the shares to trade. For stocks, only works with MarketOrders.
427
+ **Does not work with qty**.
428
+ side (OrderSide): Whether the order will buy or sell the asset.
429
+ type (OrderType): The execution logic type of the order (market, limit, etc).
430
+ time_in_force (TimeInForce): The expiration logic of the order.
431
+ extended_hours (Optional[float]): Whether the order can be executed during regular market hours.
432
+ client_order_id (Optional[str]): A string to identify which client submitted the order.
433
+ order_class (Optional[OrderClass]): The class of the order. Simple orders have no other legs.
434
+ legs (Optional[List[OptionLegRequest]]): For multi-leg option orders, the legs of the order. At most 4 legs are allowed for options.
435
+ take_profit (Optional[TakeProfitRequest]): For orders with multiple legs, an order to exit a profitable trade.
436
+ stop_loss (Optional[StopLossRequest]): For orders with multiple legs, an order to exit a losing trade.
437
+ limit_price (Optional[float]): The worst fill price for a limit or stop limit order. For the mleg order class, this
438
+ is specified such that a positive value indicates a debit (representing a cost or payment to be made) while a
439
+ negative value signifies a credit (reflecting an amount to be received).
440
+ position_intent (Optional[PositionIntent]): An enum to indicate the desired position strategy: BTO, BTC, STO, STC.
441
+ """
442
+
443
+ limit_price: Optional[float] = None
444
+
445
+ def __init__(self, **data: Any) -> None:
446
+ data["type"] = OrderType.LIMIT
447
+
448
+ super().__init__(**data)
449
+
450
+ @model_validator(mode="before")
451
+ def root_validator(cls, values: dict) -> dict:
452
+ # noinspection PyCallingNonCallable
453
+ super().root_validator(values)
454
+ if values.get("order_class", "") != OrderClass.OCO:
455
+ limit_price = values.get("limit_price", None)
456
+ if limit_price is None:
457
+ raise ValueError("limit_price is required")
458
+ return values
459
+
460
+
461
+ class StopLimitOrderRequest(OrderRequest):
462
+ """
463
+ Used to submit a stop limit order.
464
+
465
+ Attributes:
466
+ symbol (str): The symbol identifier for the asset being traded
467
+ qty (Optional[float]): The number of shares to trade. Fractional qty for stocks only with market orders.
468
+ notional (Optional[float]): The base currency value of the shares to trade. For stocks, only works with MarketOrders.
469
+ **Does not work with qty**.
470
+ side (OrderSide): Whether the order will buy or sell the asset.
471
+ type (OrderType): The execution logic type of the order (market, limit, etc).
472
+ time_in_force (TimeInForce): The expiration logic of the order.
473
+ extended_hours (Optional[float]): Whether the order can be executed during regular market hours.
474
+ client_order_id (Optional[str]): A string to identify which client submitted the order.
475
+ order_class (Optional[OrderClass]): The class of the order. Simple orders have no other legs.
476
+ legs (Optional[List[OptionLegRequest]]): For multi-leg option orders, the legs of the order. At most 4 legs are allowed for options.
477
+ take_profit (Optional[TakeProfitRequest]): For orders with multiple legs, an order to exit a profitable trade.
478
+ stop_loss (Optional[StopLossRequest]): For orders with multiple legs, an order to exit a losing trade.
479
+ stop_price (float): The price at which the stop order is converted to a market order or a stop limit
480
+ order is converted to a limit order.
481
+ limit_price (float): The worst fill price for a limit or stop limit order. For the mleg order class, this
482
+ is specified such that a positive value indicates a debit (representing a cost or payment to be made) while a
483
+ negative value signifies a credit (reflecting an amount to be received).
484
+ position_intent (Optional[PositionIntent]): An enum to indicate the desired position strategy: BTO, BTC, STO, STC.
485
+ """
486
+
487
+ stop_price: float
488
+ limit_price: float
489
+
490
+ def __init__(self, **data: Any) -> None:
491
+ data["type"] = OrderType.STOP_LIMIT
492
+
493
+ super().__init__(**data)
494
+
495
+
496
+ class TrailingStopOrderRequest(OrderRequest):
497
+ """
498
+ Used to submit a trailing stop order.
499
+
500
+ Attributes:
501
+ symbol (str): The symbol identifier for the asset being traded
502
+ qty (Optional[float]): The number of shares to trade. Fractional qty for stocks only with market orders.
503
+ notional (Optional[float]): The base currency value of the shares to trade. For stocks, only works with MarketOrders.
504
+ **Does not work with qty**.
505
+ side (OrderSide): Whether the order will buy or sell the asset.
506
+ type (OrderType): The execution logic type of the order (market, limit, etc).
507
+ time_in_force (TimeInForce): The expiration logic of the order.
508
+ extended_hours (Optional[float]): Whether the order can be executed during regular market hours.
509
+ client_order_id (Optional[str]): A string to identify which client submitted the order.
510
+ order_class (Optional[OrderClass]): The class of the order. Simple orders have no other legs.
511
+ legs (Optional[List[OptionLegRequest]]): For multi-leg option orders, the legs of the order. At most 4 legs are allowed for options.
512
+ take_profit (Optional[TakeProfitRequest]): For orders with multiple legs, an order to exit a profitable trade.
513
+ stop_loss (Optional[StopLossRequest]): For orders with multiple legs, an order to exit a losing trade.
514
+ trail_price (Optional[float]): The absolute price difference by which the trailing stop will trail.
515
+ trail_percent (Optional[float]): The percent price difference by which the trailing stop will trail.
516
+ position_intent (Optional[PositionIntent]): An enum to indicate the desired position strategy: BTO, BTC, STO, STC.
517
+ """
518
+
519
+ trail_price: Optional[float] = None
520
+ trail_percent: Optional[float] = None
521
+
522
+ def __init__(self, **data: Any) -> None:
523
+ data["type"] = OrderType.TRAILING_STOP
524
+
525
+ super().__init__(**data)
526
+
527
+ @model_validator(mode="before")
528
+ def root_validator(cls, values: dict) -> dict:
529
+ # noinspection PyCallingNonCallable
530
+ super().root_validator(values)
531
+ trail_percent_set = (
532
+ "trail_percent" in values and values["trail_percent"] is not None
533
+ )
534
+ trail_price_set = "trail_price" in values and values["trail_price"] is not None
535
+
536
+ if not trail_percent_set and not trail_price_set:
537
+ raise ValueError(
538
+ "Either trail_percent or trail_price must be set for a trailing stop order."
539
+ )
540
+ elif trail_percent_set and trail_price_set:
541
+ raise ValueError("Both trail_percent and trail_price cannot be set.")
542
+
543
+ return values
544
+
545
+
546
+ class GetCorporateAnnouncementsRequest(NonEmptyRequest):
547
+ """
548
+ Contains parameters for querying corporate action data.
549
+ Attributes:
550
+ ca_types (List[CorporateActionType]): A list of corporate action types.
551
+ since (date): The start (inclusive) of the date range when searching corporate action announcements.
552
+ The date range is limited to 90 days.
553
+ until (date): The end (inclusive) of the date range when searching corporate action announcements.
554
+ The date range is limited to 90 days.
555
+ symbol (Optional[str]): The symbol of the company initiating the announcement.
556
+ cusip (Optional[str]): The CUSIP of the company initiating the announcement.
557
+ date_type (Optional[CorporateActionDateType]): The date type for the announcement.
558
+ """
559
+
560
+ ca_types: List[CorporateActionType]
561
+ since: date
562
+ until: date
563
+ symbol: Optional[str] = None
564
+ cusip: Optional[str] = None
565
+ date_type: Optional[CorporateActionDateType] = None
566
+
567
+ @model_validator(mode="before")
568
+ def root_validator(cls, values: dict) -> dict:
569
+ return values
570
+
571
+
572
+ class GetOptionContractsRequest(NonEmptyRequest):
573
+ """
574
+ Used to fetch option contracts for a given underlying symbol.
575
+
576
+ Attributes:
577
+ underlying_symbols (Optional[List[str]]): The underlying symbols for the option contracts to be returned. (e.g. ["AAPL", "SPY"])
578
+ status (Optional[AssetStatus]): The status of the asset.
579
+ expiration_date (Optional[Union[date, str]]): The expiration date of the option contract. (YYYY-MM-DD)
580
+ expiration_date_gte (Optional[Union[date, str]]): The expiration date of the option contract greater than or equal to. (YYYY-MM-DD)
581
+ expiration_date_lte (Optional[Union[date, str]]): The expiration date of the option contract less than or equal to. (YYYY-MM-DD)
582
+ root_symbol (Optional[str]): The option root symbol.
583
+ type (Optional[ContractType]): The option contract type.
584
+ style (Optional[ExerciseStyle]): The option contract style.
585
+ strike_price_gte (Optional[str]): The option contract strike price greater than or equal to.
586
+ strike_price_lte (Optional[str]): The option contract strike price less than or equal to.
587
+ limit (Optional[int]): The number of contracts to limit per page (default=100, max=10000).
588
+ page_token (Optional[str]): Pagination token to continue from. The value to pass here is returned in specific
589
+ requests when more data is available than the request limit allows.
590
+ """
591
+
592
+ underlying_symbols: Optional[List[str]] = None
593
+ status: Optional[AssetStatus] = AssetStatus.ACTIVE
594
+ expiration_date: Optional[Union[date, str]] = None
595
+ expiration_date_gte: Optional[Union[date, str]] = None
596
+ expiration_date_lte: Optional[Union[date, str]] = None
597
+ root_symbol: Optional[str] = None
598
+ type: Optional[ContractType] = None
599
+ style: Optional[ExerciseStyle] = None
600
+ strike_price_gte: Optional[str] = None
601
+ strike_price_lte: Optional[str] = None
602
+
603
+ limit: Optional[int] = None
604
+ page_token: Optional[str] = None