Follow one worked path
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 keyThe matching package is available and the request uses the appropriate read or write scope.
python3 -m pip install nexustrade==5.0.0
printf 'NexusTrade API key: '
read -rs NEXUSTRADE_API_KEY
export NEXUSTRADE_API_KEY
printf '\n'Ask one plain-English question
Run this example. Name the filters, the time period and how many results you want in the question itself.
The screen finishes with an outcome. Rows arrive only when that outcome is ROWS.
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
Check the outcome before reading rows. Treat EMPTY as an answer, and reply to CLARIFICATION with a more specific question.
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.
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.
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.
| ROWS | Matching rows were found. | Read the rows and the row count. |
| EMPTY | Every filter ran and no stock passed all of them. | Treat it as an answer. Loosen a filter if you expected matches. |
| CLARIFICATION | The question was ambiguous. | Read the clarification and ask a more specific question. |
| NlScreenFailed raised | The screen spent its retry budget. | Catch the exception. This is the only case worth retrying. |
No matching rows. Clear the filter to see all records.
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.
# 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.
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.
No comments yet.