Installation
npm install rulebook-typescript
Requires Node.js 18+ (uses native
fetch). TypeScript 5.4+ recommended for type checking.Initialize the Client
import { Rulebook } from "rulebook-typescript";
const client = new Rulebook({ apiKey: "your-api-key" });
RULEBOOK_API_KEY environment variable and omit the parameter:
export RULEBOOK_API_KEY="your-api-key"
import { Rulebook } from "rulebook-typescript";
const client = new Rulebook(); // reads from RULEBOOK_API_KEY
RULEBOOK_BASE_URL environment variable:
export RULEBOOK_BASE_URL="https://your-custom-endpoint/api/v1"
List Exchanges
const response = await client.exchanges.list();
for (const ex of response.data) {
console.log(`${ex.name} (${ex.display_name})`);
console.log(` Fee types: ${ex.fee_types}`);
console.log(` Records: ${ex.record_count}`);
}
console.log(`Total exchanges: ${response.meta.record_count}`);
ExchangeListResponse
| Field | Type | Description |
|---|---|---|
data | Exchange[] | Array of exchange objects |
meta | Meta | Response metadata |
Show Exchange fields
Show Exchange fields
| Field | Type | Description |
|---|---|---|
name | string | Exchange identifier (e.g., nasdaq) |
display_name | string | Human-readable name |
fee_types | string[] | Available fee types |
record_count | number | Total fee schedule records |
Show meta fields
Show meta fields
| Field | Type | Description |
|---|---|---|
record_count | number | Total number of exchanges returned |
query_time_ms | number | Server-side query execution time (ms) |
Get Exchange Details
const response = await client.exchanges.retrieve("nasdaq");
const detail = response.data;
console.log(`Date range: ${detail.date_range.earliest} to ${detail.date_range.latest}`);
console.log(`Actions: ${detail.actions}`);
console.log(`Participants: ${detail.participants}`);
console.log(`Fee categories: ${detail.fee_categories}`);
console.log(`Query time: ${response.meta.query_time_ms}ms`);
ExchangeDetailResponse
| Field | Type | Description |
|---|---|---|
data | ExchangeDetail | Exchange detail object |
meta | Meta | Response metadata |
Show ExchangeDetail fields
Show ExchangeDetail fields
| Field | Type | Description |
|---|---|---|
name | string | Exchange identifier |
display_name | string | Human-readable name |
date_range | DateRange | .earliest and .latest (YYYY-MM-DD) |
fee_types | string[] | Available fee types |
fee_categories | string[] | Available fee categories |
actions | string[] | Available trading actions |
participants | string[] | Available participant types |
symbol_classifications | string[] | Available symbol classifications |
symbol_types | string[] | Available symbol types |
trade_types | string[] | Available trade types |
Show meta fields
Show meta fields
| Field | Type | Description |
|---|---|---|
record_count | number | Number of records for this exchange |
query_time_ms | number | Server-side query execution time (ms) |
List Fee Schedule Results
const page = await client.feeScheduleResults.list({
exchange_name: ["nasdaq"],
fee_type: ["option"],
fee_participant: ["market_maker"],
latest_only: true,
page_size: 10,
});
console.log(`Total results: ${page.meta.record_count}`);
for (const result of page.data) {
console.log(` ${result.fee_action}: ${result.fee_amount} (${result.fee_symbol_type})`);
}
PaginatedResponse<FeeScheduleResult>
| Field | Type | Description |
|---|---|---|
data | FeeScheduleResult[] | Array of result objects |
meta | Meta | Pagination metadata |
Show FeeScheduleResult fields (data)
Show FeeScheduleResult fields (data)
| Field | Type | Description |
|---|---|---|
record_id | string | Unique identifier (UUID) |
exchange_name | string | Exchange identifier (e.g., nasdaq) |
scraped_time | string | When the fee schedule was scraped (ISO 8601) |
version_id | string | Extraction version UUID |
fee_type | string | Fee type (option, equity) |
source_document | string | null | Source document name (with include_source) |
source_link | string | null | Source document URL (with include_source) |
page_number | number | null | Page in source doc (with include_source) |
fee_category | string | Fee category |
fee_charge_type | string | Fee or rebate charge type |
fee_amount | string | Fee/rebate amount |
fee_action | string | Trading action (make, take, open, routed, other) |
fee_action_details | string | null | Additional action details |
fee_basis | string | null | Basis for fee calculation |
fee_participant | string | Market participant type |
fee_participant_details | string | null | Participant classification details |
fee_monthly_volume | string | null | Volume threshold for tiered pricing |
fee_monthly_volume_criteria | string | null | Volume tier criteria |
fee_symbol_classification | string | null | Symbol classification |
fee_symbol_type | string | null | Penny/Non-Penny classification |
fee_trade_type | string | null | Trade type |
fee_symbol | string | null | Specific symbol(s) |
fee_excluded_symbols | string | null | Excluded symbols |
fee_conditions | string | null | Conditions for this fee |
fee_exclusions | string | null | Exclusion scenarios |
fee_notes | string | null | Additional notes |
fee_extra_info | string | null | Additional information |
relationships | object | null | Footnotes and definitions (with include_footnotes/include_definitions) |
Show meta fields
Show meta fields
| Field | Type | Description |
|---|---|---|
record_count | number | Total records matching the query |
total_pages | number | Total number of pages |
current_page | number | Current page number (0-indexed) |
page_size | number | Records per page |
query_time_ms | number | null | Query execution time in milliseconds |
| Parameter | Type | Description |
|---|---|---|
exchange_name | string[] | Filter by exchange name(s) |
fee_type | string[] | Filter by fee type(s) |
fee_category | string[] | Filter by fee category(s) |
fee_action | string[] | Filter by trading action(s) |
fee_participant | string[] | Filter by participant type(s) |
fee_symbol_classification | string[] | Filter by symbol classification(s) |
fee_symbol_type | string[] | Filter by symbol type(s) |
fee_trade_type | string[] | Filter by trade type(s) |
start_date | string | Filter by scraped date (YYYY-MM-DD) |
end_date | string | Filter by scraped date (YYYY-MM-DD) |
latest_only | boolean | Only latest version per exchange |
order_by | string | Sort field (default: created_on) |
order_dir | string | Sort direction: asc or desc |
page_size | number | Records per page (1–100) |
page_number | number | Page number (0-indexed) |
include_footnotes | boolean | Include related footnotes |
include_definitions | boolean | Include related definitions |
include_source | boolean | Include source document info |
Get a Single Fee Schedule Result
const response = await client.feeScheduleResults.retrieve(
"a3d76e96-0cad-4ece-9db1-7ad3c743bdf8",
{ include_footnotes: true, include_definitions: true, include_source: true }
);
const result = response.data;
console.log(`${result.exchange_name} — ${result.fee_type} — ${result.fee_category}`);
console.log(` Action: ${result.fee_action}`);
console.log(` Amount: ${result.fee_amount}`);
console.log(` Participant: ${result.fee_participant}`);
console.log(`Query time: ${response.meta.query_time_ms}ms`);
FeeScheduleResultResponse
| Field | Type | Description |
|---|---|---|
data | FeeScheduleResult | Fee schedule result object |
meta | Meta | Response metadata |
Show FeeScheduleResult fields (data)
Show FeeScheduleResult fields (data)
| Field | Type | Description |
|---|---|---|
record_id | string | Unique identifier (UUID) |
exchange_name | string | Exchange identifier (e.g., nasdaq) |
scraped_time | string | When the fee schedule was scraped (ISO 8601) |
version_id | string | Extraction version UUID |
fee_type | string | Fee type (option, equity) |
source_document | string | null | Source document name (with include_source) |
source_link | string | null | Source document URL (with include_source) |
page_number | number | null | Page in source doc (with include_source) |
fee_category | string | Fee category |
fee_charge_type | string | Fee or rebate charge type |
fee_amount | string | Fee/rebate amount |
fee_action | string | Trading action (make, take, open, routed, other) |
fee_action_details | string | null | Additional action details |
fee_basis | string | null | Basis for fee calculation |
fee_participant | string | Market participant type |
fee_participant_details | string | null | Participant classification details |
fee_monthly_volume | string | null | Volume threshold for tiered pricing |
fee_monthly_volume_criteria | string | null | Volume tier criteria |
fee_symbol_classification | string | null | Symbol classification |
fee_symbol_type | string | null | Penny/Non-Penny classification |
fee_trade_type | string | null | Trade type |
fee_symbol | string | null | Specific symbol(s) |
fee_excluded_symbols | string | null | Excluded symbols |
fee_conditions | string | null | Conditions for this fee |
fee_exclusions | string | null | Exclusion scenarios |
fee_notes | string | null | Additional notes |
fee_extra_info | string | null | Additional information |
relationships | Relationships | null | Footnotes and definitions (with include_footnotes/include_definitions) |
Show meta fields
Show meta fields
| Field | Type | Description |
|---|---|---|
record_count | number | Always 1 for a single result |
query_time_ms | number | Server-side query execution time (ms) |
Get Available Filters
Discover valid filter values before querying results:const response = await client.feeScheduleResults.getFilters();
const filters = response.data;
console.log(`Exchanges: ${filters.exchange_names}`);
console.log(`Fee types: ${filters.fee_types}`);
console.log(`Categories: ${filters.fee_categories}`);
console.log(`Actions: ${filters.fee_actions}`);
console.log(`Participants: ${filters.fee_participants}`);
console.log(`Total records: ${response.meta.record_count}`);
// Narrow filters to specific exchanges
const nasdaqFilters = await client.feeScheduleResults.getFilters({
exchange_name: ["nasdaq", "nasdaq_phlx"],
});
FeeScheduleResultFiltersResponse
| Field | Type | Description |
|---|---|---|
data | FeeScheduleResultFilters | Filter values object |
meta | Meta | Response metadata |
Show FeeScheduleResultFilters fields (data)
Show FeeScheduleResultFilters fields (data)
| Field | Type | Description |
|---|---|---|
exchange_names | string[] | Available exchange names |
fee_types | string[] | Available fee types |
fee_categories | string[] | Available fee categories |
fee_actions | string[] | Available trading actions |
fee_participants | string[] | Available participant types |
fee_symbol_classifications | string[] | Available symbol classifications |
fee_symbol_types | string[] | Available symbol types |
fee_trade_types | string[] | Available trade types |
Show meta fields
Show meta fields
| Field | Type | Description |
|---|---|---|
record_count | number | Total fee schedule records across filtered exchanges |
query_time_ms | number | Server-side query execution time (ms) |
Get Results by Version
Retrieve all fee schedule results from a specific extraction version:const page = await client.feeScheduleResults.getResultsByVersion(
"b962c0b1-5d99-4ef6-b3f6-36cb18c08933",
{ include_source: true, include_footnotes: true, page_size: 50 },
);
console.log(`Version has ${page.meta.record_count} results (${page.meta.total_pages} pages)`);
for (const result of page.data) {
console.log(` ${result.fee_action}: ${result.fee_amount}`);
if (result.source_document) {
console.log(` Source: ${result.source_document} (p.${result.page_number})`);
}
}
PaginatedResponse<FeeScheduleResult>
| Field | Type | Description |
|---|---|---|
data | FeeScheduleResult[] | Array of result objects |
meta | Meta | Pagination metadata |
Show FeeScheduleResult fields (data)
Show FeeScheduleResult fields (data)
| Field | Type | Description |
|---|---|---|
record_id | string | Unique identifier (UUID) |
exchange_name | string | Exchange identifier (e.g., nasdaq) |
scraped_time | string | When the fee schedule was scraped (ISO 8601) |
version_id | string | Extraction version UUID |
fee_type | string | Fee type (option, equity) |
source_document | string | null | Source document name (with include_source) |
source_link | string | null | Source document URL (with include_source) |
page_number | number | null | Page in source doc (with include_source) |
fee_category | string | Fee category |
fee_charge_type | string | Fee or rebate charge type |
fee_amount | string | Fee/rebate amount |
fee_action | string | Trading action (make, take, open, routed, other) |
fee_action_details | string | null | Additional action details |
fee_basis | string | null | Basis for fee calculation |
fee_participant | string | Market participant type |
fee_participant_details | string | null | Participant classification details |
fee_monthly_volume | string | null | Volume threshold for tiered pricing |
fee_monthly_volume_criteria | string | null | Volume tier criteria |
fee_symbol_classification | string | null | Symbol classification |
fee_symbol_type | string | null | Penny/Non-Penny classification |
fee_trade_type | string | null | Trade type |
fee_symbol | string | null | Specific symbol(s) |
fee_excluded_symbols | string | null | Excluded symbols |
fee_conditions | string | null | Conditions for this fee |
fee_exclusions | string | null | Exclusion scenarios |
fee_notes | string | null | Additional notes |
fee_extra_info | string | null | Additional information |
relationships | object | null | Footnotes and definitions (with include_footnotes/include_definitions) |
Show meta fields
Show meta fields
| Field | Type | Description |
|---|---|---|
record_count | number | Total records in this version |
total_pages | number | Total number of pages |
current_page | number | Current page number (0-indexed) |
page_size | number | Records per page |
query_time_ms | number | null | Query execution time in milliseconds |
Pagination
Fee schedule results are paginated. Usepage_number and page_size to iterate:
let page_number = 0;
let totalFetched = 0;
while (true) {
const page = await client.feeScheduleResults.list({
latest_only: true,
page_size: 50,
page_number,
});
totalFetched += page.data.length;
console.log(`Page ${page_number + 1}/${page.meta.total_pages}: ${page.data.length} results`);
if (page_number >= page.meta.total_pages - 1) break;
page_number++;
}
console.log(`Fetched ${totalFetched} of ${page.meta.record_count} total results`);
Async by Default
The TypeScript SDK is async-native — all methods return aPromise and are designed for
async/await usage. Unlike the Python SDK which provides separate Rulebook and
AsyncRulebook clients, there is no separate sync client.
import { Rulebook } from "rulebook-typescript";
async function main() {
const client = new Rulebook({ apiKey: "your-api-key" });
const exchanges = await client.exchanges.list();
const detail = await client.exchanges.retrieve("nasdaq");
}
main();
Next Steps
Error Handling
Handle API errors with typed exceptions
Advanced Usage
Timeouts, retries, raw responses, and per-request overrides

