Skip to content

Commit f0eed54

Browse files
committed
add fundamentals query parameter modifiers
1 parent a4d6625 commit f0eed54

14 files changed

+1289
-23
lines changed

FUNDAMENTALS_MIGRATION.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,21 @@ short_volume = client.list_short_volume(
8484
limit=10
8585
)
8686

87-
# Clean, direct access - no extra namespacing needed!
87+
# Clean, direct access with powerful filter modifiers!
88+
89+
# Example with filter modifiers
90+
balance_sheets = client.list_balance_sheets(
91+
tickers="AAPL",
92+
period_end_gte="2023-01-01", # From 2023 onwards
93+
fiscal_year_lte=2024 # Up to 2024
94+
)
95+
96+
# Advanced filtering for financial ratios
97+
ratios = client.list_financial_ratios(
98+
price_gt=100.0, # Stock price > $100
99+
market_cap_gte=10000000000, # Market cap >= $10B
100+
price_to_earnings_lt=25.0 # P/E ratio < 25
101+
)
88102

89103
## Key Benefits of New API
90104

IMPLEMENTATION_SUMMARY.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 🎉 Polygon Fundamentals API Implementation Complete!
1+
# 🎉 New Fundamentals API Implementation!
22

33
## Summary
44

@@ -34,8 +34,11 @@ Successfully implemented the new Polygon Fundamentals API to replace the depreca
3434

3535
### 5. Documentation & Examples
3636
- `FUNDAMENTALS_MIGRATION.md` - Complete migration guide
37-
- `examples/rest/fundamentals_example.py` - Working examples
38-
- `test_fundamentals.py` - Comprehensive test suite
37+
- `examples/rest/fundamentals_example.py` - Basic usage examples
38+
- `examples/rest/fundamentals_advanced_filtering.py` - Advanced filtering & screening
39+
- `examples/rest/fundamentals_modifiers_demo.py` - Filter modifier demonstrations
40+
- `docs/source/Fundamentals.rst` - Complete API documentation
41+
- Updated old examples with deprecation notices and migration guidance
3942

4043
## 🚀 Usage
4144

@@ -91,12 +94,17 @@ financials = client.vx.list_stock_financials(ticker="AAPL")
9194
- `polygon/rest/models/fundamentals.py` - New data models
9295
- `examples/rest/fundamentals_example.py` - Usage examples
9396
- `FUNDAMENTALS_MIGRATION.md` - Migration guide
94-
- `test_fundamentals.py` - Test suite
97+
- `test_rest/test_fundamentals.py` - Test suite
9598

9699
### Modified Files
97100
- `polygon/rest/__init__.py` - Added FundamentalsClient integration
98101
- `polygon/rest/models/__init__.py` - Added fundamentals models
99102
- `polygon/rest/vX.py` - Added deprecation warnings
103+
- `README.md` - Added fundamentals examples to main usage section
104+
- `docs/source/index.rst` - Added Fundamentals to documentation index
105+
- `docs/source/vX.rst` - Added deprecation warnings and migration guidance
106+
- `examples/rest/financials.py` - Updated with modern fundamentals examples
107+
- `examples/rest/stocks-stock_financials.py` - Added deprecation notice and migration demo
100108

101109
## 🎯 Next Steps
102110

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ print(quote)
6060
quotes = client.list_quotes(ticker=ticker, timestamp="2022-01-04")
6161
for quote in quotes:
6262
print(quote)
63+
64+
# Fundamentals Data
65+
# Get balance sheets for a company
66+
balance_sheets = client.list_balance_sheets(tickers="AAPL", timeframe="quarterly", limit=5)
67+
for sheet in balance_sheets:
68+
print(f"Period: {sheet.period_end}, Total Assets: ${sheet.total_assets:,.0f}")
69+
70+
# Get financial ratios
71+
ratios = client.list_financial_ratios(ticker="AAPL", limit=5)
72+
for ratio in ratios:
73+
print(f"P/E Ratio: {ratio.price_to_earnings}, Market Cap: ${ratio.market_cap:,.0f}")
74+
75+
# Get short interest data
76+
short_interest = client.list_short_interest(ticker="AAPL", limit=5)
77+
for si in short_interest:
78+
print(f"Settlement Date: {si.settlement_date}, Short Interest: {si.short_interest:,} shares")
6379
```
6480

6581
### Pagination Behavior

docs/source/Fundamentals.rst

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
Fundamentals
2+
============
3+
4+
.. currentmodule:: polygon
5+
6+
The Fundamentals API provides access to comprehensive financial data for public companies through 6 specialized endpoints. This modern API replaces the deprecated ``VXClient`` with focused, high-performance endpoints for specific data types.
7+
8+
.. note::
9+
**🚨 Migration Notice**: The old ``client.vx.list_stock_financials()`` method is deprecated.
10+
Use the new dedicated endpoints listed below for better performance and cleaner data access.
11+
12+
Quick Start
13+
-----------
14+
15+
.. code-block:: python
16+
17+
from polygon import RESTClient
18+
19+
client = RESTClient(api_key="your_api_key")
20+
21+
# Get balance sheets - clean and direct!
22+
balance_sheets = client.list_balance_sheets(tickers="AAPL", timeframe="quarterly", limit=5)
23+
for sheet in balance_sheets:
24+
print(f"Period: {sheet.period_end}, Assets: ${sheet.total_assets:,.0f}")
25+
26+
Available Endpoints
27+
-------------------
28+
29+
The fundamentals API consists of 6 specialized endpoints:
30+
31+
1. **Balance Sheets** - :meth:`RESTClient.list_balance_sheets`
32+
2. **Cash Flow Statements** - :meth:`RESTClient.list_cash_flow_statements`
33+
3. **Income Statements** - :meth:`RESTClient.list_income_statements`
34+
4. **Financial Ratios** - :meth:`RESTClient.list_financial_ratios`
35+
5. **Short Interest** - :meth:`RESTClient.list_short_interest`
36+
6. **Short Volume** - :meth:`RESTClient.list_short_volume`
37+
38+
Balance Sheets
39+
--------------
40+
41+
.. automethod:: RESTClient.list_balance_sheets
42+
43+
**Example:**
44+
45+
.. code-block:: python
46+
47+
# Get quarterly balance sheets for Apple from 2023 onwards
48+
balance_sheets = client.list_balance_sheets(
49+
tickers="AAPL",
50+
timeframe="quarterly",
51+
period_end_gte="2023-01-01",
52+
limit=8
53+
)
54+
55+
for sheet in balance_sheets:
56+
print(f"Q{sheet.fiscal_quarter} {sheet.fiscal_year}: ${sheet.total_assets:,.0f} total assets")
57+
58+
Cash Flow Statements
59+
--------------------
60+
61+
.. automethod:: RESTClient.list_cash_flow_statements
62+
63+
**Example:**
64+
65+
.. code-block:: python
66+
67+
# Get annual cash flow statements for multiple companies
68+
cash_flows = client.list_cash_flow_statements(
69+
tickers_any_of="AAPL,GOOGL,MSFT",
70+
timeframe="annual",
71+
limit=10
72+
)
73+
74+
for cf in cash_flows:
75+
if cf.net_cash_flow_from_operating_activities:
76+
print(f"{cf.tickers[0]} {cf.fiscal_year}: Operating CF = ${cf.net_cash_flow_from_operating_activities:,.0f}")
77+
78+
Income Statements
79+
-----------------
80+
81+
.. automethod:: RESTClient.list_income_statements
82+
83+
**Example:**
84+
85+
.. code-block:: python
86+
87+
# Get income statements with revenue filtering
88+
income_statements = client.list_income_statements(
89+
tickers="TSLA",
90+
timeframe="quarterly",
91+
revenues_gt=10000000000, # Revenue > $10B
92+
limit=5
93+
)
94+
95+
for stmt in income_statements:
96+
print(f"Q{stmt.fiscal_quarter} {stmt.fiscal_year}: Revenue ${stmt.revenues:,.0f}, Net Income ${stmt.net_income_loss:,.0f}")
97+
98+
Financial Ratios
99+
----------------
100+
101+
.. automethod:: RESTClient.list_financial_ratios
102+
103+
**Example:**
104+
105+
.. code-block:: python
106+
107+
# Find stocks with low P/E ratios and high market cap
108+
ratios = client.list_financial_ratios(
109+
price_to_earnings_lt=15, # P/E < 15
110+
market_cap_gt=50000000000, # Market cap > $50B
111+
limit=20
112+
)
113+
114+
for ratio in ratios:
115+
print(f"{ratio.ticker}: P/E = {ratio.price_to_earnings:.2f}, Market Cap = ${ratio.market_cap:,.0f}")
116+
117+
Short Interest
118+
--------------
119+
120+
.. automethod:: RESTClient.list_short_interest
121+
122+
**Example:**
123+
124+
.. code-block:: python
125+
126+
# Get short interest data with high days-to-cover
127+
short_interest = client.list_short_interest(
128+
ticker_any_of="GME,AMC,BBBY",
129+
days_to_cover_gt=5, # High short squeeze potential
130+
limit=10
131+
)
132+
133+
for si in short_interest:
134+
print(f"{si.ticker} ({si.settlement_date}): {si.short_interest:,} shares, {si.days_to_cover:.1f} days to cover")
135+
136+
Short Volume
137+
------------
138+
139+
.. automethod:: RESTClient.list_short_volume
140+
141+
**Example:**
142+
143+
.. code-block:: python
144+
145+
# Analyze recent short volume patterns
146+
from datetime import date, timedelta
147+
148+
recent_date = date.today() - timedelta(days=7)
149+
short_volume = client.list_short_volume(
150+
ticker="AAPL",
151+
date_gte=recent_date,
152+
short_volume_ratio_gt=0.4, # High short ratio
153+
limit=10
154+
)
155+
156+
for sv in short_volume:
157+
print(f"{sv.date}: {sv.short_volume_ratio:.1%} short ratio ({sv.short_volume:,} of {sv.total_volume:,} shares)")
158+
159+
Filter Modifiers
160+
----------------
161+
162+
All fundamentals endpoints support advanced filtering with these modifiers:
163+
164+
* ``.gt`` - Greater than
165+
* ``.gte`` - Greater than or equal to
166+
* ``.lt`` - Less than
167+
* ``.lte`` - Less than or equal to
168+
* ``.any_of`` - Equals any of (comma-separated values)
169+
* ``.all_of`` - Contains all of (comma-separated values, for arrays)
170+
171+
**Examples:**
172+
173+
.. code-block:: python
174+
175+
# Multiple filter examples
176+
177+
# Date range filtering
178+
balance_sheets = client.list_balance_sheets(
179+
tickers="AAPL",
180+
period_end_gte="2023-01-01",
181+
period_end_lt="2024-01-01"
182+
)
183+
184+
# Multiple tickers with any_of
185+
ratios = client.list_financial_ratios(
186+
ticker_any_of="AAPL,GOOGL,MSFT,AMZN,TSLA"
187+
)
188+
189+
# Numeric range filtering
190+
high_growth = client.list_income_statements(
191+
revenues_gt=1000000000, # Revenue > $1B
192+
fiscal_year_gte=2022 # 2022 onwards
193+
)
194+
195+
Migration from VXClient
196+
-----------------------
197+
198+
If you're migrating from the old ``VXClient``, here's the mapping:
199+
200+
.. list-table:: Migration Guide
201+
:widths: 50 50
202+
:header-rows: 1
203+
204+
* - Old (Deprecated)
205+
- New (Recommended)
206+
* - ``client.vx.list_stock_financials()``
207+
- Use 6 specific methods based on data needed
208+
* - Single complex endpoint
209+
- Dedicated optimized endpoints
210+
* - Mixed data types in response
211+
- Clean, focused response models
212+
213+
**Before (Deprecated):**
214+
215+
.. code-block:: python
216+
217+
# OLD - Shows deprecation warnings
218+
financials = client.vx.list_stock_financials(ticker="AAPL")
219+
220+
**After (Modern):**
221+
222+
.. code-block:: python
223+
224+
# NEW - Clean, fast, and focused
225+
balance_sheets = client.list_balance_sheets(tickers="AAPL")
226+
income_statements = client.list_income_statements(tickers="AAPL")
227+
ratios = client.list_financial_ratios(ticker="AAPL")
228+
229+
Benefits of New API
230+
-------------------
231+
232+
✅ **Performance**: Smaller, focused responses load faster
233+
234+
✅ **Clarity**: Each endpoint returns exactly what you need
235+
236+
✅ **Features**: Better filtering, TTM data support, cleaner models
237+
238+
✅ **Type Safety**: Better IDE support and error catching
239+
240+
✅ **Maintenance**: Easier to extend and maintain
241+
242+
✅ **Documentation**: Comprehensive parameter documentation
243+
244+
Error Handling
245+
--------------
246+
247+
All fundamentals methods use the same error handling patterns as other REST client methods:
248+
249+
.. code-block:: python
250+
251+
try:
252+
balance_sheets = client.list_balance_sheets(tickers="INVALID")
253+
for sheet in balance_sheets:
254+
print(sheet)
255+
except Exception as e:
256+
print(f"Error: {e}")
257+
258+
For more examples, see the `examples/rest/fundamentals_example.py <https://github.com/polygon-io/client-python/blob/master/examples/rest/fundamentals_example.py>`_ file.

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This documentation is for the Python client only. For details about the response
88
:caption: Contents:
99

1010
Getting-Started
11+
Fundamentals
1112
Aggs
1213
WebSocket
1314
Snapshot

docs/source/vX.rst

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
.. _vX_header:
22

3-
vX
4-
==========
3+
vX (Deprecated)
4+
===============
5+
6+
.. warning::
7+
**🚨 DEPRECATED**: The VX client and its methods are deprecated and will be removed in a future version.
8+
9+
**👉 NEW**: Use the modern :doc:`Fundamentals` API instead for better performance and cleaner access to financial data.
10+
11+
**Migration Guide**: See :doc:`Fundamentals` for migration examples and new endpoint documentation.
512

613
.. note::
714
To call vX methods, use the vx class member on RESTClient.
815

916
For example, :code:`financials = RESTClient().vx.list_stock_financials()`
17+
18+
**⚠️ This will show deprecation warnings in your code.**
1019

1120
======================
12-
List stock financials
13-
======================
21+
List stock financials (Deprecated)
22+
===================================
1423

1524
- `Stocks financials vX`_
1625

0 commit comments

Comments
 (0)