Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Build locally with `npm run build` in this directory. Keep the API key on your s
import { TidelightClient } from "@tidelight/sdk";

const client = new TidelightClient({ apiKey: process.env.TIDELIGHT_API_KEY! });
const page = await client.listTokenizedEquities({ limit: 20 });
const page = await client.listTokenizedEquities({ limit: 20, underlyingTicker: "AAPL" });
for (const instrument of page.data) console.log(instrument.symbol, instrument.underlying_ticker);

for await (const instrument of client.tokenizedEquities({ limit: 50 })) {
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,17 @@ export class TidelightClient {
this.transport = options.fetch ?? fetch;
}

async listTokenizedEquities(options: { limit?: number; cursor?: string; signal?: AbortSignal } = {}): Promise<InstrumentPage> {
async listTokenizedEquities(options: { limit?: number; cursor?: string; underlyingTicker?: string; signal?: AbortSignal } = {}): Promise<InstrumentPage> {
const limit = options.limit ?? 20;
if (!Number.isInteger(limit) || limit < 1 || limit > 100) throw new RangeError("limit must be 1 to 100.");
if (options.cursor !== undefined && !/^[A-Z0-9]{2,32}$/.test(options.cursor)) throw new TypeError("Invalid instrument cursor.");
const underlyingTicker = options.underlyingTicker?.toUpperCase();
if (underlyingTicker !== undefined && !/^[A-Z][A-Z0-9.]{0,9}$/.test(underlyingTicker)) throw new TypeError("Invalid underlyingTicker.");
const url = new URL(`${this.baseUrl}/market/instruments`);
url.searchParams.set("kind", "rtoken");
url.searchParams.set("limit", String(limit));
if (options.cursor) url.searchParams.set("cursor", options.cursor);
if (underlyingTicker) url.searchParams.set("underlying_ticker", underlyingTicker);
for (let attempt = 0; ; attempt++) {
const controller = new AbortController();
const onAbort = () => controller.abort();
Expand Down
11 changes: 11 additions & 0 deletions tests/client.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ import { TidelightApiError, TidelightClient } from "../dist/index.js";
const key = `tl_test_${"a".repeat(43)}`;
const jobId = "01234567-89ab-4cde-8fab-0123456789ab";

test("filters market instruments by normalized underlying ticker", async () => {
let requestUrl = "";
const client = new TidelightClient({ apiKey: key, fetch: async url => {
requestUrl = String(url);
return Response.json({ data: [], next_cursor: null, generated_at: 1, request_id: "market-filter" });
} });
await client.listTokenizedEquities({ limit: 1, underlyingTicker: "aapl" });
assert.match(requestUrl, /underlying_ticker=AAPL/);
await assert.rejects(client.listTokenizedEquities({ underlyingTicker: "AAPL?" }), TypeError);
});

test("starts, polls, and cancels an asynchronous research job", async () => {
const calls = [];
const client = new TidelightClient({ apiKey: key, fetch: async (url, init) => {
Expand Down
Loading