Explore more topics
NexusTrade guides

Query market data in Python

Run bounded read-only market-data SQL and stream durable results with the NexusTrade lake extra.

Jump to a section

TL;DR

Use a lake-scoped API key and the optional Python lake dependencies to run bounded read-only SQL and retain its durable Parquet results. The worked query retrieves five AAPL sessions from January 2024, preserving adjusted prices and source timestamps. It was verified through the canonical lake reader on October 10, 2026; that receipt is separate from the SDK's query-operation transport. Save the operation, manifest and checked row count before analysis.

Follow one worked path

sdk request workflow diagram with review boundaries
Source-derived workflow diagram, not a screenshot or an external-client execution receipt.
Step 1 of 3

Install the shown SDK version

Use a registered API key with lake scope. Install nexustrade[lake] for the DuckDB and pandas analysis helpers. The base SDK is standard-library-only; these analysis dependencies are optional.

What you should see

The matching package is available and the request uses the appropriate read, write or lake scope.

Shell
python3 -m pip install 'nexustrade[lake]==1.42.0'

sdk request workflow diagram with review boundaries
Source-derived workflow diagram, not a screenshot or an external-client execution receipt.
Step 2 of 3

Run the bounded query

Run the exact bounded SQL example below. Preserve the adjusted-price basis and returned session timestamps.

What you should see

The durable query job returns schema and parts; read the actual returned values before treating them as market observations.

Python
import nexustrade as nt

result = nt.lake.sql(
    "SELECT ticker, date, closingPrice FROM lake.sec_daily_ohlc "
    "WHERE ticker = ? AND date::DATE BETWEEN CAST(? AS DATE) AND CAST(? AS DATE) "
    "ORDER BY date ASC LIMIT 5",
    ["AAPL", "2024-01-02", "2024-01-08"],
    max_rows=5,
)
frame = result.to_pandas()
print(frame)
for batch in result.iter_batches():
    print(batch)

dataset version workflow diagram with review boundaries
Source-derived workflow diagram, not a screenshot or an external-client execution receipt.
Step 3 of 3

Run the query and read its results

This query asks for at most five AAPL sessions from January 2 through January 8, 2024, sorted oldest first. Both the SQL and result budget are bounded. The catalog recommends sec_daily_ohlc for canonical equity and ETF history; daily_ohlc is the legacy vendor table. Results are durable Parquet parts.

AAPL
Source timestamp (UTC): 2024-01-02T21:00:00.000Z · closingPrice (USD): 185.64
AAPL
Source timestamp (UTC): 2024-01-03T21:00:00.000Z · closingPrice (USD): 184.25
AAPL
Source timestamp (UTC): 2024-01-04T21:00:00.000Z · closingPrice (USD): 181.91
AAPL
Source timestamp (UTC): 2024-01-05T21:00:00.000Z · closingPrice (USD): 181.18
AAPL
Source timestamp (UTC): 2024-01-08T21:00:00.000Z · closingPrice (USD): 185.56
What you should see

The shown product receipt demonstrates its originating workflow, not proof that your local SDK request has executed.

Inspect the complete workflow outline

Actual output from the canonical lake reader

Show the table · 5 rows, 3 columns

Scroll sideways to compare all columns. Select a heading to sort.

AAPL2024-01-02T21:00:00.000Z185.64
AAPL2024-01-03T21:00:00.000Z184.25
AAPL2024-01-04T21:00:00.000Z181.91
AAPL2024-01-05T21:00:00.000Z181.18
AAPL2024-01-08T21:00:00.000Z185.56

We executed the exact bounded SQL below on the deployed NexusTrade lake worker on October 10, 2026. It returned these five AAPL sessions in 438 milliseconds, including setup. This verifies the canonical source query and returned values; the request used the synchronous lake reader rather than the SDK's authenticated query-operation transport.

The date values are the source's session timestamps. closingPrice is the catalog's adjusted series, so preserve that basis when comparing it with an unadjusted quote or deriving market capitalization.

Install the lake extra

Show install the lake extra

Use a registered API key with lake scope. Install nexustrade[lake] for the DuckDB and pandas analysis helpers. The base SDK is standard-library-only; these analysis dependencies are optional.

Shell
python3 -m pip install 'nexustrade[lake]==1.42.0'

Run the query and read its results

This query asks for at most five AAPL sessions from January 2 through January 8, 2024, sorted oldest first. Both the SQL and result budget are bounded. The catalog recommends sec_daily_ohlc for canonical equity and ETF history; daily_ohlc is the legacy vendor table. Results are durable Parquet parts.

Python
import nexustrade as nt

result = nt.lake.sql(
    "SELECT ticker, date, closingPrice FROM lake.sec_daily_ohlc "
    "WHERE ticker = ? AND date::DATE BETWEEN CAST(? AS DATE) AND CAST(? AS DATE) "
    "ORDER BY date ASC LIMIT 5",
    ["AAPL", "2024-01-02", "2024-01-08"],
    max_rows=5,
)
frame = result.to_pandas()
print(frame)
for batch in result.iter_batches():
    print(batch)

Save the query and result manifest

Show save the query and result manifest

The DataFrame should contain ticker, date and closingPrice columns. Inspect its row count and dates before analysis. An empty frame means no returned matches; it does not prove the price is zero or the company has no history. If authentication fails, check that the runtime key has lake scope. Record the query operation and manifest alongside exported results. Check schema and result-part checksums before reuse. Snapshot freshness and public availability depend on the dataset, not merely the time a query finished.

A SQL operation is read-only but running a query can consume compute. It does not place orders, deploy a portfolio, or publish your workspace.

Continue exploring

Discussion

Sign in or create a free account to join the discussion.

No comments yet.