thammo4 / uvatradier

Python wrapper for the Tradier brokerage API
Apache License 2.0
16 stars 12 forks source link

Add error handling to Quotes.get_quote_day for non-existent symbol argument #26

Closed thammo4 closed 4 months ago

thammo4 commented 4 months ago

Quotes.get_quote_day works fine so long as a valid symbol is passed. When a non-existent symbol is provided, it throws an error because we need to check for the existence of the json in r.json()

quotes.get_quote_day('SPY'); symbol description exch type last change volume open ... week_52_low bidsize bidexch bid_date asksize askexch ask_date root_symbols 0 SPY SPDR S&P 500 P etf 562.18 0.86 7337492 561.44 ... 409.21 4 Q 1720706867000 3 Z 1720706867000 SPY

[1 rows x 27 columns]

quotes.get_quote_day('WTF') Traceback (most recent call last): File "", line 1, in File "/Users/thammons/Desktop/msds/tradier/uvatradier/uvatradier/quotes.py", line 201, in get_quote_day df_quote = pd.json_normalize(r.json()['quotes']['quote']);


KeyError: 'quote'
thammo4 commented 4 months ago

quotes.get_quote_day('GE') symbol description exch type last change volume open high low ... prevclose week_52_high week_52_low bidsize bidexch bid_date asksize askexch ask_date root_symbols 0 GE GE Aerospace N stock 161.92 -3.5 4315417 165.19 165.68 161.79 ... 165.42 170.8 84.16343 3 P 1720728546000 1 P 1720728546000 GE,GE1,GE2

[1 rows x 27 columns]

quotes.get_quote_day('WHOOPS') No quote data for: WHOOPS. Empty DataFrame Columns: [] Index: [] quotes.get_quote_day(1234567) 'Symbol needs to be a string (duh?)' quotes.get_quote_day([]) 'Symbol needs to be a string (duh?)' quotes.get_quote_day('') 'API Request Failed: 400 Client Error: for url: https://sandbox.tradier.com/v1/markets/quotes?symbols=&greeks=false.'