From ac9196f06bb08ddcae4632ea9d26e63f09c47e8a Mon Sep 17 00:00:00 2001 From: Pelotfr Date: Thu, 9 Nov 2023 09:21:41 +0100 Subject: [PATCH] Added Symbol Code as dynamic enum --- src/clickhouse/stores.ts | 13 +++++++++++++ src/fetch/openapi.ts | 11 +++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/clickhouse/stores.ts b/src/clickhouse/stores.ts index a65ae7d..c2aafc9 100644 --- a/src/clickhouse/stores.ts +++ b/src/clickhouse/stores.ts @@ -2,6 +2,7 @@ import client from "./createClient.js"; class ClickhouseStore { private collectionNamesPromise: Promise | null = null; + private SymbolCodesPromise: Promise | null = null; public get collection_names() { if (!this.collectionNamesPromise) { @@ -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>()) + .then((symbol_codes) => symbol_codes.map(({ listing_price_symcode }) => listing_price_symcode)) + .catch(() => []); + } + + return this.SymbolCodesPromise; + } } export const store = new ClickhouseStore(); diff --git a/src/fetch/openapi.ts b/src/fetch/openapi.ts index 936a8e6..b6b6af1 100644 --- a/src/fetch/openapi.ts +++ b/src/fetch/openapi.ts @@ -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", @@ -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',