Follow one worked path
Install the shown SDK version
These examples use NexusTrade TypeScript SDK 5.0.0. Create an API key with read access on the developers page and keep it out of shared files. The client reads NEXUSTRADE_API_KEY from the environment.
Create an API keyThe matching package is available and the request uses the appropriate read or write scope.
npm 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 { NexusTradeClient } from "nexustrade";
interface ScreenResult {
outcome?: string;
rows?: Array<Record<string, unknown>>;
rowCount?: number;
asOfDate?: string;
clarification?: string;
}
const client = new NexusTradeClient();
const started = await client.createNlScreen(
"The 10 largest US technology stocks by market cap with a P/E ratio under 30"
);
const done = await client.waitForNlScreen(String(started.id), {
raiseOnFailure: false,
});
const result = (done.result ?? {}) as ScreenResult;
if (done.status === "failed") {
console.error("The screen could not produce an answer.");
} else if (done.status === "cancelled") {
console.log("The screen was cancelled before it finished.");
} else if (result.outcome === "ROWS") {
console.log(`${result.rowCount} rows as of ${result.asOfDate}`);
console.table(result.rows);
} else if (result.outcome === "CLARIFICATION") {
console.log("Ask a more specific question:", result.clarification);
} else if (result.outcome === "EMPTY") {
console.log("No stock passed every filter.");
} else {
console.log("The screen finished without rows:", result.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 TypeScript SDK 5.0.0. Create an API key with read access on the developers page and keep it out of shared files. The client reads NEXUSTRADE_API_KEY from the environment.
npm 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. createNlScreen submits the question and returns immediately; waitForNlScreen polls the same screen until it finishes. Run the example as an ES module so top-level await works.
Name the filters, the time period and how many results you want. A specific question gets a specific answer.
import { NexusTradeClient } from "nexustrade";
interface ScreenResult {
outcome?: string;
rows?: Array<Record<string, unknown>>;
rowCount?: number;
asOfDate?: string;
clarification?: string;
}
const client = new NexusTradeClient();
const started = await client.createNlScreen(
"The 10 largest US technology stocks by market cap with a P/E ratio under 30"
);
const done = await client.waitForNlScreen(String(started.id), {
raiseOnFailure: false,
});
const result = (done.result ?? {}) as ScreenResult;
if (done.status === "failed") {
console.error("The screen could not produce an answer.");
} else if (done.status === "cancelled") {
console.log("The screen was cancelled before it finished.");
} else if (result.outcome === "ROWS") {
console.log(`${result.rowCount} rows as of ${result.asOfDate}`);
console.table(result.rows);
} else if (result.outcome === "CLARIFICATION") {
console.log("Ask a more specific question:", result.clarification);
} else if (result.outcome === "EMPTY") {
console.log("No stock passed every filter.");
} else {
console.log("The screen finished without rows:", result.outcome);
}Branch on the outcome
Show branch on the outcome
Check result.outcome before reading rows. EMPTY and CLARIFICATION both arrive with no rows and mean different things, so they come back as answers. With raiseOnFailure set to false, a screen that could not produce an answer returns status failed and a cancelled screen returns status cancelled; by default waitForNlScreen throws for both.
result.usedFallbackTables 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. |
| Status failed | The screen spent its retry budget. | This is the only case worth retrying. |
No matching rows. Clear the filter to see all records.
Resume a screen by ID
Show resume a screen by id
Keep the screen ID if your process may restart. getNlScreen reads the current state, and waitForNlScreen resumes polling the same ID without submitting the question again. cancelNlScreen stops a screen you no longer need.
const screenId = String(started.id);
const current = await client.getNlScreen(screenId);
console.log(current.status);
const finished = await client.waitForNlScreen(screenId);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.