NexusTrade guides

Query market data in TypeScript with plain English

Ask the NexusTrade screener a plain-English question with the TypeScript 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 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 key
What you should see

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

Shell
npm 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.

TypeScript
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);
}

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 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.

Shell
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.

TypeScript
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.

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.
Status failedThe screen spent its retry budget.This is the only case worth retrying.

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.

TypeScript
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.

Continue exploring

Discussion

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

No comments yet.