Best Practices

Optimize your GridStatus API usage for performance, reliability, and cost-effectiveness.

Query Optimization

1

Always Use Time Filters

Unbounded queries can be slow and expensive. Always specify start_time and end_time when querying time-series data.

# Queries entire dataset - slow and expensive
curl "https://api.gridstatus.io/v1/datasets/ercot_lmp_by_settlement_point/query?api_key=YOUR_API_KEY"
2

Filter by Subseries

Most LMP and load datasets contain data for many locations. Filter to the specific locations you need.

Why this matters: LMP datasets like pjm_lmp_real_time_5_min contain 10,000+ pricing nodes. Querying all nodes for a single day can return millions of rows. If you only need hub prices for trading decisions, filter to those specific hubs.

# Returns data for all 10,000+ nodes
curl "https://api.gridstatus.io/v1/datasets/pjm_lmp_real_time_5_min/query?api_key=YOUR_API_KEY"
3

Select Only Needed Columns

Reduce response size by requesting only the columns you need.

# Only get timestamp, location, and LMP
curl "https://api.gridstatus.io/v1/datasets/caiso_lmp_real_time_5_min/query?\
start_time=2026-01-01&\
end_time=2026-01-02&\
columns=interval_start_utc,location,lmp&\
filter_column=location&\
filter_value=TH_SP15_GEN-APND&\
api_key=YOUR_API_KEY"
4

Use Appropriate Limits

Set explicit limits to control data volume and costs.

# Always set a limit during development
data = client.get_dataset(
    "ercot_fuel_mix",
    start="2026-01-01",
    end="2026-01-02",
    limit=1000  # Prevent accidental large queries
)
5

Resample Locally

If a query involving resampling is timing out on the API, download the raw data and perform resampling locally.

Pagination Strategies

Use Cursor Pagination for Large Datasets

Cursor-based pagination is more efficient than offset-based for large result sets. The client handles this automatically. For more see Pagination documentation.arrow-up-right

# The client handles pagination automatically - no manual cursor management needed
df = client.get_dataset(
    "ercot_fuel_mix",
    start="2026-01-01",
    end="2026-01-02"
)

# All pages are fetched and combined into a single DataFrame
print(f"Retrieved {len(df)} total rows")

Batch Large Date Ranges

For queries spanning months or years, batch into smaller chunks.

Caching Strategies

Caching is essential for energy market applications where you repeatedly query the same historical data for backtesting, model training, or report generation.

Cache Static Data

Dataset metadata and column values change infrequently. Cache them to reduce API calls.

Use case: When building a location selector dropdown, cache the list of available pricing nodes rather than fetching on every page load.

Cache Frequently Accessed Data

For data that's queried repeatedly, implement a local cache.

Use case: When backtesting a trading strategy across multiple parameter combinations, cache the underlying price data locally so you're not re-fetching the same historical data for each backtest run.

Error Handling

Implement Retry Logic

Handle transient errors gracefully with exponential backoff.

Monitor API Usage

Check usage before large operations to avoid hitting limits.

Data Quality

Data quality checks are critical for energy trading and operational applications where decisions are time-sensitive.

Verify Data Freshness

Check that data is current before using it in production.

Use case: Before executing trades based on current prices, verify the data is within an acceptable age threshold. Stale data could lead to trading on outdated price signals.

Validate Query Results

Verify that returned data meets expectations.

Performance Summary

Practice
Impact
Implementation

Use time filters

High

Always set start_time and end_time

Filter by location

High

Use filter_column/filter_value

Resampling

High

Remove resampling. Fetch raw data first and resample locally.

Batch large requests

High

Split into smaller chunks

Retry on errors

High

Implement exponential backoff (included in the client)

Select columns

Medium

Use columns parameter

Cursor pagination

Medium

Use cursor instead of page

Cache data

Medium

Store frequently accessed data locally

Monitor usage

Medium

Check quota before large queries

Last updated

Was this helpful?