Closed jcoffi closed 5 months ago
@jcoffi can you please try to use the latest version v0.14.0
of alpaca-py instead of alpaca-py==0.8.2
?
Seems default value for qty field is set as None with the latest code. Therefore, the error might not happen with the version v0.14.0
.
FWIW, I'm not specifying a version of alpaca_py when I install using pip. I'm getting the version I'm getting by default.
v0.14.0 seems to resolve this.
Is there an existing issue for this?
Current Behavior
from alpaca.data.timeframe import TimeFrame from alpaca.data.requests import StockBarsRequest from alpaca.data.historical import StockHistoricalDataClient# Create stock historical data client from alpaca.trading.client import TradingClient from alpaca.trading.requests import GetAssetsRequest from alpaca.trading.enums import AssetClass, AssetStatus, AssetExchange stockhistory_client = StockHistoricalDataClient(APCA_API_KEY_ID, APCA_API_SECRET_KEY) trading_client = TradingClient(APCA_API_KEY_ID, APCA_API_SECRET_KEY)
`--------------------------------------------------------------------------- PydanticUserError Traceback (most recent call last) Cell In[15], line 4 2 from alpaca.data.requests import StockBarsRequest 3 from alpaca.data.historical import StockHistoricalDataClient# Create stock historical data client ----> 4 from alpaca.trading.client import TradingClient 5 from alpaca.trading.requests import GetAssetsRequest 6 from alpaca.trading.enums import AssetClass, AssetStatus, AssetExchange
File ~/anaconda3/lib/python3.10/site-packages/alpaca/trading/init.py:1 ----> 1 from .client import 2 from .models import 3 from .enums import *
File ~/anaconda3/lib/python3.10/site-packages/alpaca/trading/client.py:11 8 from typing import Optional, List, Union 9 from alpaca.common.enums import BaseURL ---> 11 from alpaca.trading.requests import ( 12 GetCalendarRequest, 13 ClosePositionRequest, 14 GetAssetsRequest, 15 OrderRequest, 16 GetOrdersRequest, 17 ReplaceOrderRequest, 18 GetOrderByIdRequest, 19 CancelOrderResponse, 20 CreateWatchlistRequest, 21 UpdateWatchlistRequest, 22 GetCorporateAnnouncementsRequest, 23 ) 25 from alpaca.trading.models import ( 26 Order, 27 Position, (...) 35 AccountConfiguration, 36 ) 39 class TradingClient(RESTClient):
File ~/anaconda3/lib/python3.10/site-packages/alpaca/trading/requests.py:25 9 from alpaca.common.models import ValidateBaseModel as BaseModel 10 from alpaca.trading.enums import ( 11 OrderType, 12 AssetStatus, (...) 21 QueryOrderStatus, 22 ) ---> 25 class ClosePositionRequest(NonEmptyRequest): 26 """ 27 Attributes: 28 qty (str): The number of shares to liquidate. 29 percentage (str): The percentage of shares to liquidate. 30 """ 32 qty: Optional[str]
File ~/anaconda3/lib/python3.10/site-packages/alpaca/trading/requests.py:35, in ClosePositionRequest() 32 qty: Optional[str] 33 percentage: Optional[str] ---> 35 @root_validator() 36 def root_validator(cls, values: dict) -> dict: 37 if "qty" not in values or "percentage" not in values: 38 return values
File ~/anaconda3/lib/python3.10/site-packages/pydantic/deprecated/class_validators.py:237, in root_validator(pre, skip_on_failure, allow_reuse, *__args) 235 mode: Literal['before', 'after'] = 'before' if pre is True else 'after' 236 if pre is False and skip_on_failure is not True: --> 237 raise PydanticUserError( 238 'If you use
@root_validator
with pre=False (the default) you MUST specifyskip_on_failure=True
.' 239 ' Note that@root_validator
is deprecated and should be replaced with@model_validator
.', 240 code='root-validator-pre-skip', 241 ) 243 wrap = partial(_decorators_v1.make_v1_generic_root_validator, pre=pre) 245 def dec(f: Callable[..., Any] | classmethod[Any, Any, Any] | staticmethod[Any, Any]) -> Any:PydanticUserError: If you use
@root_validator
with pre=False (the default) you MUST specifyskip_on_failure=True
. Note that@root_validator
is deprecated and should be replaced with@model_validator
.For further information visit https://errors.pydantic.dev/2.6/u/root-validator-pre-skip`
Expected Behavior
No response
SDK Version I encountered this issue in
alpaca-py==0.8.2
Steps To Reproduce
Filled out the Steps to Reproduce section?
Anything else?
No response