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
68 changes: 50 additions & 18 deletions src/api/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,45 @@ const STRING_ARRAY = {
items: { type: "string" },
} as const;

const RESULT_METADATA_SCHEMA = {
type: "object",
properties: {
retrieved_at: { type: "string", format: "date-time" },
source: { type: "string" },
cache_hit: { type: "boolean" },
requested_count: { type: "integer", minimum: 0 },
returned_count: { type: "integer", minimum: 0 },
missing_symbols: STRING_ARRAY,
unavailable_symbols: STRING_ARRAY,
},
required: [
"retrieved_at",
"source",
"cache_hit",
"requested_count",
"returned_count",
"missing_symbols",
],
additionalProperties: false,
} as const;

function withMetadata(properties: Record<string, unknown>) {
return {
...properties,
metadata: RESULT_METADATA_SCHEMA,
};
}

const METADATA_REQUIRED = ["metadata"] as const;

function collectionSchema(name: string) {
return {
type: "object",
properties: {
properties: withMetadata({
total_count: { type: "integer" },
[name]: { type: "array", items: OBJECT_ROW },
},
required: ["total_count", name],
}),
required: ["total_count", name, ...METADATA_REQUIRED],
additionalProperties: true,
} as const;
}
Expand All @@ -54,50 +85,51 @@ export const OUTPUT_SCHEMAS = {
screen_etf: collectionSchema("etfs"),
lookup_symbols: {
type: "object",
properties: {
properties: withMetadata({
total_count: { type: "integer" },
symbols: { type: "array", items: OBJECT_ROW },
},
required: ["total_count", "symbols"],
}),
required: ["total_count", "symbols", ...METADATA_REQUIRED],
additionalProperties: true,
},
search_symbols: {
type: "object",
properties: {
properties: withMetadata({
query: { type: "string" },
count: { type: "integer" },
symbols: { type: "array", items: OBJECT_ROW },
},
required: ["query", "count", "symbols"],
}),
required: ["query", "count", "symbols", ...METADATA_REQUIRED],
additionalProperties: true,
},
get_market_metainfo: {
type: "object",
properties: {
properties: withMetadata({
market: { type: "string" },
requested_fields: STRING_ARRAY,
metainfo: OBJECT_ROW,
},
required: ["market"],
}),
required: ["market", ...METADATA_REQUIRED],
additionalProperties: true,
},
get_ta_summary: {
type: "object",
properties: {
properties: withMetadata({
symbols: { type: "array", items: OBJECT_ROW },
},
required: ["symbols"],
}),
required: ["symbols", ...METADATA_REQUIRED],
additionalProperties: true,
},
rank_by_ta: {
type: "object",
properties: {
properties: withMetadata({
requested_symbols: { type: "integer" },
timeframes: STRING_ARRAY,
weights: { type: "object", additionalProperties: { type: "number" } },
ranked: { type: "array", items: OBJECT_ROW },
},
required: ["requested_symbols", "timeframes", "weights", "ranked"],
excluded_symbols: { type: "array", items: OBJECT_ROW },
}),
required: ["requested_symbols", "timeframes", "weights", "ranked", "excluded_symbols", ...METADATA_REQUIRED],
additionalProperties: true,
},
list_fields: {
Expand Down
Loading
Loading