Skip to content

Commit

Permalink
Updated docs and endpoint to use standard format
Browse files Browse the repository at this point in the history
  • Loading branch information
Pelotfr committed Nov 23, 2023
1 parent 1ad0a6a commit ca64e06
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 48 deletions.
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
| GET `/health` | Health check
| GET `/chains` | Get available chains
| GET `/sales` | Get sales by `chain`, `collection_name`, `sale_id`, `timestamp`, `block_number`, `template_id`, `listing_price_amount`, `listing_price_symcode`, `trx_id` or `contains_asset_id`
| GET `/sales/aggregate` | Get aggregate of sales filtered by `chain`,`collection_name`, `listing_price_symcode`, `timestamp` or `block_number`
| GET `/sales/aggregate` | Get aggregate of sales for given time range filtered by `chain`,`collection_name` or `listing_price_symcode`
| GET `/metrics` | Prometheus metrics
| GET `/openapi` | [OpenAPI v3 JSON](https://spec.openapis.org/oas/v3.0.0)

Expand Down Expand Up @@ -56,34 +56,38 @@ MAX_LIMIT=500
# Logging
VERBOSE=true
```
## Expected database structure
## Required database structure
`substreams-sink-clickhouse` auto generates some tables (see [Database structure](https://github.com/pinax-network/substreams-sink-clickhouse#database-structure) section).
For this API to work, you will also need to provide following schemas to `substreams-sink-clickhouse` (see [Schema initialization](https://github.com/pinax-network/substreams-sink-clickhouse#schema-initialization) section):
- `substreams-atomicmarket-sales` [schema](https://github.com/pinax-network/substreams-atomicmarket-sales/blob/master/schema.sql)
- `substreams-atomicassets` [schema](https://github.com/pinax-network/substreams-atomicassets/blob/master/schema.sql)

The expected added tables to the database structure will then be:
The minimum required added tables to the database structure are:
```mermaid
erDiagram
Sales }|--|{ Assets : " "
Sales {
sale_id UInt64
trx_id String
asset_ids Array(UInt64)
listing_price_amount Int64
listing_price_precision UInt8
listing_price_symcode String
collection_name String
sale_id UInt64,
trx_id String,
seller String,
asset_ids Array(UInt64),
offer_id Int64,
listing_price_amount Int64,
listing_price_precision UInt8,
listing_price_symcode String,
settlement_symbol_precision UInt8,
settlement_symbol_code String,
maker_marketplace String,
collection_name String,
collection_fee Float64,
}
Assets {
asset_id UInt64
scope String
owner String
collection_name String
template_id Int32
}
```
## Help
Expand Down
9 changes: 5 additions & 4 deletions src/fetch/aggregate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { makeQuery } from "../clickhouse/makeQuery.js";
import { logger } from "../logger.js";
import { getAggregate } from "../queries.js";
import { SalesHistoryData, getAggregate } from "../queries.js";
import * as prometheus from "../prometheus.js";
import { BadRequest, toJSON } from "./cors.js";
import { verifyParameters } from "../utils.js";
import { parseHistoryResponse, verifyParameters } from "../utils.js";

export default async function (req: Request) {
const parametersResult = await verifyParameters(req);
Expand All @@ -14,8 +14,9 @@ export default async function (req: Request) {
const { searchParams } = new URL(req.url);
logger.info({searchParams: Object.fromEntries(Array.from(searchParams))});
const query = await getAggregate(searchParams);
const response = await makeQuery<number>(query)
return toJSON(response.data);
const response = await makeQuery<SalesHistoryData>(query)
const formatted = parseHistoryResponse(response.data, 86400);
return toJSON(formatted);
} catch (e: any) {
logger.error(e);
prometheus.request_error.inc({pathname: "/sales/aggregate", status: 400});
Expand Down
35 changes: 4 additions & 31 deletions src/fetch/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,39 +215,12 @@ export default new OpenApiBuilder()
schema: { enum: await store.symbol_codes },
},
{
name: 'timestamp',
in: 'query',
description: 'Filter by exact timestamp',
required: false,
schema: timestampSchema,
examples: timestampExamples,
},
{
name: "block_number",
description: "Filter by Block number (ex: 18399498)",
name: "range",
in: "query",
description: "Time range to query (ex: 24h)",
required: false,
schema: { type: "number" },
},
...["greater_or_equals_by_timestamp", "greater_by_timestamp", "less_or_equals_by_timestamp", "less_by_timestamp"].map(name => {
return {
name,
in: "query",
description: "Filter " + name.replace(/_/g, " "),
required: false,
schema: timestampSchema,
examples: timestampExamples,
} as ParameterObject
}),
...["greater_or_equals_by_block_number", "greater_by_block_number", "less_or_equals_by_block_number", "less_by_block_number"].map(name => {
return {
name,
in: "query",
description: "Filter " + name.replace(/_/g, " "),
required: false,
schema: { type: "number" },
} as ParameterObject
}),
schema: { enum: ["24h", "7d", "30d", "90d", "1y", "all"] },
}
],
responses: {
200: { description: "Aggregate of sales", content: { "text/plain": { example: aggregate_example} } },
Expand Down

0 comments on commit ca64e06

Please sign in to comment.