Skip to content

Commit

Permalink
Added Symbol Code as dynamic enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Pelotfr committed Nov 9, 2023
1 parent 539a28d commit ac9196f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/clickhouse/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import client from "./createClient.js";

class ClickhouseStore {
private collectionNamesPromise: Promise<string[]> | null = null;
private SymbolCodesPromise: Promise<string[]> | null = null;

public get collection_names() {
if (!this.collectionNamesPromise) {
Expand All @@ -14,6 +15,18 @@ class ClickhouseStore {

return this.collectionNamesPromise;
}

public get symbol_codes() {
if (!this.SymbolCodesPromise) {
this.SymbolCodesPromise = client
.query({ query: "SELECT DISTINCT listing_price_symcode FROM Sales", format: "JSONEachRow" })
.then((response) => response.json<Array<{ listing_price_symcode: string }>>())
.then((symbol_codes) => symbol_codes.map(({ listing_price_symcode }) => listing_price_symcode))
.catch(() => []);
}

return this.SymbolCodesPromise;
}
}

export const store = new ClickhouseStore();
11 changes: 9 additions & 2 deletions src/fetch/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ export default new OpenApiBuilder()
},
{
name: "listing_price_symcode",
description: "Filter by listing price symcode (ex: 'EOS')",
description: "Filter by Symbol Code",
in: "query",
required: false,
schema: { type: "string" },
schema: { enum: await store.symbol_codes },
},
{
name: "trx_id",
Expand Down Expand Up @@ -183,6 +183,13 @@ export default new OpenApiBuilder()
required: false,
schema: {enum: await store.collection_names},
},
{
name: "listing_price_symcode",
description: "Filter by Symbol Code",
in: "query",
required: false,
schema: { enum: await store.symbol_codes },
},
{
name: 'timestamp',
in: 'query',
Expand Down

0 comments on commit ac9196f

Please sign in to comment.