tastyware / tastytrade

An unofficial Python SDK for Tastytrade!
MIT License
108 stars 38 forks source link

string_type error in Pydantic #163

Open jowolf opened 3 weeks ago

jowolf commented 3 weeks ago

I'm getting a string_type error in Pydantic - here's my call:

watchlists = Watchlist.get_public_watchlists (session)

Traceback (most recent call last): File "[,,,] watchlists = Watchlist.get_public_watchlists (session) File "/home/joe/traderjoe/env/lib/python3.10/site-packages/tastytrade/watchlists.py", line 83, in get_public_watchlists return [cls(i) for i in data['items']] File "/home/joe/traderjoe/env/lib/python3.10/site-packages/tastytrade/watchlists.py", line 83, in return [cls(i) for i in data['items']] File "/home/joe/traderjoe/env/lib/python3.10/site-packages/pydantic/main.py", line 193, in init self.__pydantic_validator__.validate_python(data, self_instance=self) pydantic_core._pydantic_core.ValidationError: 2 validation errors for Watchlist watchlist-entries.12.instrument-type Input should be a valid string [type=string_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.8/v/string_type watchlist-entries.13.instrument-type Input should be a valid string [type=string_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.8/v/string_type

Lots of other calls work fine on this session prior to this call, so I know the session is fine and was established OK j

jowolf commented 2 weeks ago

More info / workaround: When I pass counts_only=True, it works (but returns the full results):

watchlists = Watchlist.get_public_watchlists (session, counts_only=True)
print()
print ('Watchlists')
pp ([wl.name for wl  in watchlists], indent=2)

returns:

Watchlists [ 'Russell Microcap', 'Russell 1000', 'Russell Midcap', 'All Earnings', 'Basic Materials', 'CRE Hospitality Price Return Index', 'Crypto', 'Dividend Aristocrats', 'Futures: All', 'High Options Volume', 'Market Indicators', '52 Week Near High', 'tasty Earnings', 'Communication Services', 'Futures: CME', 'Bitcoin ETFs', 'Dividend Champions', 'Liquid ETFs', '52 Week Near Low', 'CRE Office Price Return Index', 'CRE Residential Price Return Index', 'Ethereum ETFs', 'A.I. Stocks', 'Futures: Micros', 'Liquid Symbols', 'Consumer Defensive', 'Futures: Small Exchange', 'CRE Retail Price Return Index', 'Consumer Discretionary', "BAT's Watchlist", 'Futures: With Options', 'Energy', 'Dow Jones Industrial Average', 'Market', 'ISE Homebuilders Index', 'Financial Services', 'NASDAQ 100', 'tasty default', 'Healthcare', 'NASDAQ-100 Target 25 Index', 'Industrials', 'tasty Fast Movers', 'Real Estate', 'tasty Hourly Top Equities', 'NASDAQ Golden Dragon China Index', 'tasty IVR', 'Technology', 'PHLX Gold/Silver Sector', 'Utilities', "Tom's Watchlist", 'PHLX Housing Sector', 'Volatility Indexes', 'PHLX Oil Service Sector', 'PHLX Semiconductor', 'PHLX Utility Sector', 'S&P 100', 'S&P 500']

Graeme22 commented 4 days ago

Looks like some of the TT watchlists have an instrument type of None! I was able to reproduce. Will be fixed in next release.