Skip to content

Commit 46df27b

Browse files
karlwaldmanclaude
andcommitted
docs: default polling interval now fits the free plan (api#7235, api#7240)
Both recommended intervals in the SDK docs exceeded our own free plan: EXAMPLES.md time.sleep(300) -> 288/day = 5.8x the 50/day allowance PERFORMANCE_GUIDE.md time.sleep(300) -> same, and it is the "Solution" block Defaults are now 1800 (30 min = 48 requests/day, fits free), with an inline note to drop to 300 on Developer and above. PERFORMANCE_GUIDE gains a plan/interval table and the measured update cadence (BRENT ~2.5 min, WTI and natural gas ~5 min, refined products ~twice a day, from the prices table over 7 days), so the interval is chosen from evidence rather than habit. Above Developer, extra quota is better spent on more codes than a shorter timer - the data has no more resolution to give. Also flags api#7240 where a reader will trip over it: get_multiple() currently issues one HTTP request PER CODE (prices.py:96-99 loops over self.get), so it costs the same as a manual loop while the REST API accepts 20 codes in one request that counts once. Verified against production today. NOT changed after reading the context: PERFORMANCE_GUIDE.md:228 time.sleep(1) - explicitly labelled an anti-pattern EXAMPLES.md was patched in binary to preserve its 640 CRLF line endings; a formatter had otherwise normalised the whole file and turned an 8-line change into a 1,286-line diff. Refs api#7235, api#7240 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JKAExynd9zoKwt6rYA66EA
1 parent 8c5fee7 commit 46df27b

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

EXAMPLES.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,12 @@ def monitor_prices():
456456
elif price.value < limits['low']:
457457
send_alert(commodity, price.value, limits['low'], 'BELOW')
458458

459-
# Example caller-selected interval; honor API limit and freshness metadata.
460-
time.sleep(300)
459+
# 30 minutes fits the free plan: 48 requests/day against a 50/day
460+
# allowance. On Developer and above use 300 (5 minutes), which matches
461+
# how often spot prices actually change - nothing we publish moves
462+
# faster than ~2.5 minutes, so a shorter timer returns the same number.
463+
# See https://docs.oilpriceapi.com/guides/rate-limiting#how-often-to-poll
464+
time.sleep(1800)
461465

462466
if __name__ == '__main__':
463467
print("Starting price monitor...")

docs/PERFORMANCE_GUIDE.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,37 @@ while True:
235235

236236
**Solution:**
237237
```python
238-
# Choose an interval from API limits and the application's freshness need
238+
# Match the interval to your plan AND to how fast the data moves.
239239
import time
240240

241241
while True:
242242
price = client.prices.get("WTI_USD")
243243
print(f"WTI: ${price.value}")
244-
time.sleep(300) # Example client-selected interval
244+
time.sleep(1800) # 30 min -> 48 requests/day, fits the free plan
245+
# Developer and above: 300 (5 minutes)
245246
```
246247

248+
**Pick the interval from your plan:**
249+
250+
| Plan | Quota | Poll every | Requests/day |
251+
| --- | --- | --- | --- |
252+
| Free | 50 / day | **30 minutes** | 48 |
253+
| Developer | 10,000 / month | 5 minutes | 288 |
254+
| Starter | 50,000 / month | 5 minutes | 1,440 |
255+
| Professional+ | 100,000+ / month | 5 minutes | 2,880 |
256+
257+
Polling faster than the data changes cannot return new information. Measured
258+
over a week: `BRENT_CRUDE_USD` updates about every 2.5 minutes, `WTI_USD` and
259+
`NATURAL_GAS_USD` about every 5, and refined products such as `DIESEL_USD`
260+
about twice a day. Above Developer, extra quota is better spent on more
261+
commodity codes than on a shorter timer.
262+
263+
⚠️ **`get_multiple()` currently issues one HTTP request per code**, so it
264+
consumes quota per commodity rather than per call. Until that is batched
265+
(api#7240), a loop over `get()` and a call to `get_multiple()` cost the same.
266+
The REST API itself accepts up to 20 codes in a single request that counts
267+
once — see the rate-limiting guide if you are close to your quota.
268+
247269
**Better Solution (for streamed updates):**
248270
```python
249271
# Use WebSocket streaming when the account is entitled to it.

0 commit comments

Comments
 (0)