26
26
TradeConfirmationEmail ,
27
27
TradeEvent ,
28
28
)
29
- from pydantic import Field
29
+ from pydantic import Field , model_validator
30
30
31
31
32
32
class Asset (ModelWithID ):
@@ -182,19 +182,19 @@ class Order(ModelWithID):
182
182
replaced_at (Optional[datetime]): Timestamp when the order was replaced by a new order.
183
183
replaced_by (Optional[UUID]): ID of order that replaces this order.
184
184
replaces (Optional[UUID]): ID of order which this order replaces.
185
- asset_id (UUID): ID of the asset.
186
- symbol (str): Symbol of the asset.
187
- asset_class (AssetClass): Asset class of the asset.
185
+ asset_id (Optional[ UUID] ): ID of the asset. Omitted from top-level of response if the order is of mleg class .
186
+ symbol (Optional[ str] ): Symbol of the asset. Omitted from top-level of response if the order is of mleg class .
187
+ asset_class (Optional[ AssetClass] ): Asset class of the asset. Omitted from top-level of response if the order is of mleg class .
188
188
notional (Optional[str]): Ordered notional amount. If entered, qty will be null. Can take up to 9 decimal
189
189
points.
190
190
qty (Optional[str]): Ordered quantity. If entered, notional will be null. Can take up to 9 decimal points.
191
191
filled_qty (Optional[str]): Filled quantity.
192
192
filled_avg_price (Optional[str]): Filled average price. Can be 0 until order is processed in case order is
193
193
passed outside of market hours.
194
194
order_class (OrderClass): Valid values: simple, bracket, oco or oto.
195
- order_type (OrderType): Deprecated with just type field below.
196
- type (OrderType): Valid values: market, limit, stop, stop_limit, trailing_stop.
197
- side (OrderSide): Valid values: buy and sell.
195
+ order_type (Optional[ OrderType] ): Deprecated with just type field below. Omitted from legs of mleg orders .
196
+ type (Optional[ OrderType] ): Valid values: market, limit, stop, stop_limit, trailing_stop. Omitted from legs of mleg orders .
197
+ side (Optional[ OrderSide] ): Valid values: buy and sell. Omitted from top-level of response if the order is of mleg class .
198
198
time_in_force (TimeInForce): Length of time the order is in force.
199
199
limit_price (Optional[str]): Limit price of the order.
200
200
stop_price (Optional[str]): Stop price of the order.
@@ -206,6 +206,7 @@ class Order(ModelWithID):
206
206
trail_price (Optional[str]): The dollar value away from the high water mark for trailing stop orders.
207
207
hwm (Optional[str]): The highest (lowest) market price seen since the trailing stop order was submitted.
208
208
position_intent (Optional[PositionIntent]): Represents the desired position strategy.
209
+ ratio_qty (Optional[str]): The proportional quantity of this leg in relation to the overall multi-leg order quantity.
209
210
"""
210
211
211
212
client_order_id : str
@@ -219,17 +220,17 @@ class Order(ModelWithID):
219
220
replaced_at : Optional [datetime ] = None
220
221
replaced_by : Optional [UUID ] = None
221
222
replaces : Optional [UUID ] = None
222
- asset_id : UUID
223
- symbol : str
224
- asset_class : AssetClass
223
+ asset_id : Optional [ UUID ] = None
224
+ symbol : Optional [ str ] = None
225
+ asset_class : Optional [ AssetClass ] = None
225
226
notional : Optional [str ] = None
226
227
qty : Optional [Union [str , float ]] = None
227
228
filled_qty : Optional [Union [str , float ]] = None
228
229
filled_avg_price : Optional [Union [str , float ]] = None
229
230
order_class : OrderClass
230
- order_type : OrderType
231
- type : OrderType
232
- side : OrderSide
231
+ order_type : Optional [ OrderType ] = None
232
+ type : Optional [ OrderType ] = None
233
+ side : Optional [ OrderSide ] = None
233
234
time_in_force : TimeInForce
234
235
limit_price : Optional [Union [str , float ]] = None
235
236
stop_price : Optional [Union [str , float ]] = None
@@ -240,11 +241,18 @@ class Order(ModelWithID):
240
241
trail_price : Optional [str ] = None
241
242
hwm : Optional [str ] = None
242
243
position_intent : Optional [PositionIntent ] = None
244
+ ratio_qty : Optional [Union [str , float ]] = None
243
245
244
246
def __init__ (self , ** data : Any ) -> None :
245
247
if "order_class" not in data or data ["order_class" ] == "" :
246
248
data ["order_class" ] = OrderClass .SIMPLE
247
249
250
+ # mleg responses will give ''s that will need to be converted to None
251
+ # to avoid validation errors from pydantic
252
+ for k in ["asset_id" , "symbol" , "asset_class" , "side" , "type" , "order_type" ]:
253
+ if k in data and data [k ] == "" :
254
+ data [k ] = None
255
+
248
256
super ().__init__ (** data )
249
257
250
258
@@ -500,9 +508,9 @@ class TradeAccount(ModelWithID):
500
508
(inclusive of today)
501
509
options_buying_power (Optional[str]): Your buying power for options trading
502
510
options_approved_level (Optional[int]): The options trading level that was approved for this account.
503
- 0=disabled, 1=Covered Call/Cash-Secured Put, 2=Long Call/Put.
511
+ 0=disabled, 1=Covered Call/Cash-Secured Put, 2=Long Call/Put, 3=Spreads/Straddles .
504
512
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.
505
- 0=disabled, 1=Covered Call/Cash-Secured Put, 2=Long
513
+ 0=disabled, 1=Covered Call/Cash-Secured Put, 2=Long, 3=Spreads/Straddles.
506
514
"""
507
515
508
516
account_number : str
@@ -553,7 +561,7 @@ class AccountConfiguration(BaseModel):
553
561
suspend_trade (bool): If true Account becomes unable to submit new orders
554
562
trade_confirm_email (TradeConfirmationEmail): Controls whether Trade confirmation emails are sent.
555
563
ptp_no_exception_entry (bool): If set to true then Alpaca will accept orders for PTP symbols with no exception. Default is false.
556
- max_options_trading_level (Optional[int]): The desired maximum options trading level. 0=disabled, 1=Covered Call/Cash-Secured Put, 2=Long Call/Put.
564
+ 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 .
557
565
"""
558
566
559
567
dtbp_check : DTBPCheck
0 commit comments