Error when view chart for options using Polygon
I added an API key from Polygon, but I get this error message.
TypeError: Cannot read properties of undefined (reading 'length')
Polygon is capable of charting aggregates (Bars) for options. Please see below link for Polygon documentations. https://polygon.io/docs/options/get_v2_aggs_ticker__optionsticker__range__multiplier___timespan___from___to
The issue is that Polygon ticker symbol for options starts with O:
But the csv file from Interactive Brockers does not come with this extra "O:" by default
I faced with exactly this problem as well. The problem as I see is that the symbol in option trades is actually an underlying stock, which is SPY in your case. There are two problems with this approach:
- In the trades you will only see SPY. You won't see wether it's a Call/Put, expiration date, strike price
- The app sends a ticker as "O:SPY" which doesn't make any sense for Polygon because in this format it expects an option.
I ended up writing a simple python script to process an exported CSV file from IBKR. What it does:
- Removes spaces in the Symbol column to convert SPY 250904P00642000 to SPY250904P00642000
- Copies the value to the UnderlyingSymbol column to replace SPY with SPY250904P00642000
Now Polygon recognises them properly and I have charts