NexusTrade guides

Query market data in Python with plain English

Ask the NexusTrade screener a plain-English question with the Python SDK and get the matching rows back. Install, authenticate, branch on the outcome and read the rows.

Explore more topics

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

These examples use NexusTrade Python SDK 5.0.0. Create an API key with read access on the developers page and keep it out of shared files.

Create an API key
What you should see

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

Shell
python3 -m pip install nexustrade==5.0.0
printf 'NexusTrade API key: '
read -rs NEXUSTRADE_API_KEY
export NEXUSTRADE_API_KEY
printf '\n'

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

Ask one plain-English question

Run this example. Name the filters, the time period and how many results you want in the question itself.

What you should see

The screen finishes with an outcome. Rows arrive only when that outcome is ROWS.

Python
import nexustrade as nt

screen = nt.nl.screen_stocks(
    "The 10 largest US technology stocks by market cap with a P/E ratio under 30"
)

if screen.outcome == "ROWS":
    print(f"{screen.row_count} rows as of {screen.as_of_date}")
    for row in screen.rows:
        print(row)
elif screen.needs_clarification:
    print("Ask a more specific question:", screen.clarification)
elif screen.is_empty:
    print("No stock passed every filter.")
else:
    print("The screen finished without rows:", screen.outcome)

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

Branch on the outcome

Check the outcome before reading rows. Treat EMPTY as an answer, and reply to CLARIFICATION with a more specific question.

What you should see

You read rows from a finished screen and print one row before relying on its column names. A screen spends LLM credits and changes nothing in your account.

Install and authenticate

Show install and authenticate

These examples use NexusTrade Python SDK 5.0.0. Create an API key with read access on the developers page and keep it out of shared files.

Shell
python3 -m pip install nexustrade==5.0.0
printf 'NexusTrade API key: '
read -rs NEXUSTRADE_API_KEY
export NEXUSTRADE_API_KEY
printf '\n'

Run a plain-English screen

Show run a plain-english screen

Describe the stocks you want in one sentence. nt.nl.screen_stocks submits the question, waits for the screen to finish and returns an NlScreen with the matching rows.

Name the filters, the time period and how many results you want. A specific question gets a specific answer.

Python
import nexustrade as nt

screen = nt.nl.screen_stocks(
    "The 10 largest US technology stocks by market cap with a P/E ratio under 30"
)

if screen.outcome == "ROWS":
    print(f"{screen.row_count} rows as of {screen.as_of_date}")
    for row in screen.rows:
        print(row)
elif screen.needs_clarification:
    print("Ask a more specific question:", screen.clarification)
elif screen.is_empty:
    print("No stock passed every filter.")
else:
    print("The screen finished without rows:", screen.outcome)

Branch on the outcome

Show branch on the outcome

Check screen.outcome before reading rows. EMPTY and CLARIFICATION both arrive with no rows and mean different things, so they come back as answers. screen_stocks raises NlScreenFailed only when the screen could not produce an answer after its retries. Any other outcome, such as a cancelled screen, arrives without rows.

screen.used_fallback_tables is True when the screener could not narrow its data sources before answering. Review those rows more carefully.

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

ROWSMatching rows were found.Read the rows and the row count.
EMPTYEvery filter ran and no stock passed all of them.Treat it as an answer. Loosen a filter if you expected matches.
CLARIFICATIONThe question was ambiguous.Read the clarification and ask a more specific question.
NlScreenFailed raisedThe screen spent its retry budget.Catch the exception. This is the only case worth retrying.

Analyze the rows in pandas

Show analyze the rows in pandas

Each row is a dictionary keyed by column name. The columns follow the question, so print one row before writing code that depends on a field. to_pandas() needs the optional stats extra.

Python
# python3 -m pip install 'nexustrade[stats]==5.0.0'
frame = screen.to_pandas()
print(frame.head())

Poll a screen yourself

Show poll a screen yourself

The client methods submit and poll separately. Keep the screen ID if your process may restart, and resume waiting on that ID instead of submitting the question again.

Python
from nexustrade import NexusTradeClient

client = NexusTradeClient()
started = client.create_nl_screen("Large-cap biotech stocks with positive free cash flow")
done = client.wait_for_nl_screen(started["id"])
result = done.get("result") or {}
print(result.get("outcome"), result.get("rowCount"))
for row in result.get("rows") or []:
    print(row)

Cost and account effects

Show cost and account effects

Each screen spends LLM credits from your account. A screen only reads market data. It does not save a watchlist, change a portfolio or place an order.

Rows are dated. Check the as-of date on the result before comparing the numbers with a live quote.

Continue exploring

Discussion

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

No comments yet.